Skip to content

Commit

Permalink
[FEAT] 선물 단건 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
wlwpfh committed Sep 11, 2024
1 parent 46c5ce3 commit 8d96788
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public ResponseEntity<ApiResponse> getPresents(
}

@Operation(summary = "해당 소원에 대한 케이크 조회")
@GetMapping("/{wishId}/{cakeId}")
@GetMapping("/{wishId}/{presentId}")
public ResponseEntity<ApiResponse> getEachPresent(
@Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails,
@PathVariable("wishId") Long wishId,
@PathVariable("cakeId") Long cakeId
@PathVariable("presentId") Long presentId
) {
val response = cakeService.getEachPresent(memberDetails.getId(), wishId, cakeId);
val response = cakeService.getEachPresent(memberDetails.getId(), wishId, presentId);
return ResponseEntity.ok(ApiResponse.success(SUCCESS_GET_PRESENT_MESSAGE.getMessage(), response));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
@Builder
public record PresentResponseDTO(
String name,
String message
String message,
Long cakeId,
Long giftMenuId
) {
public static PresentResponseDTO from(Present present){
return PresentResponseDTO.builder()
.name(present.getName())
.cakeId(present.getCake().getId())
.giftMenuId(present.getGiftMenu().getId())
.message(present.getMessage())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
import java.util.List;

public interface PresentRepository extends JpaRepository<Present, Long> {
List<Present> findPresentsByWishIdAndCakeId(Long wishId, Long cakeId);
Present findPresentByWishIdAndId(Long wishId, Long presentId);
}
6 changes: 3 additions & 3 deletions src/main/java/com/sopterm/makeawish/service/CakeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ public Cake getPayCake(Long cakeId) {
return getCake(cakeId);
}

public List<PresentResponseDTO> getEachPresent(Long userId, Long wishId, Long cakeId) {
public PresentResponseDTO getEachPresent(Long userId, Long wishId, Long presentId) {
val wish = wishService.getWish(wishId);
if (!isRightWisher(userId, wish)) {
throw new IllegalArgumentException(INCORRECT_WISH.getMessage());
}
val presents = presentRepository.findPresentsByWishIdAndCakeId(wishId, cakeId);
return presents.stream().map(PresentResponseDTO::from).collect(Collectors.toList());
val present = presentRepository.findPresentByWishIdAndId(wishId, presentId);
return PresentResponseDTO.from(present);
}

@Transactional
Expand Down

0 comments on commit 8d96788

Please sign in to comment.