Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature/7-desserts-getDessert] 상품 상세 조회 API에 디자인 요금 추가 #165

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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