Skip to content

Commit

Permalink
Merge pull request #165 from Kek-i/feature/7-desserts-getDessert
Browse files Browse the repository at this point in the history
  • Loading branch information
JoongHyun-Kim authored Mar 6, 2023
2 parents f451835 + d4d6e9d commit d2c2dad
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class GetDessertRes {
private Integer dessertPrice;
private String dessertDescription;
private List<Image> images;
private List<Option> options;

@Getter
@AllArgsConstructor
Expand All @@ -24,4 +25,12 @@ public static class Image {
private Long imgIdx;
private String imgUrl;
}

@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class Option {
private String optionDescription;
private Integer optionPrice;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.codepatissier.keki.dessert.entity;

import com.codepatissier.keki.common.BaseEntity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
Expand All @@ -11,7 +12,7 @@
@Entity
@NoArgsConstructor
@DynamicInsert
public class Option {
public class Option extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long optionIdx;
Expand All @@ -24,5 +25,5 @@ public class Option {
private String description;

@Column(nullable = false)
private int price;
private Integer price;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.codepatissier.keki.dessert.repository;

import com.codepatissier.keki.dessert.entity.Dessert;
import com.codepatissier.keki.dessert.entity.Option;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OptionRepository extends JpaRepository<Option, Long> {
List<Option> findByDessertAndStatusOrderByOptionIdx(Dessert dessert, String activeStatus);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.codepatissier.keki.dessert.dto.*;
import com.codepatissier.keki.dessert.entity.Dessert;
import com.codepatissier.keki.dessert.repository.DessertRepository;
import com.codepatissier.keki.dessert.repository.OptionRepository;
import com.codepatissier.keki.post.entity.PostImg;
import com.codepatissier.keki.post.repository.PostRepository;
import com.codepatissier.keki.store.entity.Store;
Expand All @@ -29,6 +30,7 @@ public class DessertService {
private final StoreRepository storeRepository;
private final PostRepository postRepository;
private final UserRepository userRepository;
private final OptionRepository optionRepository;

/**
* ์ƒํ’ˆ ์ „์ฒด ์กฐํšŒ
Expand Down Expand Up @@ -85,8 +87,10 @@ public GetDessertRes getDessert(Long dessertIdx) throws BaseException {
ArrayList<GetDessertRes.Image> postImgList = getPostImgList(dessert);
imgList.addAll(postImgList);

// nickname, dessertName, dessertPrice, dessertDescription, imgList(์ƒํ’ˆ ์ƒ์„ธ ์ด๋ฏธ์ง€ 1์žฅ, ํ”ผ๋“œ ์ด๋ฏธ์ง€ 4์žฅ)
return new GetDessertRes(dessert.getStore().getUser().getNickname(), dessert.getDessertName(), dessert.getDessertPrice(), dessert.getDessertDescription(), imgList);
List<GetDessertRes.Option> optionList = getOptionList(dessert);

// nickname, dessertName, dessertPrice, dessertDescription, imgList(์ƒํ’ˆ ์ƒ์„ธ ์ด๋ฏธ์ง€ 1์žฅ, ํ”ผ๋“œ ์ด๋ฏธ์ง€ 4์žฅ), description, price
return new GetDessertRes(dessert.getStore().getUser().getNickname(), dessert.getDessertName(), dessert.getDessertPrice(), dessert.getDessertDescription(), imgList, optionList);
} catch (BaseException e) {
throw e;
} catch (Exception e) {
Expand All @@ -109,6 +113,11 @@ private String representPostImgUrl(List<PostImg> postImages){
return postImages.isEmpty() ? null : postImages.get(0).getImgUrl();
}

private List<GetDessertRes.Option> getOptionList(Dessert dessert) {
return optionRepository.findByDessertAndStatusOrderByOptionIdx(dessert, ACTIVE_STATUS).stream()
.map(option -> new GetDessertRes.Option(option.getDescription(), option.getPrice())).collect(Collectors.toList());
}

/**
* [ํŒ๋งค์ž] ์ƒํ’ˆ ๋“ฑ๋ก
* ์ƒํ’ˆ ์ด๋ฆ„, ๊ฐ€๊ฒฉ, ์†Œ๊ฐœ, ์ด๋ฏธ์ง€(1์žฅ)
Expand Down

0 comments on commit d2c2dad

Please sign in to comment.