Skip to content

Commit

Permalink
Merge pull request #139 from survey-mate/develop
Browse files Browse the repository at this point in the history
수정사항 배포
  • Loading branch information
JinhyeokFang authored Feb 15, 2024
2 parents 393af25 + 67cf984 commit 3f395ed
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import jakarta.transaction.Transactional;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -112,6 +115,8 @@ public Data getData(Long dataId) {
.orElseThrow(() -> new GeneralException(Status.DATA_NOT_FOUND));
}

public List<Data> getDataList() { return dataRepository.findAll(Sort.by(Sort.Direction.DESC, "createdAt")); }

public List<Data> getDataListAsBuyer(Member buyer) {
return dataRepository.findByBuyer(buyer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.List;
import java.util.Optional;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import uk.jinhy.survey_mate_api.auth.domain.entity.Member;
Expand All @@ -12,16 +14,18 @@ public interface DataRepository extends JpaRepository<Data, Long> {
Optional<Data> findByDataId(Long id);

@Query("select data from Data data "
+ "where data.seller = :member and data.isDeleted = false")
+ "where data.seller = :member and data.isDeleted = false"
+ " order by data.createdAt desc")
List<Data> findBySeller(Member member);

@Query("select data from Data data "
+ "join PurchaseHistory purchase_history on data = purchase_history.data "
+ "where purchase_history.buyer = :member")
+ "where purchase_history.buyer = :member"
+ " order by data.createdAt desc")
List<Data> findByBuyer(Member member);

@Query("select data from Data data "
+ "where data.isDeleted = false"
+ " order by data.createdAt limit 15 ")
+ " order by data.createdAt desc limit 15 ")
List<Data> findRecentData();
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public ApiResponse<Object> buyData(
@GetMapping(value = "/list")
@Operation(summary = "전체 설문장터 조회")
public ApiResponse<DataControllerDTO.DataListDTO> getDataList() {
List<Data> dataList = dataService.getRecentDataList();
List<Data> dataList = dataService.getDataList();
DataControllerDTO.DataListDTO responseDTO = converter.toControllerDataListDto(dataList);
return ApiResponse.onSuccess(Status.OK.getCode(), Status.OK.getMessage(), responseDTO);
}
Expand All @@ -112,4 +112,12 @@ public ApiResponse<DataControllerDTO.DataListDTO> getDataListAsSeller() {
DataControllerDTO.DataListDTO responseDTO = converter.toControllerDataListDto(dataList);
return ApiResponse.onSuccess(Status.OK.getCode(), Status.OK.getMessage(), responseDTO);
}

@GetMapping(value = "/new")
@Operation(summary = "신규 설문장터 조회")
public ApiResponse<DataControllerDTO.DataListDTO> getNewDataList() {
List<Data> dataList = dataService.getRecentDataList();
DataControllerDTO.DataListDTO responseDTO = converter.toControllerDataListDto(dataList);
return ApiResponse.onSuccess(Status.OK.getCode(), Status.OK.getMessage(), responseDTO);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Statement getStatement(Long statementId) {
}

public List<Statement> getStatementList(Member member) {
return statementRepository.findByMember(member);
return statementRepository.findByMemberOrderByCreatedAtDesc(member);
}

public Long getTotalAmount(Member member) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ public interface StatementRepository extends JpaRepository<Statement, Long> {

Optional<Statement> findByStatementId(Long id);

List<Statement> findByMember(Member member);

@Query("select ifnull(sum(statement.amount), 0) from Statement statement "
+ "where statement.member = :member")
Long findTotalAmountByMember(Member member);

List<Statement> findByMemberOrderByCreatedAtDesc(Member member);

@Query("select statement from Statement statement "
+ "where statement.member = :buyer and statement.amount < 0")
+ "where statement.member = :buyer and statement.amount < 0"
+ " order by statement.createdAt desc")
List<Statement> findByBuyer(Member buyer);

@Query("select statement from Statement statement "
+ "where statement.member = :seller and statement.amount > 0")
+ "where statement.member = :seller and statement.amount > 0"
+ " order by statement.createdAt desc")
List<Statement> findBySeller(Member seller);
}

0 comments on commit 3f395ed

Please sign in to comment.