diff --git a/src/main/java/com/sopterm/makeawish/common/message/SuccessMessage.java b/src/main/java/com/sopterm/makeawish/common/message/SuccessMessage.java index a039ae2..f2a87f0 100644 --- a/src/main/java/com/sopterm/makeawish/common/message/SuccessMessage.java +++ b/src/main/java/com/sopterm/makeawish/common/message/SuccessMessage.java @@ -40,7 +40,11 @@ public enum SuccessMessage { /** present **/ SUCCESS_GET_ALL_PRESENT("선물 전체 조회 성공"), - SUCCESS_GET_PRESENT_MESSAGE("케이크에 대한 편지 조회 성공"); + SUCCESS_GET_PRESENT_MESSAGE("케이크에 대한 편지 조회 성공"), + + /** gift menu **/ + SUCESS_GET_ALL_GIFT_MENU("선물 가능한 목록 전체 조회 성공") + ; private final String message; } diff --git a/src/main/java/com/sopterm/makeawish/controller/PublicController.java b/src/main/java/com/sopterm/makeawish/controller/PublicController.java index 37d4baf..f9c534e 100644 --- a/src/main/java/com/sopterm/makeawish/controller/PublicController.java +++ b/src/main/java/com/sopterm/makeawish/controller/PublicController.java @@ -40,6 +40,13 @@ public ResponseEntity getAllCakes() { return ResponseEntity.ok(ApiResponse.success(SUCCESS_GET_ALL_CAKE.getMessage(), response)); } + @Operation(summary = "선물 가능 리스트 조회") + @GetMapping("/giftMenu") + public ResponseEntity getAllGiftMenu(){ + val response = cakeService.getAllGiftMenu(); + return ResponseEntity.ok(ApiResponse.success(SUCESS_GET_ALL_GIFT_MENU.getMessage(), response)); + } + @Operation(summary = "소원 링크 조회") @GetMapping("/wishes/{wishId}") public ResponseEntity findWish(@PathVariable Long wishId) throws AccessDeniedException { diff --git a/src/main/java/com/sopterm/makeawish/domain/wish/Wish.java b/src/main/java/com/sopterm/makeawish/domain/wish/Wish.java index 59cc4bb..0c0c18b 100644 --- a/src/main/java/com/sopterm/makeawish/domain/wish/Wish.java +++ b/src/main/java/com/sopterm/makeawish/domain/wish/Wish.java @@ -34,17 +34,10 @@ public class Wish extends BaseEntity { private String presentImageUrl; - @Column(columnDefinition = "TEXT") - private String hint; - - private String initial; - private LocalDateTime startAt; private LocalDateTime endAt; - private int presentPrice; - private int totalPrice; @ManyToOne(fetch = LAZY) @@ -57,15 +50,12 @@ public class Wish extends BaseEntity { private boolean wantsGift; @Builder - public Wish(String title, String presentImageUrl, String hint, String initial, LocalDateTime startAt, - LocalDateTime endAt, int presentPrice, User wisher, boolean wantsGift) { + public Wish(String title, String presentImageUrl, LocalDateTime startAt, + LocalDateTime endAt, User wisher, boolean wantsGift) { this.title = title; this.presentImageUrl = presentImageUrl; - this.hint = hint; - this.initial = initial; this.startAt = startAt; this.endAt = endAt; - this.presentPrice = presentPrice; this.totalPrice = 0; this.wantsGift = wantsGift; setWisher(wisher); @@ -94,22 +84,13 @@ public WishStatus getStatus(int expiryDay) { } } - public void updateContent(String imageUrl, Integer price, String title, String hint, String initial, boolean wantsGift) { + public void updateContent(String imageUrl, String title, boolean wantsGift) { if (nonNull(imageUrl)) { this.presentImageUrl = imageUrl; } - if (nonNull(price)) { - this.presentPrice = price; - } if (nonNull(title)) { this.title = title; } - if (nonNull(hint)) { - this.hint = hint; - } - if (nonNull(initial)) { - this.initial = initial; - } if(nonNull(wantsGift)) { this.wantsGift = wantsGift; } diff --git a/src/main/java/com/sopterm/makeawish/dto/cake/CakeCreateResponseDTO.java b/src/main/java/com/sopterm/makeawish/dto/cake/CakeCreateResponseDTO.java index a4d7934..d9be66a 100644 --- a/src/main/java/com/sopterm/makeawish/dto/cake/CakeCreateResponseDTO.java +++ b/src/main/java/com/sopterm/makeawish/dto/cake/CakeCreateResponseDTO.java @@ -6,8 +6,6 @@ public record CakeCreateResponseDTO( Long cakeId, String imageUrl, - String hint, - String initial, String wisher ) { } diff --git a/src/main/java/com/sopterm/makeawish/dto/cake/CakeResponseDTO.java b/src/main/java/com/sopterm/makeawish/dto/cake/CakeResponseDTO.java index b297cf6..97c91ea 100644 --- a/src/main/java/com/sopterm/makeawish/dto/cake/CakeResponseDTO.java +++ b/src/main/java/com/sopterm/makeawish/dto/cake/CakeResponseDTO.java @@ -7,14 +7,13 @@ import lombok.Builder; @Builder(access = PRIVATE) -public record CakeResponseDTO(Long cakeId, String name, String imageUrl, int price) { +public record CakeResponseDTO(Long cakeId, String name, String imageUrl) { public static CakeResponseDTO from(Cake cake) { return CakeResponseDTO.builder() .cakeId(cake.getId()) .name(cake.getName()) .imageUrl(cake.getImageUrl()) - .price(cake.getPrice()) .build(); } @@ -22,8 +21,6 @@ public Cake toEntity(){ return Cake.builder() .id(cakeId) .name(name) - .imageUrl(imageUrl) - .price(price) .build(); } } diff --git a/src/main/java/com/sopterm/makeawish/dto/giftMenu/GiftMenuResponseDTO.java b/src/main/java/com/sopterm/makeawish/dto/giftMenu/GiftMenuResponseDTO.java new file mode 100644 index 0000000..defd51d --- /dev/null +++ b/src/main/java/com/sopterm/makeawish/dto/giftMenu/GiftMenuResponseDTO.java @@ -0,0 +1,17 @@ +package com.sopterm.makeawish.dto.giftMenu; + +import com.sopterm.makeawish.domain.GiftMenu; +import lombok.Builder; + +import static lombok.AccessLevel.PRIVATE; + +@Builder(access = PRIVATE) +public record GiftMenuResponseDTO(Long giftMenuId, String name, int price) { + public static GiftMenuResponseDTO from(GiftMenu giftMenu) { + return GiftMenuResponseDTO.builder() + .giftMenuId(giftMenu.getId()) + .name(giftMenu.getName()) + .price(giftMenu.getPrice()) + .build(); + } +} diff --git a/src/main/java/com/sopterm/makeawish/dto/wish/UserWishResponseDTO.java b/src/main/java/com/sopterm/makeawish/dto/wish/UserWishResponseDTO.java index e6e2006..9403a3c 100644 --- a/src/main/java/com/sopterm/makeawish/dto/wish/UserWishResponseDTO.java +++ b/src/main/java/com/sopterm/makeawish/dto/wish/UserWishResponseDTO.java @@ -1,7 +1,5 @@ package com.sopterm.makeawish.dto.wish; -import static com.sopterm.makeawish.common.Util.*; - import com.sopterm.makeawish.domain.wish.Wish; import lombok.Builder; @@ -10,9 +8,7 @@ public record UserWishResponseDTO( String title, String startAt, - String endAt, - int price, - int percent + String endAt ) { public static UserWishResponseDTO of(Wish wish) { @@ -20,8 +16,7 @@ public static UserWishResponseDTO of(Wish wish) { .title(wish.getTitle()) .startAt(wish.getStartAt().toString()) .endAt(wish.getEndAt().toString()) - .price(getPriceAppliedFee(wish.getTotalPrice())) - .percent(getPricePercent(wish.getTotalPrice(), wish.getPresentPrice())) + .build(); } } diff --git a/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateRequestDTO.java b/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateRequestDTO.java index 15d495e..156a278 100644 --- a/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateRequestDTO.java +++ b/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateRequestDTO.java @@ -13,8 +13,6 @@ public record UserWishUpdateRequestDTO( String imageUrl, Integer price, String title, - String hint, - String initial, boolean wantsGift ) { } diff --git a/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateResponseDTO.java b/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateResponseDTO.java index 29bfbb5..011ed22 100644 --- a/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateResponseDTO.java +++ b/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateResponseDTO.java @@ -17,9 +17,6 @@ public record UserWishUpdateResponseDTO( AccountInfo accountInfo, String imageUrl, String title, - int price, - String initial, - String hint, WishStatus status ) { public static UserWishUpdateResponseDTO of(User user, Wish wish) { @@ -30,9 +27,6 @@ public static UserWishUpdateResponseDTO of(User user, Wish wish) { .accountInfo(nonNull(user.getAccount()) ? user.getAccount() : null) .imageUrl(wish.getPresentImageUrl()) .title(wish.getTitle()) - .price(wish.getPresentPrice()) - .initial(wish.getInitial()) - .hint(wish.getHint()) .status(wish.getStatus(0)) .build(); } diff --git a/src/main/java/com/sopterm/makeawish/repository/GiftMenuRepository.java b/src/main/java/com/sopterm/makeawish/repository/GiftMenuRepository.java index 70ca08b..bc2fbc8 100644 --- a/src/main/java/com/sopterm/makeawish/repository/GiftMenuRepository.java +++ b/src/main/java/com/sopterm/makeawish/repository/GiftMenuRepository.java @@ -3,5 +3,8 @@ import com.sopterm.makeawish.domain.GiftMenu; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface GiftMenuRepository extends JpaRepository { + List findAllByOrderById(); } diff --git a/src/main/java/com/sopterm/makeawish/repository/PresentRepository.java b/src/main/java/com/sopterm/makeawish/repository/PresentRepository.java index 43fa24f..2d5df7e 100644 --- a/src/main/java/com/sopterm/makeawish/repository/PresentRepository.java +++ b/src/main/java/com/sopterm/makeawish/repository/PresentRepository.java @@ -4,7 +4,8 @@ import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; +import java.util.Optional; public interface PresentRepository extends JpaRepository { - Present findPresentByWishIdAndId(Long wishId, Long presentId); + Optional findPresentByWishIdAndId(Long wishId, Long presentId); } diff --git a/src/main/java/com/sopterm/makeawish/service/CakeService.java b/src/main/java/com/sopterm/makeawish/service/CakeService.java index 0f2d4c5..030f746 100644 --- a/src/main/java/com/sopterm/makeawish/service/CakeService.java +++ b/src/main/java/com/sopterm/makeawish/service/CakeService.java @@ -1,20 +1,20 @@ package com.sopterm.makeawish.service; import com.sopterm.makeawish.common.KakaoPayProperties; -import com.sopterm.makeawish.common.Util; import com.sopterm.makeawish.domain.Cake; import com.sopterm.makeawish.domain.GiftMenu; import com.sopterm.makeawish.domain.Present; import com.sopterm.makeawish.domain.wish.Wish; import com.sopterm.makeawish.dto.cake.*; +import com.sopterm.makeawish.dto.giftMenu.GiftMenuResponseDTO; import com.sopterm.makeawish.dto.present.PresentDTO; import com.sopterm.makeawish.dto.present.PresentResponseDTO; import com.sopterm.makeawish.repository.CakeRepository; import com.sopterm.makeawish.repository.GiftMenuRepository; import com.sopterm.makeawish.repository.PresentRepository; import jakarta.persistence.EntityNotFoundException; -import lombok.*; -import org.springframework.cache.annotation.Cacheable; +import lombok.RequiredArgsConstructor; +import lombok.val; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Service; @@ -24,9 +24,7 @@ import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; -import java.util.Comparator; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import static com.sopterm.makeawish.common.message.ErrorMessage.*; @@ -145,7 +143,8 @@ public PresentResponseDTO getEachPresent(Long userId, Long wishId, Long presentI if (!isRightWisher(userId, wish)) { throw new IllegalArgumentException(INCORRECT_WISH.getMessage()); } - val present = presentRepository.findPresentByWishIdAndId(wishId, presentId); + val present = presentRepository.findPresentByWishIdAndId(wishId, presentId) + .orElseThrow(() -> new EntityNotFoundException(INVALID_GIFT_MENU.getMessage())); return PresentResponseDTO.from(present); } @@ -163,10 +162,16 @@ public CakeCreateResponseDTO createPresent(CakeCreateRequest request) { .build(); presentRepository.save(present); wish.updateTotalPrice(giftMenu.getPrice()); - return new CakeCreateResponseDTO(cake.getId(), wish.getPresentImageUrl(), wish.getHint(), wish.getInitial(), wish.getWisher().getNickname()); + return new CakeCreateResponseDTO(cake.getId(), wish.getPresentImageUrl(), wish.getWisher().getNickname()); } - private GiftMenu getGiftMenuInfo(Long giftMenuId){ + private GiftMenu getGiftMenuInfo(Long giftMenuId) { return giftMenuRepository.findById(giftMenuId).orElseThrow(() -> new EntityNotFoundException(INVALID_GIFT_MENU.getMessage())); } + + public List getAllGiftMenu() { + return giftMenuRepository.findAllByOrderById().stream() + .map(GiftMenuResponseDTO::from) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/com/sopterm/makeawish/service/WishService.java b/src/main/java/com/sopterm/makeawish/service/WishService.java index 23a4d64..ba42bb9 100644 --- a/src/main/java/com/sopterm/makeawish/service/WishService.java +++ b/src/main/java/com/sopterm/makeawish/service/WishService.java @@ -130,7 +130,7 @@ public UserWishUpdateResponseDTO updateUserMainWish(Long userId, UserWishUpdateR wish.updateTerm(startDate, endDate); } if (status.equals(BEFORE) || status.equals(WHILE)) { - wish.updateContent(request.imageUrl(), request.price(), request.title(), request.hint(), request.initial(), request.wantsGift()); + wish.updateContent(request.imageUrl(), request.title(), request.wantsGift()); wisher.updateProfile(request.name(), request.bankName(), request.account(), request.phone()); } diff --git a/src/test/java/com/sopterm/makeawish/config/CacheTest.java b/src/test/java/com/sopterm/makeawish/config/CacheTest.java index 9d23c17..a33b0bb 100644 --- a/src/test/java/com/sopterm/makeawish/config/CacheTest.java +++ b/src/test/java/com/sopterm/makeawish/config/CacheTest.java @@ -73,9 +73,6 @@ private Wish createWish(User user) { .wisher(user) .presentImageUrl("image-url") .title("소원 제목") - .hint("소원 힌트") - .initial("ㅅㅇ ㅈㅁ") - .presentPrice(50000) .startAt(Util.convertToDate(getLocalDateTime(0))) .endAt(Util.convertToDate(getLocalDateTime(7))) .build(); diff --git a/src/test/java/com/sopterm/makeawish/service/CakeServiceTest.java b/src/test/java/com/sopterm/makeawish/service/CakeServiceTest.java index d346240..c3dad7a 100644 --- a/src/test/java/com/sopterm/makeawish/service/CakeServiceTest.java +++ b/src/test/java/com/sopterm/makeawish/service/CakeServiceTest.java @@ -147,9 +147,6 @@ private Wish createWish(User user){ .wisher(user) .presentImageUrl("image-url") .title("소원 제목") - .hint("소원 힌트") - .initial("ㅅㅇ ㅈㅁ") - .presentPrice(50000) .startAt(Util.convertToDate(getLocalDateTime(0))) .endAt(Util.convertToDate(getLocalDateTime(7))) .build();