Skip to content

Commit

Permalink
Merge pull request #197 from Make-A-Wish-Sopt/feature/jiyoung-#196-de…
Browse files Browse the repository at this point in the history
…velop

[CHORE] 정책 및 칼럼 값 업데이트
  • Loading branch information
wlwpfh authored Sep 11, 2024
2 parents 1c8ae6e + 2993722 commit 8ef293c
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public ResponseEntity<ApiResponse> getAllCakes() {
return ResponseEntity.ok(ApiResponse.success(SUCCESS_GET_ALL_CAKE.getMessage(), response));
}

@Operation(summary = "선물 가능 리스트 조회")
@GetMapping("/giftMenu")
public ResponseEntity<ApiResponse> getAllGiftMenu(){
val response = cakeService.getAllGiftMenu();
return ResponseEntity.ok(ApiResponse.success(SUCESS_GET_ALL_GIFT_MENU.getMessage(), response));
}

@Operation(summary = "소원 링크 조회")
@GetMapping("/wishes/{wishId}")
public ResponseEntity<ApiResponse> findWish(@PathVariable Long wishId) throws AccessDeniedException {
Expand Down
25 changes: 3 additions & 22 deletions src/main/java/com/sopterm/makeawish/domain/wish/Wish.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
public record CakeCreateResponseDTO(
Long cakeId,
String imageUrl,
String hint,
String initial,
String wisher
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@
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();
}

public Cake toEntity(){
return Cake.builder()
.id(cakeId)
.name(name)
.imageUrl(imageUrl)
.price(price)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,18 +8,15 @@
public record UserWishResponseDTO(
String title,
String startAt,
String endAt,
int price,
int percent
String endAt
) {

public static UserWishResponseDTO of(Wish wish) {
return UserWishResponseDTO.builder()
.title(wish.getTitle())
.startAt(wish.getStartAt().toString())
.endAt(wish.getEndAt().toString())
.price(getPriceAppliedFee(wish.getTotalPrice()))
.percent(getPricePercent(wish.getTotalPrice(), wish.getPresentPrice()))

.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public record UserWishUpdateRequestDTO(
String imageUrl,
Integer price,
String title,
String hint,
String initial,
boolean wantsGift
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GiftMenu, Long> {
List<GiftMenu> findAllByOrderById();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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, Long> {
Present findPresentByWishIdAndId(Long wishId, Long presentId);
Optional<Present> findPresentByWishIdAndId(Long wishId, Long presentId);
}
21 changes: 13 additions & 8 deletions src/main/java/com/sopterm/makeawish/service/CakeService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.*;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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<GiftMenuResponseDTO> getAllGiftMenu() {
return giftMenuRepository.findAllByOrderById().stream()
.map(GiftMenuResponseDTO::from)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
3 changes: 0 additions & 3 deletions src/test/java/com/sopterm/makeawish/config/CacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8ef293c

Please sign in to comment.