Skip to content

Commit

Permalink
Merge pull request #191 from Kek-i/develop-sprint-3
Browse files Browse the repository at this point in the history
[develop-sprint-3] 3차 개발 sprint develop 브랜치로 이전
  • Loading branch information
chaerlo127 authored Mar 21, 2023
2 parents f0f2712 + 51cce03 commit 9e8b659
Show file tree
Hide file tree
Showing 33 changed files with 890 additions and 25 deletions.
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 @@ -165,10 +167,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 @@ -193,6 +196,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 @@ -203,14 +232,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());
}
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/codepatissier/keki/order/dto/GetEditOrder.java
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

0 comments on commit 9e8b659

Please sign in to comment.