From d75c8dffe7ad3242137912e473a75b61eecf11bd Mon Sep 17 00:00:00 2001 From: KwonJuHwan <118177454+KwonJuHwan@users.noreply.github.com> Date: Mon, 22 Jan 2024 18:41:19 +0900 Subject: [PATCH 01/12] =?UTF-8?q?[feat]=20RedisCache=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20config=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/config/RedisCacheConfig.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/com/coolpeace/global/config/RedisCacheConfig.java diff --git a/src/main/java/com/coolpeace/global/config/RedisCacheConfig.java b/src/main/java/com/coolpeace/global/config/RedisCacheConfig.java new file mode 100644 index 00000000..1bab6107 --- /dev/null +++ b/src/main/java/com/coolpeace/global/config/RedisCacheConfig.java @@ -0,0 +1,31 @@ +package com.coolpeace.global.config; + +import java.time.Duration; +import org.springframework.cache.CacheManager; +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.cache.RedisCacheManager; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializationContext.SerializationPair; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +@Configuration +@EnableCaching +public class RedisCacheConfig { + + @Bean + public CacheManager contentCacheManager(RedisConnectionFactory cf) { + RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig() + .serializeKeysWith(SerializationPair.fromSerializer( + new StringRedisSerializer())) + .serializeValuesWith(SerializationPair.fromSerializer( + new GenericJackson2JsonRedisSerializer())) + .entryTtl(Duration.ofHours(6)); + + return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(cf) + .cacheDefaults(redisCacheConfiguration).build(); + } +} From 4d42d02e9b310961e8a26b29801a71f1e2665e9c Mon Sep 17 00:00:00 2001 From: KwonJuHwan <118177454+KwonJuHwan@users.noreply.github.com> Date: Mon, 22 Jan 2024 18:42:01 +0900 Subject: [PATCH 02/12] =?UTF-8?q?[feat]=20=EC=88=99=EB=B0=95=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C,=20=EC=88=99=EB=B0=95=20=EA=B0=9D=EC=8B=A4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=BA=90=EC=8B=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/accommodation/service/AccomodationService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/coolpeace/domain/accommodation/service/AccomodationService.java b/src/main/java/com/coolpeace/domain/accommodation/service/AccomodationService.java index 06c8d761..1d437910 100644 --- a/src/main/java/com/coolpeace/domain/accommodation/service/AccomodationService.java +++ b/src/main/java/com/coolpeace/domain/accommodation/service/AccomodationService.java @@ -12,6 +12,7 @@ import com.coolpeace.global.jwt.security.JwtPrincipal; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; @Service @@ -22,6 +23,7 @@ public class AccomodationService { private final AccommodationRepository accommodationRepository; private final RoomRepository roomRepository; + @Cacheable(value = "accommodation", key = "#jwtPrincipal.toString()",cacheManager = "contentCacheManager") public List getAccommodations(JwtPrincipal jwtPrincipal) { Long memberId = Long.parseLong(jwtPrincipal.getMemberId()); @@ -34,6 +36,7 @@ public List getAccommodations(JwtPrincipal jwtPrincipal) .toList(); } + @Cacheable(value = "rooms", key = "#accommodationId",cacheManager = "contentCacheManager") public List getRooms(JwtPrincipal jwtPrincipal, Long accommodationId) { Long memberId = Long.parseLong(jwtPrincipal.getMemberId()); From 808a4ca6bf7b4048faa7d2d884e09a6bf88454e8 Mon Sep 17 00:00:00 2001 From: KwonJuHwan <118177454+KwonJuHwan@users.noreply.github.com> Date: Mon, 22 Jan 2024 18:42:19 +0900 Subject: [PATCH 03/12] =?UTF-8?q?[feat]=20=EC=BA=90=EC=8B=B1=20=EA=B0=80?= =?UTF-8?q?=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=96=B4=EB=85=B8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/coolpeace/CoolPeaceApplication.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/coolpeace/CoolPeaceApplication.java b/src/main/java/com/coolpeace/CoolPeaceApplication.java index f59fd38b..51bb07b8 100644 --- a/src/main/java/com/coolpeace/CoolPeaceApplication.java +++ b/src/main/java/com/coolpeace/CoolPeaceApplication.java @@ -2,10 +2,12 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @EnableScheduling +@EnableCaching public class CoolPeaceApplication { public static void main(String[] args) { From e5ac9345bb49dec7aa6db19c5e414180b6de0c62 Mon Sep 17 00:00:00 2001 From: KwonJuHwan <118177454+KwonJuHwan@users.noreply.github.com> Date: Mon, 22 Jan 2024 18:44:13 +0900 Subject: [PATCH 04/12] =?UTF-8?q?[feat]=20=EB=8C=80=EC=8B=9C=EB=B3=B4?= =?UTF-8?q?=EB=93=9C=EC=97=90=EC=84=9C=20=EC=A1=B0=ED=9A=8C=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=A0=84=EB=B6=80=20?= =?UTF-8?q?=EC=BA=90=EC=8B=B1=20=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/dashboard/service/DashboardService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/coolpeace/domain/dashboard/service/DashboardService.java b/src/main/java/com/coolpeace/domain/dashboard/service/DashboardService.java index df05832f..0be16b00 100644 --- a/src/main/java/com/coolpeace/domain/dashboard/service/DashboardService.java +++ b/src/main/java/com/coolpeace/domain/dashboard/service/DashboardService.java @@ -28,6 +28,7 @@ import java.util.Comparator; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -42,6 +43,7 @@ public class DashboardService { private final AccommodationRepository accommodationRepository; private final LocalCouponDownloadRepository localCouponDownloadRepository; + @Cacheable(value = "monthlyData", key = "#accommodationId", cacheManager = "contentCacheManager") public List monthlyData(String memberId, Long accommodationId) { Accommodation accommodation = checkAccommodationMatchMember(memberId, accommodationId); MonthlySearchDate monthlySearchDate = MonthlySearchDate.getMonthlySearchDate(0,0); @@ -56,6 +58,7 @@ public List monthlyData(String memberId, Long accommodation } + @Cacheable(value = "weeklyCoupon", key = "#accommodationId", cacheManager = "contentCacheManager") public WeeklyCouponResponse weeklyCoupon(String memberId, Long accommodationId) { Accommodation accommodation = checkAccommodationMatchMember(memberId, accommodationId); @@ -65,6 +68,7 @@ public WeeklyCouponResponse weeklyCoupon(String memberId, Long accommodationId) return WeeklyCouponResponse.from(dailyStatisticsList); } + @Cacheable(value = "downloadCouponTop3", key = "#accommodationId", cacheManager = "contentCacheManager") public MonthlyCouponDownloadResponse downloadCouponTop3(String memberId, Long accommodationId) { Accommodation accommodation = checkAccommodationMatchMember(memberId, accommodationId); MonthlySearchDate monthlySearchDate = MonthlySearchDate.getMonthlySearchDate(0,0); @@ -78,6 +82,7 @@ public MonthlyCouponDownloadResponse downloadCouponTop3(String memberId, Long ac } + @Cacheable(value = "couponCountAvg", key = "#accommodationId", cacheManager = "contentCacheManager") public CouponCountAvgResponse couponCountAvg(String memberId,Long accommodationId) { Accommodation accommodation = checkAccommodationMatchMember(memberId, accommodationId); MonthlySearchDate monthlySearchDate = MonthlySearchDate.getMonthlySearchDate(0,0); @@ -91,7 +96,7 @@ public CouponCountAvgResponse couponCountAvg(String memberId,Long accommodationI return getCouponCountAvgResponse(type, localCouponDownload, address); } - + @Cacheable(value = "byYearCumulativeData", key = "#accommodationId", cacheManager = "contentCacheManager") public ByYearCumulativeDataResponse byYearCumulativeData(int year, String memberId, Long accommodationId) { Accommodation accommodation = checkAccommodationMatchMember(memberId, accommodationId); List monthlyStatisticsList = monthlyStatisticsRepository @@ -113,7 +118,7 @@ public ByYearCumulativeDataResponse byYearCumulativeData(int year, String member .map(MonthlyDataLightResponse::from).toList()); } - + @Cacheable(value = "cumulativeData", key = "#accommodationId", cacheManager = "contentCacheManager") public CumulativeDataResponse cumulativeData(String memberId, Long accommodationId) { Accommodation accommodation = checkAccommodationMatchMember(memberId, accommodationId); List monthlyStatisticsList = monthlyStatisticsRepository From a09ec0187e28b2f379e75fcaf488ae344feb15ba Mon Sep 17 00:00:00 2001 From: KwonJuHwan <118177454+KwonJuHwan@users.noreply.github.com> Date: Mon, 22 Jan 2024 18:44:30 +0900 Subject: [PATCH 05/12] =?UTF-8?q?[feat]=20=EC=A0=95=EC=82=B0=20=EC=9A=94?= =?UTF-8?q?=EC=95=BD=20=EC=A1=B0=ED=9A=8C=20=EC=BA=90=EC=8B=B1=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coolpeace/domain/settlement/service/SettlementService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/coolpeace/domain/settlement/service/SettlementService.java b/src/main/java/com/coolpeace/domain/settlement/service/SettlementService.java index 97468424..b0abfaf6 100644 --- a/src/main/java/com/coolpeace/domain/settlement/service/SettlementService.java +++ b/src/main/java/com/coolpeace/domain/settlement/service/SettlementService.java @@ -21,6 +21,7 @@ import java.time.LocalDate; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.Cacheable; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -37,6 +38,7 @@ public class SettlementService { private final AccommodationRepository accommodationRepository; private final MemberRepository memberRepository; + @Cacheable(value = "sumSettlement", key = "#accommodationId", cacheManager = "contentCacheManager") public SumSettlementResponse sumSettlement(String memberId, Long accommodationId) { Accommodation accommodation = checkAccommodationMatchMember(memberId, accommodationId); MonthlySearchDate monthlySearchDate = MonthlySearchDate.getMonthlySearchDate(0,0); From 2906644076edc8dbe7980106a6a1fee0240c6bb0 Mon Sep 17 00:00:00 2001 From: KwonJuHwan <118177454+KwonJuHwan@users.noreply.github.com> Date: Mon, 22 Jan 2024 19:17:24 +0900 Subject: [PATCH 06/12] =?UTF-8?q?[feat]=20=EC=9D=BC=EA=B0=84=20=EC=BF=A0?= =?UTF-8?q?=ED=8F=B0=20=EB=A6=AC=ED=8F=AC=ED=8A=B8=20=EC=BA=90=EC=8B=B1=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coolpeace/domain/coupon/service/CouponQueryService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/coolpeace/domain/coupon/service/CouponQueryService.java b/src/main/java/com/coolpeace/domain/coupon/service/CouponQueryService.java index 1299f0db..32515437 100644 --- a/src/main/java/com/coolpeace/domain/coupon/service/CouponQueryService.java +++ b/src/main/java/com/coolpeace/domain/coupon/service/CouponQueryService.java @@ -6,6 +6,7 @@ import com.coolpeace.domain.coupon.repository.CouponRepository; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,17 +17,21 @@ public class CouponQueryService { private final CouponRepository couponRepository; + @Cacheable(value = "dailyReport", key = "#accommodationId",cacheManager = "contentCacheManager") public CouponDailyResponse dailyReport(String jwtPrincipal, Long accommodationId) { Long memberId = Long.valueOf(jwtPrincipal); + if (Boolean.TRUE.equals(couponRepository.noRegister(memberId, accommodationId))) { return CouponDailyResponse.from(1,CouponDailyCondition.NO_REGISTER); } + List expiration3daysCoupons = couponRepository.expiration3days(memberId, accommodationId); if (!expiration3daysCoupons.isEmpty()) { return CouponDailyResponse.from(3, CouponDailyCondition.EXPIRATION_3DAYS, expiration3daysCoupons.stream().map(Coupon::getCouponTitle).toList()); } + if (Boolean.TRUE.equals(couponRepository.noExposure(memberId, accommodationId))) { return CouponDailyResponse.from(2, CouponDailyCondition.NO_EXPOSURE); } From a617a48c11053bef2f5c537652e0ec1d28e6ec09 Mon Sep 17 00:00:00 2001 From: KwonJuHwan <118177454+KwonJuHwan@users.noreply.github.com> Date: Mon, 22 Jan 2024 19:18:10 +0900 Subject: [PATCH 07/12] =?UTF-8?q?[feat]=20=EC=BF=A0=ED=8F=B0=EC=9D=B4=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=EB=90=A0=20=EB=95=8C,=20=EC=9D=BC=EA=B0=84?= =?UTF-8?q?=20=EC=BF=A0=ED=8F=B0=20=EB=A6=AC=ED=8F=AC=ED=8A=B8=20=EC=BA=90?= =?UTF-8?q?=EC=8B=9C=20=EC=82=AD=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/coupon/service/CouponService.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/coolpeace/domain/coupon/service/CouponService.java b/src/main/java/com/coolpeace/domain/coupon/service/CouponService.java index 0154abc2..568316a1 100644 --- a/src/main/java/com/coolpeace/domain/coupon/service/CouponService.java +++ b/src/main/java/com/coolpeace/domain/coupon/service/CouponService.java @@ -10,7 +10,12 @@ import com.coolpeace.domain.coupon.dto.response.CouponCategoryResponse; import com.coolpeace.domain.coupon.dto.response.CouponResponse; import com.coolpeace.domain.coupon.entity.Coupon; -import com.coolpeace.domain.coupon.entity.type.*; +import com.coolpeace.domain.coupon.entity.type.CouponIssuerType; +import com.coolpeace.domain.coupon.entity.type.CouponRoomType; +import com.coolpeace.domain.coupon.entity.type.CouponStatusType; +import com.coolpeace.domain.coupon.entity.type.CouponUseDaysType; +import com.coolpeace.domain.coupon.entity.type.CustomerType; +import com.coolpeace.domain.coupon.entity.type.DiscountType; import com.coolpeace.domain.coupon.exception.CouponAccessDeniedException; import com.coolpeace.domain.coupon.exception.CouponNotFoundException; import com.coolpeace.domain.coupon.exception.CouponUpdateLimitExposureStateException; @@ -24,7 +29,13 @@ import com.coolpeace.domain.room.exception.RoomNotFoundException; import com.coolpeace.domain.room.repository.RoomRepository; import com.coolpeace.global.common.ValuedEnum; +import java.time.LocalDate; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -33,12 +44,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; -import java.time.LocalDate; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; - @RequiredArgsConstructor @Service public class CouponService { @@ -84,6 +89,7 @@ public List getRecentHistory(Long memberId) { } @Transactional + @CacheEvict(value = "dailyReport", key = "#couponRegisterRequest.accommodationId()",cacheManager = "contentCacheManager") public void register(Long memberId, CouponRegisterRequest couponRegisterRequest) { Member storedMember = memberRepository.findById(memberId).orElseThrow(MemberNotFoundException::new); Accommodation accommodation = accommodationRepository.findById(couponRegisterRequest.accommodationId()) From 28e912ca8f7d9b373fb501c6cddfac083af01908 Mon Sep 17 00:00:00 2001 From: KwonJuHwan <118177454+KwonJuHwan@users.noreply.github.com> Date: Mon, 22 Jan 2024 19:19:00 +0900 Subject: [PATCH 08/12] =?UTF-8?q?[feat]=20=EC=9D=BC=EC=9D=BC=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=ED=95=A0=20=EB=95=8C=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=88=EB=8B=AC=20=EC=BF=A0=ED=8F=B0=20=ED=98=84=ED=99=A9,?= =?UTF-8?q?=20=EC=A0=95=EC=82=B0=20=EC=9A=94=EC=95=BD=20=EC=BA=90=EC=8B=9C?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/statistics/service/DailyStatisticsService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/coolpeace/domain/statistics/service/DailyStatisticsService.java b/src/main/java/com/coolpeace/domain/statistics/service/DailyStatisticsService.java index a4970f39..9357bfd9 100644 --- a/src/main/java/com/coolpeace/domain/statistics/service/DailyStatisticsService.java +++ b/src/main/java/com/coolpeace/domain/statistics/service/DailyStatisticsService.java @@ -13,11 +13,12 @@ import com.coolpeace.domain.statistics.entity.DailyStatistics; import com.coolpeace.domain.statistics.exception.DailyStatisticsNotFoundException; import com.coolpeace.domain.statistics.repository.DailyStatisticsRepository; -import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -33,6 +34,7 @@ public class DailyStatisticsService { private final SettlementRepository settlementRepository; + @CacheEvict(value = "weeklyCoupon", cacheManager = "contentCacheManager") public void updateSales(int statisticsYear, int statisticsMonth, int statisticsDay){ DailySearchDate dailySearchDate = DailySearchDate. getDailySearchDate(statisticsYear,statisticsMonth,statisticsDay); @@ -90,6 +92,7 @@ public void updateCoupon(int statisticsYear, int statisticsMonth, int statistics }); } + @CacheEvict(value = "sumSettlement", cacheManager = "contentCacheManager") public void updateSettlement(int statisticsYear, int statisticsMonth, int statisticsDay){ DailySearchDate dailySearchDate = DailySearchDate. getDailySearchDate(statisticsYear,statisticsMonth,statisticsDay); From 5e65e12aa0d9fbc9f78fb403ca8b6849aba8b1ba Mon Sep 17 00:00:00 2001 From: KwonJuHwan <118177454+KwonJuHwan@users.noreply.github.com> Date: Mon, 22 Jan 2024 19:20:04 +0900 Subject: [PATCH 09/12] =?UTF-8?q?[feat]=20=EC=9B=94=EB=B3=84=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=ED=95=A0=20=EB=95=8C=20=EC=9B=94?= =?UTF-8?q?=EA=B0=84=20=EB=B9=84=EA=B5=90=20=EA=B7=B8=EB=9E=98=ED=94=84,?= =?UTF-8?q?=20=EC=A7=80=EC=97=AD=20=EC=BF=A0=ED=8F=B0=20=EB=8B=A4=EC=9A=B4?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20Top3,=20=ED=8F=89=EA=B7=A0=20=EC=BF=A0?= =?UTF-8?q?=ED=8F=B0=20=EA=B0=9C=EC=88=98,=20=EC=97=B0=EB=8F=84=EB=B3=84?= =?UTF-8?q?=20=ED=86=B5=EA=B3=84,=20=EB=88=84=EC=A0=81=20=ED=86=B5?= =?UTF-8?q?=EA=B3=84=20=EC=BA=90=EC=8B=9C=20=EC=82=AD=EC=A0=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/statistics/service/MonthlyStatisticsService.java | 4 +++- .../java/com/coolpeace/global/config/RedisCacheConfig.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/coolpeace/domain/statistics/service/MonthlyStatisticsService.java b/src/main/java/com/coolpeace/domain/statistics/service/MonthlyStatisticsService.java index fc60ce8b..d00b543d 100644 --- a/src/main/java/com/coolpeace/domain/statistics/service/MonthlyStatisticsService.java +++ b/src/main/java/com/coolpeace/domain/statistics/service/MonthlyStatisticsService.java @@ -17,6 +17,7 @@ import java.time.LocalDate; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -31,6 +32,7 @@ public class MonthlyStatisticsService { private final LocalCouponDownloadRepository localCouponDownloadRepository; private final AccommodationRepository accommodationRepository; + @CacheEvict(value = {"monthlyData","byYearCumulativeData","cumulativeData "}, cacheManager = "contentCacheManager") public void updateMonthlySum(int statisticsYear, int statisticsMonth) { MonthlySearchDate monthlySearchDate = MonthlySearchDate. getMonthlySearchDate(statisticsYear,statisticsMonth); @@ -64,7 +66,7 @@ public void updateMonthlySum(int statisticsYear, int statisticsMonth) { }); } - + @CacheEvict(value = {"downloadCouponTop3","couponCountAvg"}, cacheManager = "contentCacheManager") public void updateCouponDownloadTop3(int statisticsYear, int statisticsMonth) { MonthlySearchDate monthlySearchDate = MonthlySearchDate. getMonthlySearchDate(statisticsYear,statisticsMonth); diff --git a/src/main/java/com/coolpeace/global/config/RedisCacheConfig.java b/src/main/java/com/coolpeace/global/config/RedisCacheConfig.java index 1bab6107..7ed062fb 100644 --- a/src/main/java/com/coolpeace/global/config/RedisCacheConfig.java +++ b/src/main/java/com/coolpeace/global/config/RedisCacheConfig.java @@ -23,7 +23,7 @@ public CacheManager contentCacheManager(RedisConnectionFactory cf) { new StringRedisSerializer())) .serializeValuesWith(SerializationPair.fromSerializer( new GenericJackson2JsonRedisSerializer())) - .entryTtl(Duration.ofHours(6)); + .entryTtl(Duration.ofHours(12)); return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(cf) .cacheDefaults(redisCacheConfiguration).build(); From fcda2d4695519778fb6969067e5127716fa49f9c Mon Sep 17 00:00:00 2001 From: KwonJuHwan <118177454+KwonJuHwan@users.noreply.github.com> Date: Mon, 22 Jan 2024 19:20:56 +0900 Subject: [PATCH 10/12] =?UTF-8?q?[feat]=20Wrapper=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EA=B5=AC=ED=98=84=EC=9C=BC=EB=A1=9C=20=EC=9D=B8?= =?UTF-8?q?=ED=95=9C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=BD=94=EB=93=9C=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 --- .../domain/dashboard/service/DashboardService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/coolpeace/domain/dashboard/service/DashboardService.java b/src/main/java/com/coolpeace/domain/dashboard/service/DashboardService.java index 0be16b00..388e3bdd 100644 --- a/src/main/java/com/coolpeace/domain/dashboard/service/DashboardService.java +++ b/src/main/java/com/coolpeace/domain/dashboard/service/DashboardService.java @@ -13,6 +13,7 @@ import com.coolpeace.domain.dashboard.dto.response.MonthlyDataLightResponse; import com.coolpeace.domain.dashboard.dto.response.MonthlyDataResponse; import com.coolpeace.domain.dashboard.dto.response.WeeklyCouponResponse; +import com.coolpeace.domain.dashboard.dto.response.WrapMonthlyDataResponse; import com.coolpeace.domain.member.entity.Member; import com.coolpeace.domain.member.exception.MemberNotFoundException; import com.coolpeace.domain.member.repository.MemberRepository; @@ -44,7 +45,7 @@ public class DashboardService { private final LocalCouponDownloadRepository localCouponDownloadRepository; @Cacheable(value = "monthlyData", key = "#accommodationId", cacheManager = "contentCacheManager") - public List monthlyData(String memberId, Long accommodationId) { + public WrapMonthlyDataResponse monthlyData(String memberId, Long accommodationId) { Accommodation accommodation = checkAccommodationMatchMember(memberId, accommodationId); MonthlySearchDate monthlySearchDate = MonthlySearchDate.getMonthlySearchDate(0,0); @@ -53,9 +54,8 @@ public List monthlyData(String memberId, Long accommodation monthlyStatisticsRepository.findLast6monthsMonthlyStatistics (accommodation, last6Months[0], last6Months[1], last6Months[2], last6Months[3]); - return last6monthsMonthlyStatistics.stream() - .map(MonthlyDataResponse::from).toList(); - + return WrapMonthlyDataResponse.from(last6monthsMonthlyStatistics.stream() + .map(MonthlyDataResponse::from).toList()); } @Cacheable(value = "weeklyCoupon", key = "#accommodationId", cacheManager = "contentCacheManager") From 8640ec91b4b628e2da271c9cbfde01d3d169dfda Mon Sep 17 00:00:00 2001 From: KwonJuHwan <118177454+KwonJuHwan@users.noreply.github.com> Date: Mon, 22 Jan 2024 19:21:05 +0900 Subject: [PATCH 11/12] =?UTF-8?q?[feat]=20Wrapper=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EA=B5=AC=ED=98=84=EC=9C=BC=EB=A1=9C=20=EC=9D=B8?= =?UTF-8?q?=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=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 --- .../dashboard/DashboardControllerTest.java | 21 ++++---- .../controller/DashboardControllerTest.java | 52 ++++++++++--------- .../service/DashboardServiceTest.java | 16 +++--- 3 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/test/java/com/coolpeace/docs/dashboard/DashboardControllerTest.java b/src/test/java/com/coolpeace/docs/dashboard/DashboardControllerTest.java index 2f1c9673..6550fa9f 100644 --- a/src/test/java/com/coolpeace/docs/dashboard/DashboardControllerTest.java +++ b/src/test/java/com/coolpeace/docs/dashboard/DashboardControllerTest.java @@ -24,6 +24,7 @@ import com.coolpeace.domain.dashboard.dto.response.MonthlyDataLightResponse; import com.coolpeace.domain.dashboard.dto.response.MonthlyDataResponse; import com.coolpeace.domain.dashboard.dto.response.WeeklyCouponResponse; +import com.coolpeace.domain.dashboard.dto.response.WrapMonthlyDataResponse; import com.coolpeace.domain.dashboard.service.DashboardService; import com.coolpeace.domain.member.entity.Member; import com.coolpeace.domain.room.entity.Room; @@ -68,7 +69,9 @@ void monthlyData_success() throws Exception { List monthlyDataResponses = monthlyStatistics.stream() .map(MonthlyDataResponse::from).toList(); - given(dashboardService.monthlyData(any(), anyLong())).willReturn(monthlyDataResponses); + WrapMonthlyDataResponse wrapMonthlyDataResponse = + WrapMonthlyDataResponse.from(monthlyDataResponses); + given(dashboardService.monthlyData(any(), anyLong())).willReturn(wrapMonthlyDataResponse); //when,then mockMvc.perform(RestDocumentationRequestBuilders .get("/v1/dashboards/{accommodation_id}/reports/month", 1L) @@ -80,21 +83,21 @@ void monthlyData_success() throws Exception { .description("월간 비교 그래프 조회 API") .responseSchema(Schema.schema(MonthlyDataResponse.class.getSimpleName())) .responseFields( - fieldWithPath("[].statistics_year").type(JsonFieldType.NUMBER) + fieldWithPath(".monthly_data_responses[].statistics_year").type(JsonFieldType.NUMBER) .description("통계 집계한 연도"), - fieldWithPath("[].statistics_month").type(JsonFieldType.NUMBER) + fieldWithPath(".monthly_data_responses[].statistics_month").type(JsonFieldType.NUMBER) .description("통계 집계한 월"), - fieldWithPath("[].total_sales").type(JsonFieldType.NUMBER) + fieldWithPath(".monthly_data_responses[].total_sales").type(JsonFieldType.NUMBER) .description("해당 월 총 매출 "), - fieldWithPath("[].coupon_total_sales").type(JsonFieldType.NUMBER) + fieldWithPath(".monthly_data_responses[].coupon_total_sales").type(JsonFieldType.NUMBER) .description("쿠폰 적용 매출"), - fieldWithPath("[].download_count").type(JsonFieldType.NUMBER) + fieldWithPath(".monthly_data_responses[].download_count").type(JsonFieldType.NUMBER) .description("쿠폰 다운로드 수"), - fieldWithPath("[].used_count").type(JsonFieldType.NUMBER) + fieldWithPath(".monthly_data_responses[].used_count").type(JsonFieldType.NUMBER) .description("쿠폰 사용 완료 수 "), - fieldWithPath("[].settlement_amount").type(JsonFieldType.NUMBER) + fieldWithPath(".monthly_data_responses[].settlement_amount").type(JsonFieldType.NUMBER) .description("이번달 쿠폰 정산 금액"), - fieldWithPath("[].conversion_rate").type(JsonFieldType.NUMBER) + fieldWithPath(".monthly_data_responses[].conversion_rate").type(JsonFieldType.NUMBER) .description("전환율") ) .build() diff --git a/src/test/java/com/coolpeace/domain/dashboard/controller/DashboardControllerTest.java b/src/test/java/com/coolpeace/domain/dashboard/controller/DashboardControllerTest.java index 09e414f6..7aac0402 100644 --- a/src/test/java/com/coolpeace/domain/dashboard/controller/DashboardControllerTest.java +++ b/src/test/java/com/coolpeace/domain/dashboard/controller/DashboardControllerTest.java @@ -11,6 +11,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.coolpeace.domain.dashboard.dto.response.CouponCountAvgResponse; +import com.coolpeace.domain.dashboard.dto.response.WrapMonthlyDataResponse; import com.coolpeace.global.util.RoomTestUtil; import com.coolpeace.domain.accommodation.entity.Accommodation; import com.coolpeace.domain.coupon.dto.response.CouponDailyResponse; @@ -64,35 +65,36 @@ void monthlyData_success() throws Exception { List monthlyStatistics = getMonthlyStatistics(member, accommodation); List monthlyDataResponses = monthlyStatistics.stream() .map(MonthlyDataResponse::from).toList(); + WrapMonthlyDataResponse wrapMonthlyDataResponse = WrapMonthlyDataResponse.from(monthlyDataResponses); - given(dashboardService.monthlyData(any(), anyLong())).willReturn(monthlyDataResponses); + given(dashboardService.monthlyData(any(), anyLong())).willReturn(wrapMonthlyDataResponse); //when,then mockMvc.perform(get("/v1/dashboards/{accommodation_id}/reports/month", 1L)) .andExpect(status().isOk()) - .andExpect(jsonPath("$[0].statistics_year").isNumber()) - .andExpect(jsonPath("$[0].statistics_month").isNumber()) - .andExpect(jsonPath("$[0].total_sales").isNumber()) - .andExpect(jsonPath("$[0].coupon_total_sales").isNumber()) - .andExpect(jsonPath("$[0].download_count").isNumber()) - .andExpect(jsonPath("$[0].used_count").isNumber()) - .andExpect(jsonPath("$[0].settlement_amount").isNumber()) - .andExpect(jsonPath("$[0].conversion_rate").isNumber()) - .andExpect(jsonPath("$[1].statistics_year").isNumber()) - .andExpect(jsonPath("$[1].statistics_month").isNumber()) - .andExpect(jsonPath("$[1].total_sales").isNumber()) - .andExpect(jsonPath("$[1].coupon_total_sales").isNumber()) - .andExpect(jsonPath("$[1].download_count").isNumber()) - .andExpect(jsonPath("$[1].used_count").isNumber()) - .andExpect(jsonPath("$[1].settlement_amount").isNumber()) - .andExpect(jsonPath("$[1].conversion_rate").isNumber()) - .andExpect(jsonPath("$[2].statistics_year").isNumber()) - .andExpect(jsonPath("$[2].statistics_month").isNumber()) - .andExpect(jsonPath("$[2].total_sales").isNumber()) - .andExpect(jsonPath("$[2].coupon_total_sales").isNumber()) - .andExpect(jsonPath("$[2].download_count").isNumber()) - .andExpect(jsonPath("$[2].used_count").isNumber()) - .andExpect(jsonPath("$[2].settlement_amount").isNumber()) - .andExpect(jsonPath("$[2].conversion_rate").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[0].statistics_year").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[0].statistics_month").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[0].total_sales").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[0].coupon_total_sales").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[0].download_count").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[0].used_count").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[0].settlement_amount").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[0].conversion_rate").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[1].statistics_year").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[1].statistics_month").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[1].total_sales").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[1].coupon_total_sales").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[1].download_count").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[1].used_count").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[1].settlement_amount").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[1].conversion_rate").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[2].statistics_year").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[2].statistics_month").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[2].total_sales").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[2].coupon_total_sales").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[2].download_count").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[2].used_count").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[2].settlement_amount").isNumber()) + .andExpect(jsonPath("$.monthly_data_responses[2].conversion_rate").isNumber()) .andDo(print()); } diff --git a/src/test/java/com/coolpeace/domain/dashboard/service/DashboardServiceTest.java b/src/test/java/com/coolpeace/domain/dashboard/service/DashboardServiceTest.java index 3b556d21..7c124048 100644 --- a/src/test/java/com/coolpeace/domain/dashboard/service/DashboardServiceTest.java +++ b/src/test/java/com/coolpeace/domain/dashboard/service/DashboardServiceTest.java @@ -17,8 +17,8 @@ import com.coolpeace.domain.dashboard.dto.response.CouponCountAvgResponse; import com.coolpeace.domain.dashboard.dto.response.CumulativeDataResponse; import com.coolpeace.domain.dashboard.dto.response.MonthlyCouponDownloadResponse; -import com.coolpeace.domain.dashboard.dto.response.MonthlyDataResponse; import com.coolpeace.domain.dashboard.dto.response.WeeklyCouponResponse; +import com.coolpeace.domain.dashboard.dto.response.WrapMonthlyDataResponse; import com.coolpeace.domain.member.entity.Member; import com.coolpeace.domain.member.exception.MemberNotFoundException; import com.coolpeace.domain.member.repository.MemberRepository; @@ -30,7 +30,6 @@ import com.coolpeace.domain.statistics.repository.MonthlyStatisticsRepository; import com.coolpeace.global.builder.AccommodationTestBuilder; import com.coolpeace.global.builder.MemberTestBuilder; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -143,15 +142,18 @@ void monthlyData_success() { anyInt(), anyInt(), anyInt(), anyInt())).willReturn(monthlyStatisticsList); //when - List monthlyDataResponses = dashboardService.monthlyData("1", 1L); + WrapMonthlyDataResponse wrapMonthlyDataResponse = dashboardService.monthlyData("1", 1L); //then - assertThat(monthlyDataResponses).hasSize(3); - assertThat(monthlyDataResponses.get(0)).extracting("totalSales", "statisticsMonth","conversionRate") + assertThat(wrapMonthlyDataResponse.monthlyDataResponses()).hasSize(3); + assertThat(wrapMonthlyDataResponse.monthlyDataResponses().get(0)) + .extracting("totalSales", "statisticsMonth","conversionRate") .containsExactly(10000000, 12,71); - assertThat(monthlyDataResponses.get(1)).extracting("totalSales", "statisticsMonth","conversionRate") + assertThat(wrapMonthlyDataResponse.monthlyDataResponses().get(1)) + .extracting("totalSales", "statisticsMonth","conversionRate") .containsExactly(20000000, 11,71); - assertThat(monthlyDataResponses.get(2)).extracting("totalSales", "statisticsMonth","conversionRate") + assertThat(wrapMonthlyDataResponse.monthlyDataResponses().get(2)) + .extracting("totalSales", "statisticsMonth","conversionRate") .containsExactly(30000000, 10,71); } From 65ea500a49ef177e28c5ae98f00f74239918f0f4 Mon Sep 17 00:00:00 2001 From: KwonJuHwan <118177454+KwonJuHwan@users.noreply.github.com> Date: Mon, 22 Jan 2024 19:22:09 +0900 Subject: [PATCH 12/12] =?UTF-8?q?[feat]=20Redis=20=EC=BA=90=EC=8B=B1=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20List=EB=A5=BC=20=EC=9D=BD?= =?UTF-8?q?=EC=96=B4=EC=98=AC=20=EB=95=8C,=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EB=B0=A9=EC=A7=80=EB=A5=BC=20=EC=9C=84=ED=95=9C=20Wrapper=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/WrapMonthlyDataResponse.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/com/coolpeace/domain/dashboard/dto/response/WrapMonthlyDataResponse.java diff --git a/src/main/java/com/coolpeace/domain/dashboard/dto/response/WrapMonthlyDataResponse.java b/src/main/java/com/coolpeace/domain/dashboard/dto/response/WrapMonthlyDataResponse.java new file mode 100644 index 00000000..27ff864f --- /dev/null +++ b/src/main/java/com/coolpeace/domain/dashboard/dto/response/WrapMonthlyDataResponse.java @@ -0,0 +1,12 @@ +package com.coolpeace.domain.dashboard.dto.response; + +import java.util.List; + +public record WrapMonthlyDataResponse ( + List monthlyDataResponses +){ + + public static WrapMonthlyDataResponse from(List monthlyDataResponses) { + return new WrapMonthlyDataResponse(monthlyDataResponses); + } +}