Skip to content

Commit

Permalink
fix(#125) : 인증서 조회 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
aeeazip committed Aug 20, 2023
1 parent 5a8062a commit 0003dd1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
public interface HistoryRepository extends JpaRepository<History, Long> {

List<History> findAllByProductIdOrderBySoldAtDesc(Long productId);
Optional<LocalDateTime> findTopByProduct_IdOrderBySoldAt(Long productId);
Optional<History> findTopByProduct_IdOrderBySoldAt(Long productId);
}
10 changes: 7 additions & 3 deletions src/main/java/trothly/trothcam/service/web/ProductService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ public List<ProductsResDto> findPublicProducts(String webId) throws BaseExceptio

List<ProductsResDto> result = findProducts.stream()
.map(p -> {
LocalDateTime soldAt = historyRepository.findTopByProduct_IdOrderBySoldAt(p.getId())
.orElse(p.getLastModifiedAt());
Optional<History> history = historyRepository.findTopByProduct_IdOrderBySoldAt(p.getId());
boolean isLiked = likeProductRepository.existsByProduct_IdAndMember_Id(p.getId(), p.getMember().getId());

if(history.isEmpty())
return new ProductsResDto(p.getId(), p.getTitle(), p.getMember().getWebId(),
p.getLastModifiedAt(), p.getPrice(), isLiked);

return new ProductsResDto(p.getId(), p.getTitle(), p.getMember().getWebId(),
soldAt, p.getPrice(), isLiked);
history.get().getSoldAt(), p.getPrice(), isLiked);

})
.collect(Collectors.toList());

Expand Down

0 comments on commit 0003dd1

Please sign in to comment.