Skip to content

Commit

Permalink
Merge pull request #176 from Make-A-Wish-Sopt/refactor-develop
Browse files Browse the repository at this point in the history
[FIX] 리팩토링
  • Loading branch information
wlwpfh authored Feb 13, 2024
2 parents 126c07d + aa97404 commit 40343b0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ public ResponseEntity<ApiResponse> 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<ApiResponse> createCakePresent(@RequestBody CakeCreateRequest request) {
val response = cakeService.createPresentNew(request);
val response = cakeService.createPresent(request);
return ResponseEntity.ok(ApiResponse.success(SUCCESS_CREATE_CAKE.getMessage(), response));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
@Builder
public record CakeCreateRequest(
String name,
Long cakeId,
String message,
Long cakeId,
Long wishId
) {
}
16 changes: 1 addition & 15 deletions src/main/java/com/sopterm/makeawish/service/CakeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down Expand Up @@ -176,7 +162,7 @@ public List<PresentResponseDTO> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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());
}
Expand Down

0 comments on commit 40343b0

Please sign in to comment.