Skip to content

Commit

Permalink
SAPHY-57 feat : 상품 배송 현황 조회 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
gyuseon25 committed Oct 7, 2024
1 parent ca11c53 commit 14d4ad0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package saphy.saphy.purchase.domain.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import saphy.saphy.member.domain.Member;
import saphy.saphy.purchase.domain.Purchase;
import saphy.saphy.purchase.domain.PurchaseStatus;
Expand All @@ -16,4 +18,7 @@ public interface PurchaseRepository extends JpaRepository<Purchase, Long> {

Purchase findByIdAndMember(Long id, Member member);

@Query("SELECT p FROM Purchase p WHERE p.status IN (:statuses) AND p.member = :member")
List<Purchase> findByStatusesAndMember(@Param("statuses") List<PurchaseStatus> statuses, @Param("member") Member member);

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,14 @@ public ApiResponse<PurchaseResponse> findById(
Member loggedInmember = customUserDetails.getMember();
return new ApiResponse<>(purchaseService.findById(loggedInmember, purchaseId));
}

@GetMapping("/deliveries")
@Operation(summary = "배송 현황 조회 API", description = "사용자의 모든 배송 현황을 조회하는 API 입니다.")
public ApiResponse<PurchaseResponse> findDeliveries(
@AuthenticationPrincipal CustomUserDetails customUserDetails
) {
Member loggedInmember = customUserDetails.getMember();
return new ApiResponse<>(purchaseService.findDeliveries(loggedInmember));
}

}
11 changes: 11 additions & 0 deletions src/main/java/saphy/saphy/purchase/service/PurchaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,15 @@ public PurchaseResponse findById(Member member, Long purchaseId) {
return PurchaseResponse.toDto(purchaseRepository.findByIdAndMember(purchaseId, member));
}

public List<PurchaseResponse> findDeliveries(Member member) {
return purchaseRepository.findByStatusesAndMember(List.of(
PurchaseStatus.START,
PurchaseStatus.SHIPPED,
PurchaseStatus.DELIVERED
), member)
.stream()
.map(PurchaseResponse::toDto)
.toList();
}

}

0 comments on commit 14d4ad0

Please sign in to comment.