From 87f59802183a4538253e66cc5bb86118c8a345fe Mon Sep 17 00:00:00 2001 From: hazel Date: Wed, 29 May 2024 15:40:40 +0900 Subject: [PATCH 1/6] =?UTF-8?q?[#44]=20refactor=20:=20GenericJackson2JsonR?= =?UTF-8?q?edisSerializer=EB=A1=9C=20redis=20=EC=A7=81=EB=A0=AC=ED=99=94?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/kboticketing/kboticketing/config/RedisConfig.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/kboticketing/kboticketing/config/RedisConfig.java b/src/main/java/com/kboticketing/kboticketing/config/RedisConfig.java index 5efaf44..43df5ac 100644 --- a/src/main/java/com/kboticketing/kboticketing/config/RedisConfig.java +++ b/src/main/java/com/kboticketing/kboticketing/config/RedisConfig.java @@ -7,6 +7,7 @@ import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; /** @@ -39,9 +40,10 @@ public RedisConnectionFactory redisConnectionFactory() { RedisTemplate redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(redisConnectionFactory()); - // 일반적인 key:value의 경우 직렬화 기본 (JdkSerializationRedisSerializer) + //String으로 직렬화 redisTemplate.setKeySerializer(new StringRedisSerializer()); - redisTemplate.setValueSerializer(new StringRedisSerializer()); + //JSON으로 직렬화 + redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); return redisTemplate; } From e48869bc05da03156b44546cedcbea4713fb0edb Mon Sep 17 00:00:00 2001 From: hazel Date: Wed, 29 May 2024 15:41:18 +0900 Subject: [PATCH 2/6] =?UTF-8?q?[#44]=20feat=20:=20spring-boot-starter-cach?= =?UTF-8?q?e=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B0=8F=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 ++ .../kboticketing/config/RedisCacheConfig.java | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/main/java/com/kboticketing/kboticketing/config/RedisCacheConfig.java diff --git a/build.gradle b/build.gradle index bf0f5e1..1929f1f 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,8 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' //jwt implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.12.5' + // spring-boot-starter-cache + implementation 'org.springframework.boot:spring-boot-starter-cache' } tasks.named('test') { diff --git a/src/main/java/com/kboticketing/kboticketing/config/RedisCacheConfig.java b/src/main/java/com/kboticketing/kboticketing/config/RedisCacheConfig.java new file mode 100644 index 0000000..6c32673 --- /dev/null +++ b/src/main/java/com/kboticketing/kboticketing/config/RedisCacheConfig.java @@ -0,0 +1,30 @@ +package com.kboticketing.kboticketing.config; + +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializationContext; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +/** + * @author hazel + */ +@EnableCaching +@Configuration +public class RedisCacheConfig { + + @Bean + public RedisCacheConfiguration redisCacheConfiguration() { + return RedisCacheConfiguration.defaultCacheConfig() + .disableCachingNullValues() + .serializeKeysWith( + RedisSerializationContext.SerializationPair.fromSerializer( + new StringRedisSerializer()) + ) + .serializeValuesWith( + RedisSerializationContext.SerializationPair.fromSerializer( + new GenericJackson2JsonRedisSerializer())); + } +} \ No newline at end of file From 25f8a7b3093c00fedb35a8b79ece216245baf620 Mon Sep 17 00:00:00 2001 From: hazel Date: Wed, 29 May 2024 15:45:05 +0900 Subject: [PATCH 3/6] =?UTF-8?q?[#44]=20feat=20:=20=ED=8C=80=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EC=BA=90=EC=8B=B1=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/kboticketing/kboticketing/domain/Team.java | 10 ++++++++-- .../kboticketing/kboticketing/service/TeamService.java | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/kboticketing/kboticketing/domain/Team.java b/src/main/java/com/kboticketing/kboticketing/domain/Team.java index 5b5b389..bd2e75a 100644 --- a/src/main/java/com/kboticketing/kboticketing/domain/Team.java +++ b/src/main/java/com/kboticketing/kboticketing/domain/Team.java @@ -1,15 +1,21 @@ package com.kboticketing.kboticketing.domain; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; -import lombok.RequiredArgsConstructor; /** * @author hazel */ -@RequiredArgsConstructor @Getter public class Team { private final Integer teamId; private final String name; + + @JsonCreator + public Team(@JsonProperty("teamId") Integer teamId, @JsonProperty("name") String name) { + this.teamId = teamId; + this.name = name; + } } diff --git a/src/main/java/com/kboticketing/kboticketing/service/TeamService.java b/src/main/java/com/kboticketing/kboticketing/service/TeamService.java index f3b83f9..4146e36 100644 --- a/src/main/java/com/kboticketing/kboticketing/service/TeamService.java +++ b/src/main/java/com/kboticketing/kboticketing/service/TeamService.java @@ -4,6 +4,7 @@ import com.kboticketing.kboticketing.domain.Team; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; /** @@ -15,6 +16,7 @@ public class TeamService { private final TeamMapper teamMapper; + @Cacheable(value = "teams/") public List getTeams() { return teamMapper.selectTeams(); } From 706217b87da0154ab21ef551223f2b036ee47ac2 Mon Sep 17 00:00:00 2001 From: hazel Date: Wed, 29 May 2024 15:45:56 +0900 Subject: [PATCH 4/6] =?UTF-8?q?[#44]=20feat=20:=20=EA=B2=BD=EA=B8=B0=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EC=BA=90=EC=8B=B1=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EB=8F=84=EB=A9=94=EC=9D=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kboticketing/domain/ScheduleTeam.java | 14 ++++++++++++-- .../kboticketing/dto/ScheduleQueryParamDto.java | 4 ++++ .../kboticketing/service/ScheduleService.java | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/kboticketing/kboticketing/domain/ScheduleTeam.java b/src/main/java/com/kboticketing/kboticketing/domain/ScheduleTeam.java index 679501a..fc46dcf 100644 --- a/src/main/java/com/kboticketing/kboticketing/domain/ScheduleTeam.java +++ b/src/main/java/com/kboticketing/kboticketing/domain/ScheduleTeam.java @@ -1,12 +1,12 @@ package com.kboticketing.kboticketing.domain; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; -import lombok.RequiredArgsConstructor; /** * @author hazel */ -@RequiredArgsConstructor @Getter public class ScheduleTeam { @@ -14,4 +14,14 @@ public class ScheduleTeam { private final String scheduleName; private final String stadiumName; private final String date; + + @JsonCreator + public ScheduleTeam(@JsonProperty("scheduleId") Integer scheduleId, + @JsonProperty("scheduleName") String scheduleName, + @JsonProperty("stadiumName") String stadiumName, @JsonProperty("date") String date) { + this.scheduleId = scheduleId; + this.scheduleName = scheduleName; + this.stadiumName = stadiumName; + this.date = date; + } } diff --git a/src/main/java/com/kboticketing/kboticketing/dto/ScheduleQueryParamDto.java b/src/main/java/com/kboticketing/kboticketing/dto/ScheduleQueryParamDto.java index b069b8b..9f00193 100644 --- a/src/main/java/com/kboticketing/kboticketing/dto/ScheduleQueryParamDto.java +++ b/src/main/java/com/kboticketing/kboticketing/dto/ScheduleQueryParamDto.java @@ -1,12 +1,16 @@ package com.kboticketing.kboticketing.dto; import java.time.LocalDateTime; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; /** * @author hazel */ @Getter +@EqualsAndHashCode +@ToString public class ScheduleQueryParamDto { private final Integer teamId; diff --git a/src/main/java/com/kboticketing/kboticketing/service/ScheduleService.java b/src/main/java/com/kboticketing/kboticketing/service/ScheduleService.java index 54c3fcd..abc2bc2 100644 --- a/src/main/java/com/kboticketing/kboticketing/service/ScheduleService.java +++ b/src/main/java/com/kboticketing/kboticketing/service/ScheduleService.java @@ -7,6 +7,7 @@ import com.kboticketing.kboticketing.dto.ScheduleQueryParamDto; import java.util.ArrayList; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; /** @@ -18,6 +19,7 @@ public class ScheduleService { private final ScheduleMapper scheduleMapper; + @Cacheable(value = "schedules/", key = "#scheduleQueryParamDto.toString()") public ArrayList getSchedules(ScheduleQueryParamDto scheduleQueryParamDto) { return scheduleMapper.selectSchedules(scheduleQueryParamDto); } From 635bdb969220682874e462e618da9a1b76438443 Mon Sep 17 00:00:00 2001 From: hazel Date: Wed, 29 May 2024 15:46:10 +0900 Subject: [PATCH 5/6] =?UTF-8?q?[#44]=20feat=20:=20=EA=B2=BD=EA=B8=B0=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=BA=90=EC=8B=B1=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B0=8F=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kboticketing/domain/ScheduleInfo.java | 15 +++++++++++++-- .../kboticketing/service/ScheduleService.java | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/kboticketing/kboticketing/domain/ScheduleInfo.java b/src/main/java/com/kboticketing/kboticketing/domain/ScheduleInfo.java index 96f30b7..0c52647 100644 --- a/src/main/java/com/kboticketing/kboticketing/domain/ScheduleInfo.java +++ b/src/main/java/com/kboticketing/kboticketing/domain/ScheduleInfo.java @@ -1,17 +1,28 @@ package com.kboticketing.kboticketing.domain; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; -import lombok.RequiredArgsConstructor; /** * @author hazel */ @Getter -@RequiredArgsConstructor public class ScheduleInfo { private final Integer scheduleId; private final String scheduleName; private final String date; private final String stadiumName; + + @JsonCreator + public ScheduleInfo(@JsonProperty("scheduleId") Integer scheduleId, + @JsonProperty("scheduleName") String scheduleName, + @JsonProperty("date") String date, + @JsonProperty("stadiumName") String stadiumName) { + this.scheduleId = scheduleId; + this.scheduleName = scheduleName; + this.date = date; + this.stadiumName = stadiumName; + } } diff --git a/src/main/java/com/kboticketing/kboticketing/service/ScheduleService.java b/src/main/java/com/kboticketing/kboticketing/service/ScheduleService.java index abc2bc2..7b96267 100644 --- a/src/main/java/com/kboticketing/kboticketing/service/ScheduleService.java +++ b/src/main/java/com/kboticketing/kboticketing/service/ScheduleService.java @@ -24,6 +24,7 @@ public ArrayList getSchedules(ScheduleQueryParamDto scheduleQueryP return scheduleMapper.selectSchedules(scheduleQueryParamDto); } + @Cacheable(value = "schedules/", key = "#id") public ScheduleInfo getSchedule(String id) { return scheduleMapper.selectInfo(id); } From bb26ae039561500aa916e5c50aa96340d1aba5ce Mon Sep 17 00:00:00 2001 From: hazel Date: Wed, 29 May 2024 15:46:25 +0900 Subject: [PATCH 6/6] =?UTF-8?q?[#44]=20feat=20:=20=EC=A2=8C=EC=84=9D=20?= =?UTF-8?q?=EB=93=B1=EA=B8=89=20=EC=A1=B0=ED=9A=8C=20=EC=BA=90=EC=8B=B1=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EB=8F=84=EB=A9=94=EC=9D=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kboticketing/kboticketing/domain/SeatGrade.java | 13 +++++++++++-- .../kboticketing/service/SeatService.java | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/kboticketing/kboticketing/domain/SeatGrade.java b/src/main/java/com/kboticketing/kboticketing/domain/SeatGrade.java index b440495..c8342b1 100644 --- a/src/main/java/com/kboticketing/kboticketing/domain/SeatGrade.java +++ b/src/main/java/com/kboticketing/kboticketing/domain/SeatGrade.java @@ -1,18 +1,27 @@ package com.kboticketing.kboticketing.domain; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.EqualsAndHashCode; import lombok.Getter; -import lombok.RequiredArgsConstructor; /** * @author hazel */ @Getter -@RequiredArgsConstructor @EqualsAndHashCode public class SeatGrade { private final Integer seatGradeId; private final String seatGradeName; private final String seatCount; + + @JsonCreator + public SeatGrade(@JsonProperty("seatGradeId") Integer seatGradeId, + @JsonProperty("seatGradeName") String seatGradeName, + @JsonProperty("seatCount") String seatCount) { + this.seatGradeId = seatGradeId; + this.seatGradeName = seatGradeName; + this.seatCount = seatCount; + } } diff --git a/src/main/java/com/kboticketing/kboticketing/service/SeatService.java b/src/main/java/com/kboticketing/kboticketing/service/SeatService.java index e7a1c01..4ab5298 100644 --- a/src/main/java/com/kboticketing/kboticketing/service/SeatService.java +++ b/src/main/java/com/kboticketing/kboticketing/service/SeatService.java @@ -11,6 +11,7 @@ import java.util.Collections; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.Cacheable; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.script.DefaultRedisScript; import org.springframework.stereotype.Service; @@ -38,6 +39,7 @@ public ReservationSeatDto getSeatsByGrade(String scheduleId, String seatGradeId) return new ReservationSeatDto(reservedSeat); } + @Cacheable(value = "seat-grades/", key = "#id") public SeatGrade getSeatGrade(String id) { return seatMapper.selectSeatGrade(id); }