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

[develop-sprint-3] 3차 개발 sprint develop 브랜치로 이전 #191

Merged
merged 45 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a1c5bc5
feat: 상품 상세 조회 API에 디자인 요금 추가
JoongHyun-Kim Mar 9, 2023
0e28eeb
Merge branch 'develop-sprint-3' into feature/7-desserts-getDessert
JoongHyun-Kim Mar 9, 2023
d93c61e
Merge pull request #170 from Kek-i/feature/7-desserts-getDessert
JoongHyun-Kim Mar 9, 2023
239b037
#161 feat: 주문 취소 API 추가
sojungpp Mar 9, 2023
eb88644
Merge pull request #171 from Kek-i/feature/161-orders-cancel
sojungpp Mar 9, 2023
a81c9a0
#160 feat: [판매자] 상품 등록 API에 디자인 요금 추가
JoongHyun-Kim Mar 10, 2023
7804872
Merge pull request #172 from Kek-i/feature/7-desserts-addDessert
JoongHyun-Kim Mar 10, 2023
dd44926
#161 fix: baseEntity 추가 및 무한 참조 순환 에러 해결
chaerlo127 Mar 10, 2023
ff23862
#161 feat: 주문 상세 조회 api
chaerlo127 Mar 10, 2023
3ec321d
#161 fix: 오타 수정
chaerlo127 Mar 10, 2023
64e9e60
#161 feat: [판매자] 주문 상태 변경 API 추가
sojungpp Mar 11, 2023
f027185
Merge pull request #174 from Kek-i/feature/161-orders-get
chaerlo127 Mar 11, 2023
294a773
Merge branch 'develop-sprint-3' into feature/161-orders-status
sojungpp Mar 11, 2023
d50fd98
Merge pull request #175 from Kek-i/feature/161-orders-status
sojungpp Mar 12, 2023
7b7cb50
#160 fix: 상품 상세 조회 API response값에 optionIdx 추가
JoongHyun-Kim Mar 13, 2023
e1249fa
Merge pull request #177 from Kek-i/feature/7-desserts-getDessert
JoongHyun-Kim Mar 13, 2023
afbed00
#161 feat: 주문하기 API 생성
psyeon1120 Mar 13, 2023
090e7ba
#8 feat: 주문 내역 조회 API 추가
sojungpp Mar 13, 2023
c73ee2e
#161 feat: 주문 내역 조회 API 추가
sojungpp Mar 13, 2023
d91ba9f
Merge remote-tracking branch 'origin/feature/161-orders-history' into…
sojungpp Mar 14, 2023
561d53b
#161 feat: 주문 화면 조회 (디저트 + 옵션)
chaerlo127 Mar 14, 2023
2b0df6e
#161 fix: 사용자 익셉션 처리
chaerlo127 Mar 14, 2023
9336ccd
#161 fix: url 변경
chaerlo127 Mar 14, 2023
16b8aa7
#160 feat: [판매자] 상품 수정 API에 디자인 옵션 추가 구현
JoongHyun-Kim Mar 14, 2023
72469c5
#161 fix: 사용자 정보 추가
chaerlo127 Mar 14, 2023
1aba605
Merge pull request #179 from Kek-i/feature/161-orders-history
sojungpp Mar 14, 2023
7e46c3f
fix: BaseResponseStatus에서 option 관련 dessert로 이동
JoongHyun-Kim Mar 14, 2023
ad6e5e0
Merge pull request #180 from Kek-i/feature/7-desserts-patchDessert
JoongHyun-Kim Mar 14, 2023
27d55a1
#161 fix: 사용자 정보 return 변경
chaerlo127 Mar 14, 2023
d40f7c7
Merge branch 'develop-sprint-3' into feature/161-orders-get
chaerlo127 Mar 14, 2023
309f627
Merge pull request #178 from Kek-i/feature/161-orders-get
chaerlo127 Mar 14, 2023
cb0c7e6
#161 feat: 주문 수정 화면 조회 api 생성
chaerlo127 Mar 15, 2023
55d232d
#161 fix: 주문 service function 주석 추가
chaerlo127 Mar 15, 2023
c06b35b
Merge pull request #182 from Kek-i/feature/161-orders-get
chaerlo127 Mar 15, 2023
16a2408
#161 feat: [판매자] 주문 상세 조회
chaerlo127 Mar 15, 2023
44e21f6
#161 refactor: 주문 이미지, 옵션 extract method
chaerlo127 Mar 15, 2023
6ea4075
#184 feat: 마이페이지 조회 API Res 추가
sojungpp Mar 15, 2023
6ff9b71
Merge pull request #186 from Kek-i/feature/184-users-mypage
sojungpp Mar 17, 2023
f5ea493
#160 feat: [판매자] 상품 상세 조회 API 디자인 옵션 추가
JoongHyun-Kim Mar 17, 2023
cb8e43f
Merge pull request #183 from Kek-i/feature/161-orders-get
chaerlo127 Mar 17, 2023
b0dd3ad
Merge pull request #187 from Kek-i/feature/7-desserts-store-getDessert
JoongHyun-Kim Mar 18, 2023
128d4b8
Merge remote-tracking branch 'origin/develop-sprint-3' into feature/1…
psyeon1120 Mar 18, 2023
91a35d2
#161 feat: 주문수정 API 생성
psyeon1120 Mar 18, 2023
b30b53a
#161 refactor: 주문하기 API orderImg, optionOrder 로직 추가
psyeon1120 Mar 18, 2023
51cce03
Merge pull request #188 from Kek-i/feature/161-orders-make
psyeon1120 Mar 19, 2023
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 @@ -53,6 +53,10 @@ public enum BaseResponseStatus {
INVALID_DESERT_PRICE(false, 3303, "디저트 가격은 0원 이상이어야 합니다."),
NULL_DESSERT_DESCRIPTION(false, 3304, "디저트 설명을 입력해주세요."),
DELETED_DESSERT(false, 3305, "이미 삭제된 디저트입니다."),
NULL_OPTION(false, 3306, "옵션을 입력해주세요."),
NULL_OPTION_IDX(false, 3307, "optionIdx를 입력해주세요."),
NULL_OPTION_DESCRIPTION(false, 3308, "옵션명을 입력해주세요."),
NULL_OPTION_PRICE(false, 3309, "옵션 가격을 입력해주세요."),

// calendars(2400~2499)
NULL_TITLE(false, 2400, "캘린더 제목을 입력해주세요."),
Expand All @@ -61,6 +65,10 @@ public enum BaseResponseStatus {
NULL_TAG(false, 2403, "태그를 입력해주세요"),

// histories(2500~2599)
// cs(2600-2699)
// order(2700~2799)
NULL_ORDER_IDX(false, 2700, "주문 아이디를 입력해주세요."),
NULL_ORDER_STATUS(false, 2701, "주문 상태를 선택해주세요."),


/**
Expand All @@ -71,8 +79,9 @@ public enum BaseResponseStatus {
EXIST_NICKNAME(false, 3001, "이미 사용 중인 닉네임입니다."),
INVALID_EMAIL(false, 3002, "존재하지 않는 이메일입니다."),
NO_STORE_ROLE(false, 3003, "판매자가 아닙니다."),
INVALID_USER_STATUS(false, 3004, "비활성화된 사용자입니다."),
EXPIRED_TOKEN(false, 3005, "만료된 토큰 값입니다."),
NO_CUSTOMER_ROLE(false, 3004, "구매자가 아닙니다."),
INVALID_USER_STATUS(false, 3005, "비활성화된 사용자입니다."),
EXPIRED_TOKEN(false, 3006, "만료된 토큰 값입니다."),

// stores(3100~3199)
INVALID_STORE_IDX(false, 3100, "존재하지 않는 스토어입니다."),
Expand All @@ -83,6 +92,7 @@ public enum BaseResponseStatus {

// desserts(3300~3399)
INVALID_DESSERT_IDX(false, 3300, "존재하지 않는 디저트입니다."),
INVALID_OPTION_IDX(false, 3301, "존재하지 않는 옵션입니다."),

// calendars(3400~3499)
INVALID_CALENDAR_TAG(false, 3400, "캘린더 TAG를 찾을 수 없습니다."),
Expand All @@ -100,6 +110,12 @@ public enum BaseResponseStatus {
NO_NOTICE(false, 3600, "공지사항이 없습니다."),
INVALID_NOTICE_IDX(false, 3601, "존재하지 않는 공지사항 입니다."),

// order(3700~3799)
INVALID_ORDER_IDX(false, 3700, "존재하지 않는 주문 입니다."),
NO_MATCH_ORDER_USER(false, 3701, "주문에 접근할 수 있는 사용자가 아닙니다."),
NO_MATCH_ORDER_STATUS(false, 3702, "가능한 주문 상태가 아닙니다."),
INVALID_ORDER_STATUS(false, 3703, "존재하지 않는 주문 상태 입니다."),

/**
* 4000: DB, Server 오류
*/
Expand Down
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<OptionDTO> options;

@Getter
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
Expand All @@ -13,4 +15,5 @@ public class GetStoreDessertRes {
private String dessertName;
private Integer dessertPrice;
private String dessertDescription;
private List<OptionDTO> options;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@AllArgsConstructor
@NoArgsConstructor
public class OptionDTO {
private String optionDescription;
private Integer optionPrice;
}
private Long optionIdx;
private String optionDescription;
private Integer optionPrice;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.codepatissier.keki.dessert.dto;

import lombok.Data;
import lombok.Getter;

import java.util.List;

@Data
@Getter
public class PatchDessertReq {
private String dessertImg;
private String dessertName;
private Integer dessertPrice;
private String dessertDescription;
private List<OptionDTO> options;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ public Option(Dessert dessert, String description, Integer price) {
this.description = description;
this.price = price;
}

public void setDescription(String description) {
this.description = description;
}

public void setPrice(Integer price) {
this.price = price;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface OptionRepository extends JpaRepository<Option, Long> {
List<Option> findByDessertAndStatusOrderByOptionIdx(Dessert dessert, String activeStatus);
Optional<Option> findByOptionIdxAndStatus(Long optionIdx, String activeStatus);
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,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<OptionDTO> optionList = getOptionList(dessert);

// nickname, dessertName, dessertPrice, dessertDescription, imgList(상품 상세 이미지 1장, 피드 이미지 4장), optionList(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 @@ -113,10 +115,10 @@ 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());
// }
private List<OptionDTO> getOptionList(Dessert dessert) {
return optionRepository.findByDessertAndStatusOrderByOptionIdx(dessert, ACTIVE_STATUS).stream()
.map(option -> new OptionDTO(option.getOptionIdx(), option.getDescription(), option.getPrice())).collect(Collectors.toList());
}

/**
* [판매자] 상품 등록
Expand Down Expand Up @@ -180,10 +182,11 @@ public void deleteDessert(Long userIdx, Long dessertIdx) throws BaseException {
* [판매자] 상품 수정
* 상품 이미지, 이름, 가격, 소개
*/
@Transactional(rollbackFor = Exception.class)
public void modifyDessert(PatchDessertReq patchDessertReq, Long dessertIdx, Long userIdx) throws BaseException {
try {
checkStore(userIdx);
Dessert dessert = dessertRepository.findByDessertIdxAndStatus(dessertIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_DESSERT_IDX));
Dessert dessert = dessertRepository.findByDessertIdxAndStatus(dessertIdx,ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_DESSERT_IDX));

if (patchDessertReq.getDessertImg() != null) {
if (!patchDessertReq.getDessertImg().equals("") && !patchDessertReq.getDessertImg().equals(" "))
Expand All @@ -208,6 +211,32 @@ public void modifyDessert(PatchDessertReq patchDessertReq, Long dessertIdx, Long
dessert.setDessertDescription(patchDessertReq.getDessertDescription());
else throw new BaseException(NULL_DESSERT_DESCRIPTION);
}

if (!patchDessertReq.getOptions().isEmpty() && !(patchDessertReq.getOptions() == null)) {
for (OptionDTO optionDTO : patchDessertReq.getOptions()) {
if(optionDTO.getOptionIdx() == null)
throw new BaseException(NULL_OPTION_IDX);
if(optionDTO.getOptionDescription() == null)
throw new BaseException(NULL_OPTION_DESCRIPTION);
if(optionDTO.getOptionPrice() == null)
throw new BaseException(NULL_OPTION_PRICE);
}

List<Long> optionIdxList = new ArrayList<>();
for (OptionDTO optionDTO : patchDessertReq.getOptions()) {
optionIdxList.add(optionDTO.getOptionIdx());
}

for (Long optionIdx : optionIdxList) {
Option option = optionRepository.findByOptionIdxAndStatus(optionIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_OPTION_IDX));

for(OptionDTO modifiedOption : patchDessertReq.getOptions()) {
option.setDescription(modifiedOption.getOptionDescription());
option.setPrice(modifiedOption.getOptionPrice());
}
optionRepository.save(option);
}
}
dessertRepository.save(dessert);
} catch (BaseException e) {
throw e;
Expand All @@ -218,14 +247,15 @@ public void modifyDessert(PatchDessertReq patchDessertReq, Long dessertIdx, Long

/**
* [판매자] 상품 상세 조회
* 상품 이미지, 이름, 가격, 소개
* 가게 이름, 상품 이미지, 상품명, 상품 가격, 상품 설명, 옵션(optionIdx, 옵션명, 옵션 가격)
*/
public GetStoreDessertRes getStoreDessert(Long userIdx, Long dessertIdx) throws BaseException {
try {
checkStore(userIdx);
Dessert dessert = dessertRepository.findByDessertIdxAndStatus(dessertIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_DESSERT_IDX));

return new GetStoreDessertRes(dessert.getStore().getUser().getNickname(), dessert.getDessertImg(), dessert.getDessertName(), dessert.getDessertPrice(), dessert.getDessertDescription());
List<OptionDTO> optionList = getOptionList(dessert);
return new GetStoreDessertRes(dessert.getStore().getUser().getNickname(), dessert.getDessertImg(), dessert.getDessertName(), dessert.getDessertPrice(), dessert.getDessertDescription(), optionList);
} catch (BaseException e) {
throw e;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,152 @@
package com.codepatissier.keki.order.controller;

import com.codepatissier.keki.common.BaseException;
import com.codepatissier.keki.common.BaseResponse;

import com.codepatissier.keki.order.dto.*;
import com.codepatissier.keki.order.dto.PatchOrderStatusReq;
import com.codepatissier.keki.order.dto.OrderReq;
import com.codepatissier.keki.order.entity.OrderStatus;

import com.codepatissier.keki.order.service.OrderService;
import com.codepatissier.keki.user.service.AuthService;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.bind.annotation.*;


import java.util.Objects;

import static com.codepatissier.keki.common.BaseResponseStatus.*;
import static com.codepatissier.keki.order.entity.OrderStatus.getOrderStatusByName;

@SecurityRequirement(name = "Bearer")
@Tag(name = "orders", description = "주문 API")
@RestController
@RequestMapping(value = "/orders")
@RequiredArgsConstructor
public class OrderController {

private final AuthService authService;
private final OrderService orderService;


/**
* 주문하기 API
* [POST] /orders
*/
@PostMapping("")
public BaseResponse<String> makeOrder(@RequestBody OrderReq orderReq){
try {
orderService.makeOrder(authService.getUserIdx(), orderReq);
return new BaseResponse<>(SUCCESS);
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
}

/**
* 주문수정 API
* [PATCH] /orders/:orderIdx
*/
@PatchMapping("{orderIdx}")
public BaseResponse<String> editOrder(@PathVariable("orderIdx") Long orderIdx, @RequestBody OrderReq orderReq){
try {
orderService.editOrder(authService.getUserIdx(), orderIdx, orderReq);
return new BaseResponse<>(SUCCESS);
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
}

/**
* [구매자/판매자] 주문 상세 조회 API
* @param orderIdx
* @return GetOrder
*/
@GetMapping("{orderIdx}")
public BaseResponse<GetOrder> getOrder(@PathVariable("orderIdx") Long orderIdx){
try {
return new BaseResponse<>(orderService.getOrderReturn(authService.getUserIdx(), orderIdx));
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
}

/**
* 주문 내역 조회 API
* @param getOrderHistoryReq(orderStatus)
*/
@GetMapping("/history")
public BaseResponse<GetOrderHistoryRes> getOrderHistory(GetOrderHistoryReq getOrderHistoryReq){
try {
return new BaseResponse<>(orderService.getOrderHistory(authService.getUserIdx(), getOrderHistoryReq));
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
}

/**
* 주문 취소 API
* @param orderIdx
*/
@PatchMapping("/cancel/{orderIdx}")
public BaseResponse<?> cancelOrder(@PathVariable("orderIdx") Long orderIdx) {
try{
orderService.cancelOrder(authService.getUserIdx(), orderIdx);
return new BaseResponse<>(SUCCESS);
}catch (BaseException e){
return new BaseResponse<>(e.getStatus());
}
}

/**
* [판매자] 주문 상태 변경
* @param patchOrderStatusReq(orderIdx, orderStatus)
*/
@PatchMapping("/status")
public BaseResponse<?> changeOrderStatus(PatchOrderStatusReq patchOrderStatusReq) {
try{
if(Objects.isNull(patchOrderStatusReq.getOrderIdx())) throw new BaseException(NULL_ORDER_IDX);
String orderStatus = patchOrderStatusReq.getOrderStatus();
if(!StringUtils.hasText(orderStatus)) throw new BaseException(NULL_ORDER_STATUS);
if(Objects.isNull(getOrderStatusByName(orderStatus)) || getOrderStatusByName(orderStatus) == OrderStatus.CANCELED) throw new BaseException(INVALID_ORDER_STATUS);
orderService.changeOrderStatus(authService.getUserIdx(), patchOrderStatusReq);
return new BaseResponse<>(SUCCESS);
}catch (BaseException e){
return new BaseResponse<>(e.getStatus());
}
}

/**
* 주문 화면 조회
*/
@GetMapping("/view/{storeIdx}")
public BaseResponse<GetOrderStore> getStoreDessertsAndOptions(@PathVariable("storeIdx") Long storeIdx){
try{
return new BaseResponse<>(this.orderService.getStoreDessertsAndOptions(storeIdx));
}catch (BaseException e){
return new BaseResponse<>(e.getStatus());
}
}

/**
* 주문 수정 화면 조회
*/
@GetMapping("/{orderIdx}/editView")
public BaseResponse<GetEditOrder> getEditOrderView(@PathVariable("orderIdx") Long orderIdx){
try {
return new BaseResponse<>(this.orderService.getEditOrderView(orderIdx, authService.getUserIdx()));
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.codepatissier.keki.order.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class GetEditOrder {
GetOrder getOrder;
List<GetStoreDessertAndOptions> getStoreDessertAndOptions;

}
Loading