diff --git a/src/main/java/com/sopterm/makeawish/controller/PublicController.java b/src/main/java/com/sopterm/makeawish/controller/PublicController.java index d3d646e..53c9b36 100644 --- a/src/main/java/com/sopterm/makeawish/controller/PublicController.java +++ b/src/main/java/com/sopterm/makeawish/controller/PublicController.java @@ -59,15 +59,14 @@ public ResponseEntity createCake(@RequestBody CakeApproveRequestDTO if (cake.getId() != 1) { cakeService.getKakaoPayApprove(request); } - val wish = wishService.getWish(request.wishId()); - val response = cakeService.createPresent(request.name(), cake, wish, request.message()); + val response = cakeService.createPresent(new CakeCreateRequest(request.name(), request.message(), request.cakeId(), request.wishId())); return ResponseEntity.ok(ApiResponse.success(SUCCESS_CREATE_CAKE.getMessage(), response)); } @Operation(summary = "케이크 저장하기") @PostMapping("/cakes") public ResponseEntity createCakePresent(@RequestBody CakeCreateRequest request) { - val response = cakeService.createPresentNew(request); + val response = cakeService.createPresent(request); return ResponseEntity.ok(ApiResponse.success(SUCCESS_CREATE_CAKE.getMessage(), response)); } } diff --git a/src/main/java/com/sopterm/makeawish/dto/cake/CakeCreateRequest.java b/src/main/java/com/sopterm/makeawish/dto/cake/CakeCreateRequest.java index 6af6a62..6189324 100644 --- a/src/main/java/com/sopterm/makeawish/dto/cake/CakeCreateRequest.java +++ b/src/main/java/com/sopterm/makeawish/dto/cake/CakeCreateRequest.java @@ -5,8 +5,8 @@ @Builder public record CakeCreateRequest( String name, - Long cakeId, String message, + Long cakeId, Long wishId ) { } diff --git a/src/main/java/com/sopterm/makeawish/service/CakeService.java b/src/main/java/com/sopterm/makeawish/service/CakeService.java index a40cfc3..9beb7aa 100644 --- a/src/main/java/com/sopterm/makeawish/service/CakeService.java +++ b/src/main/java/com/sopterm/makeawish/service/CakeService.java @@ -112,20 +112,6 @@ public CakeApproveResponseDTO getKakaoPayApprove(CakeApproveRequestDTO request) } } - @Transactional - public CakeCreateResponseDTO createPresent(String name, Cake cake, Wish wish, String message) { - val present = Present.builder() - .name(name) - .message(message) - .cake(cake) - .wish(wish) - .build(); - presentRepository.save(present); - wish.updateTotalPrice(cake.getPrice()); - val contribute = Util.calculateContribution(cake.getPrice(), wish.getPresentPrice()); - return new CakeCreateResponseDTO(cake.getId(), wish.getPresentImageUrl(), wish.getHint(), wish.getInitial(), contribute, wish.getWisher().getNickname()); - } - public Cake getCake(Long id) { return cakeRepository.findById(id).orElseThrow(() -> new EntityNotFoundException(INVALID_CAKE.getMessage())); } @@ -176,7 +162,7 @@ public List getEachPresent(Long userId, Long wishId, Long ca } @Transactional - public CakeCreateResponseDTO createPresentNew(CakeCreateRequest request) { + public CakeCreateResponseDTO createPresent(CakeCreateRequest request) { val cake = getCake(request.cakeId()); val wish = wishService.getWish(request.wishId()); val present = Present.builder() diff --git a/src/test/java/com/sopterm/makeawish/service/CakeServiceTest.java b/src/test/java/com/sopterm/makeawish/service/CakeServiceTest.java index 9a5b0bb..7a82bb0 100644 --- a/src/test/java/com/sopterm/makeawish/service/CakeServiceTest.java +++ b/src/test/java/com/sopterm/makeawish/service/CakeServiceTest.java @@ -6,6 +6,7 @@ import com.sopterm.makeawish.domain.user.SocialType; import com.sopterm.makeawish.domain.user.User; import com.sopterm.makeawish.domain.wish.Wish; +import com.sopterm.makeawish.dto.cake.CakeCreateRequest; import com.sopterm.makeawish.dto.cake.CakeReadyRequestDTO; import com.sopterm.makeawish.repository.CakeRepository; import com.sopterm.makeawish.repository.UserRepository; @@ -94,7 +95,7 @@ class CakeServiceTest { int prevTotalPrice = wish.getTotalPrice(); // when - cakeService.createPresent("최아무", cake, wish, "선물 메세지"); + cakeService.createPresent(new CakeCreateRequest("최아무", "메세지", cake.getId(), wish.getId())); //then assertThat(prevTotalPrice).isEqualTo(wishService.getWish(wish.getId()).getTotalPrice()); @@ -110,8 +111,7 @@ class CakeServiceTest { int prevTotalPrice = wish.getTotalPrice(); // when - cakeService.createPresent("최아무", cake, wish, "선물 메세지"); - + cakeService.createPresent(new CakeCreateRequest("최아무", "메세지", cake.getId(), wish.getId())); //then assertThat(prevTotalPrice).isEqualTo(wishService.getWish(wish.getId()).getTotalPrice() - cake.getPrice()); }