diff --git a/src/main/java/com/flab/shoeauction/controller/TradeApiController.java b/src/main/java/com/flab/shoeauction/controller/TradeApiController.java index 9ba610f..dfce17c 100644 --- a/src/main/java/com/flab/shoeauction/controller/TradeApiController.java +++ b/src/main/java/com/flab/shoeauction/controller/TradeApiController.java @@ -5,13 +5,16 @@ import com.flab.shoeauction.controller.dto.TradeDto; import com.flab.shoeauction.controller.dto.TradeDto.ChangeRequest; import com.flab.shoeauction.controller.dto.TradeDto.ImmediateTradeRequest; +import com.flab.shoeauction.controller.dto.TradeDto.MonthlyTradingVolumesResponse; import com.flab.shoeauction.controller.dto.TradeDto.ReasonRequest; import com.flab.shoeauction.controller.dto.TradeDto.TrackingNumberRequest; import com.flab.shoeauction.controller.dto.TradeDto.TradeInfoResponse; +import com.flab.shoeauction.controller.dto.TradeDto.TradeMonthSearchCondition; import com.flab.shoeauction.controller.dto.TradeDto.TradeResource; import com.flab.shoeauction.controller.dto.TradeDto.TradeSearchCondition; import com.flab.shoeauction.domain.users.common.UserLevel; import com.flab.shoeauction.service.TradeService; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -127,4 +130,10 @@ public Page getTradeInfos(TradeSearchCondition tradeSearchCon Pageable pageable) { return tradeService.getTradeInfos(tradeSearchCondition, pageable); } + + @LoginCheck(authority =UserLevel.ADMIN) + @GetMapping("/month-volumes") + public List getMonthVolumes(TradeMonthSearchCondition tradeMonthSearchCondition) { + return tradeService.getMonthlyTradingVolumes(tradeMonthSearchCondition); + } } \ No newline at end of file diff --git a/src/main/java/com/flab/shoeauction/controller/dto/TradeDto.java b/src/main/java/com/flab/shoeauction/controller/dto/TradeDto.java index 18a5911..e52f6ff 100644 --- a/src/main/java/com/flab/shoeauction/controller/dto/TradeDto.java +++ b/src/main/java/com/flab/shoeauction/controller/dto/TradeDto.java @@ -176,6 +176,7 @@ public boolean isSearchByBuyer() { @Getter @NoArgsConstructor public static class TradeInfoResponse { + private Long id; private TradeStatus status; @@ -189,6 +190,7 @@ public TradeInfoResponse(Long id, TradeStatus status) { @Getter @NoArgsConstructor public static class TradeCompleteInfo { + private double productSize; private Long price; private LocalDateTime completeTime; @@ -200,4 +202,18 @@ public TradeCompleteInfo(double productSize, Long price, LocalDateTime completeT this.completeTime = completeTime; } } -} \ No newline at end of file + + @Getter + @NoArgsConstructor + public static class TradeMonthSearchCondition { + private String year; + } + + @Getter + @NoArgsConstructor + public static class MonthlyTradingVolumesResponse { + private String date; + private Long count; + } +} + diff --git a/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepository.java b/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepository.java index 6762d89..0cf99c7 100644 --- a/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepository.java +++ b/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepository.java @@ -1,8 +1,11 @@ package com.flab.shoeauction.domain.trade; +import com.flab.shoeauction.controller.dto.TradeDto.MonthlyTradingVolumesResponse; import com.flab.shoeauction.controller.dto.TradeDto.TradeInfoResponse; +import com.flab.shoeauction.controller.dto.TradeDto.TradeMonthSearchCondition; import com.flab.shoeauction.controller.dto.TradeDto.TradeSearchCondition; import com.flab.shoeauction.domain.users.user.User; +import java.util.List; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -10,5 +13,9 @@ public interface SearchTradeRepository { boolean existsProgressingByUser(User user); - Page searchByTradeStatusAndTradeId(TradeSearchCondition searchCondition, Pageable pageable); + Page searchByTradeStatusAndTradeId(TradeSearchCondition searchCondition, + Pageable pageable); + + List searchTradeVolumeByMonth( + TradeMonthSearchCondition tradeMonthSearchCondition); } diff --git a/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepositoryImpl.java b/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepositoryImpl.java index 6a3be2a..a177f93 100644 --- a/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepositoryImpl.java +++ b/src/main/java/com/flab/shoeauction/domain/trade/SearchTradeRepositoryImpl.java @@ -2,12 +2,17 @@ import static com.flab.shoeauction.domain.trade.QTrade.trade; +import com.flab.shoeauction.controller.dto.TradeDto.MonthlyTradingVolumesResponse; import com.flab.shoeauction.controller.dto.TradeDto.TradeInfoResponse; +import com.flab.shoeauction.controller.dto.TradeDto.TradeMonthSearchCondition; import com.flab.shoeauction.controller.dto.TradeDto.TradeSearchCondition; import com.flab.shoeauction.domain.users.user.User; import com.querydsl.core.QueryResults; +import com.querydsl.core.types.ConstantImpl; import com.querydsl.core.types.Projections; import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.core.types.dsl.StringTemplate; import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.List; import lombok.RequiredArgsConstructor; @@ -54,7 +59,32 @@ public Page searchByTradeStatusAndTradeId(TradeSearchConditio } return searchByTradeId(searchRequest.getTradeId(), pageable); + } + + @Override + public List searchTradeVolumeByMonth( + TradeMonthSearchCondition tradeMonthSearchCondition) { + + StringTemplate dateFormat = Expressions.stringTemplate( + "DATE_FORMAT({0}, {1})", trade.modifiedDate, ConstantImpl.create("%Y-%m")); + + List results = jpaQueryFactory + .select(Projections.fields(MonthlyTradingVolumesResponse.class, + trade.id.count().as("count"), + dateFormat.as("date") + )).from(trade) + .where(statusEqAndDateContains(tradeMonthSearchCondition, dateFormat)) + .groupBy(dateFormat) + .fetch(); + + return results; + } + private BooleanExpression statusEqAndDateContains( + TradeMonthSearchCondition tradeMonthSearchCondition, + StringTemplate dateFormat) { + return trade.status.eq(TradeStatus.TRADE_COMPLETE).and(dateFormat.contains( + tradeMonthSearchCondition.getYear())); } private Page searchByTradeId(Long tradeId, Pageable pageable) { diff --git a/src/main/java/com/flab/shoeauction/service/TradeService.java b/src/main/java/com/flab/shoeauction/service/TradeService.java index 96b37a2..13815e5 100644 --- a/src/main/java/com/flab/shoeauction/service/TradeService.java +++ b/src/main/java/com/flab/shoeauction/service/TradeService.java @@ -7,8 +7,10 @@ import com.flab.shoeauction.controller.dto.ProductDto.ProductInfoByTrade; import com.flab.shoeauction.controller.dto.TradeDto.ChangeRequest; import com.flab.shoeauction.controller.dto.TradeDto.ImmediateTradeRequest; +import com.flab.shoeauction.controller.dto.TradeDto.MonthlyTradingVolumesResponse; import com.flab.shoeauction.controller.dto.TradeDto.SaveRequest; import com.flab.shoeauction.controller.dto.TradeDto.TradeInfoResponse; +import com.flab.shoeauction.controller.dto.TradeDto.TradeMonthSearchCondition; import com.flab.shoeauction.controller.dto.TradeDto.TradeResource; import com.flab.shoeauction.controller.dto.TradeDto.TradeSearchCondition; import com.flab.shoeauction.controller.dto.UserDto.TradeUserInfo; @@ -23,6 +25,7 @@ import com.flab.shoeauction.exception.user.NotAuthorizedException; import com.flab.shoeauction.exception.user.UserNotFoundException; import com.flab.shoeauction.service.message.MessageService; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CacheEvict; import org.springframework.data.domain.Page; @@ -218,4 +221,9 @@ public void confirmPurchase(Long tradeId, String email) { pointService.salesPointReceive(trade.getSeller(), trade.getPrice()); } + + public List getMonthlyTradingVolumes( + TradeMonthSearchCondition tradeMonthSearchCondition) { + return tradeRepository.searchTradeVolumeByMonth(tradeMonthSearchCondition); + } } \ No newline at end of file