Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
[#131] feat : 월별 거래량 조회 (#132)
Browse files Browse the repository at this point in the history
1. ADMIN 권한을 가진 사용자가 연도별 검색을 통해 1월~12월 거래량을 확인할 수 있다.

issue number : #131
  • Loading branch information
kihyuk-jeong authored May 31, 2021
1 parent d6615e7 commit eb6e5e8
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -127,4 +130,10 @@ public Page<TradeInfoResponse> getTradeInfos(TradeSearchCondition tradeSearchCon
Pageable pageable) {
return tradeService.getTradeInfos(tradeSearchCondition, pageable);
}

@LoginCheck(authority =UserLevel.ADMIN)
@GetMapping("/month-volumes")
public List<MonthlyTradingVolumesResponse> getMonthVolumes(TradeMonthSearchCondition tradeMonthSearchCondition) {
return tradeService.getMonthlyTradingVolumes(tradeMonthSearchCondition);
}
}
18 changes: 17 additions & 1 deletion src/main/java/com/flab/shoeauction/controller/dto/TradeDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public boolean isSearchByBuyer() {
@Getter
@NoArgsConstructor
public static class TradeInfoResponse {

private Long id;
private TradeStatus status;

Expand All @@ -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;
Expand All @@ -200,4 +202,18 @@ public TradeCompleteInfo(double productSize, Long price, LocalDateTime completeT
this.completeTime = completeTime;
}
}
}

@Getter
@NoArgsConstructor
public static class TradeMonthSearchCondition {
private String year;
}

@Getter
@NoArgsConstructor
public static class MonthlyTradingVolumesResponse {
private String date;
private Long count;
}
}

Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
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;

public interface SearchTradeRepository {

boolean existsProgressingByUser(User user);

Page<TradeInfoResponse> searchByTradeStatusAndTradeId(TradeSearchCondition searchCondition, Pageable pageable);
Page<TradeInfoResponse> searchByTradeStatusAndTradeId(TradeSearchCondition searchCondition,
Pageable pageable);

List<MonthlyTradingVolumesResponse> searchTradeVolumeByMonth(
TradeMonthSearchCondition tradeMonthSearchCondition);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,7 +59,32 @@ public Page<TradeInfoResponse> searchByTradeStatusAndTradeId(TradeSearchConditio
}

return searchByTradeId(searchRequest.getTradeId(), pageable);
}

@Override
public List<MonthlyTradingVolumesResponse> searchTradeVolumeByMonth(
TradeMonthSearchCondition tradeMonthSearchCondition) {

StringTemplate dateFormat = Expressions.stringTemplate(
"DATE_FORMAT({0}, {1})", trade.modifiedDate, ConstantImpl.create("%Y-%m"));

List<MonthlyTradingVolumesResponse> 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<TradeInfoResponse> searchByTradeId(Long tradeId, Pageable pageable) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/flab/shoeauction/service/TradeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -218,4 +221,9 @@ public void confirmPurchase(Long tradeId, String email) {

pointService.salesPointReceive(trade.getSeller(), trade.getPrice());
}

public List<MonthlyTradingVolumesResponse> getMonthlyTradingVolumes(
TradeMonthSearchCondition tradeMonthSearchCondition) {
return tradeRepository.searchTradeVolumeByMonth(tradeMonthSearchCondition);
}
}

0 comments on commit eb6e5e8

Please sign in to comment.