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) { 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()); 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); } 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 3cd72527..39dbf050 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 { @@ -85,6 +90,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()) 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); + } +} 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..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; @@ -28,6 +29,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,7 +44,8 @@ public class DashboardService { private final AccommodationRepository accommodationRepository; private final LocalCouponDownloadRepository localCouponDownloadRepository; - public List monthlyData(String memberId, Long accommodationId) { + @Cacheable(value = "monthlyData", key = "#accommodationId", cacheManager = "contentCacheManager") + public WrapMonthlyDataResponse monthlyData(String memberId, Long accommodationId) { Accommodation accommodation = checkAccommodationMatchMember(memberId, accommodationId); MonthlySearchDate monthlySearchDate = MonthlySearchDate.getMonthlySearchDate(0,0); @@ -51,11 +54,11 @@ 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") 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 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); 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); 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 new file mode 100644 index 00000000..7ed062fb --- /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(12)); + + return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(cf) + .cacheDefaults(redisCacheConfiguration).build(); + } +} 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); }