Skip to content

Commit

Permalink
Merge pull request #152 from UMC-WOWMARKET/feat/MyOrderManage-137
Browse files Browse the repository at this point in the history
[feat] 판매 등록폼 수정 #137
  • Loading branch information
yunji118 authored Jan 7, 2024
2 parents e560d98 + 2ff38d6 commit 4c196c8
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package wowmarket.wow_server.converter;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import wowmarket.wow_server.domain.ReceiveType;

@Converter
public class ReceiveTypeConverter implements AttributeConverter<ReceiveType, Long> {

@Override
public Long convertToDatabaseColumn(ReceiveType receiveType) {
if (receiveType == null)
return null;
return receiveType.getCode();
}

@Override
public ReceiveType convertToEntityAttribute(Long dbData) {
return ReceiveType.ofReceiveType(dbData);
}
}
1 change: 1 addition & 0 deletions src/main/java/wowmarket/wow_server/domain/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public class Category {
private Long id;

private String name;

}
8 changes: 8 additions & 0 deletions src/main/java/wowmarket/wow_server/domain/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
import wowmarket.wow_server.mypage.myproject.MySalesProject.dto.MySalesItemDto;

@Entity
@Getter
Expand Down Expand Up @@ -31,4 +32,11 @@ public void setProject(Project project){
this.project = project;
}

public void modify(MySalesItemDto itemDto){
this.name = itemDto.getItemName();
this.price = itemDto.getPrice();
this.goal = itemDto.getGoal();
this.limits = itemDto.getLimits();
}

}
26 changes: 26 additions & 0 deletions src/main/java/wowmarket/wow_server/domain/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.Check;
import wowmarket.wow_server.converter.ReceiveTypeConverter;
import wowmarket.wow_server.mypage.myproject.MySalesProject.dto.MySalesProjectModifyRequestDto;

import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -48,6 +50,7 @@ public class Project extends BaseEntity{


@Enumerated(EnumType.STRING)
@Convert(converter = ReceiveTypeConverter.class)
private ReceiveType receive_type; //delivery, pickup
private String receive_address; //직접수령 시 픽업장소
private String deliveryType; // 배송 시 배송 방법
Expand Down Expand Up @@ -85,6 +88,29 @@ public void setCategory(Category category){
this.category = category;
}

public void modify(MySalesProjectModifyRequestDto requestDto, Category category){
this.projectName = requestDto.getProjectName();
this.description = requestDto.getDescription();
this.sellerName = requestDto.getSellerName();
this.phoneNumber = requestDto.getSellerPhoneNumber();
this.email = requestDto.getSellerEmail();
this.sellerEtc = requestDto.getSellerEtc();
this.thumbnail = requestDto.getThumbnail();
this.image1 = requestDto.getImage1();
this.image2 = requestDto.getImage2();
this.image3 = requestDto.getImage3();
this.startDate = requestDto.getStartDate();
this.endDate = requestDto.getEndDate();
this.receive_type = ReceiveType.ofReceiveType(requestDto.getReceiveType());
this.receive_address = requestDto.getReceiveAddress();
this.delivery_fee = requestDto.getDeliveryFee();
this.bank = requestDto.getSellerBank();
this.account = requestDto.getSellerAccount();
this.account_holder_name = requestDto.getSellerAccountName();
this.category = category;
//this.sellToAll = sellToAll;
}

}


19 changes: 18 additions & 1 deletion src/main/java/wowmarket/wow_server/domain/ReceiveType.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
package wowmarket.wow_server.domain;

import com.fasterxml.jackson.databind.annotation.EnumNaming;
import lombok.Getter;

import java.util.Arrays;


@Getter
public enum ReceiveType {
DELIVERY, PICKUP, ALL;
DELIVERY(1L), PICKUP(2L), ALL(3L);

private Long code;

private ReceiveType(Long code) {
this.code = code;
}

public static ReceiveType ofReceiveType(Long code){
return Arrays.stream(ReceiveType.values())
.filter(v -> v.getCode().equals(code))
.findAny()
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 수령방법입니다."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public MyOrderFormListResponseDto getMyOrderList(@RequestParam(value = "page", d

//나의 판매 주문폼 상세보기
@GetMapping("/detail/{order_id}")
public MyOrderSalesDetailResponseDto getMyDetailOrder(@PathVariable Long order_id){
return myOrderService.findMyOrderFormDetail(order_id);
public MyOrderSalesDetailResponseDto getMyDetailOrder(@PathVariable Long order_id, @AuthenticationPrincipal User user){
return myOrderService.findMyOrderFormDetail(order_id, user);
}

//나의 주문폼 취소하기
@DeleteMapping("/detail/{order_id}")
//나의 판매 주문폼 취소하기
@PutMapping("/detail/{order_id}")
public ResponseEntity deleteMyOrder(@PathVariable Long order_id){
return myOrderService.deleteMyOrderFormDetail(order_id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ public MyOrderFormListResponseDto findAllMyOrderForm(Pageable pageable, User use
}

@Transactional(readOnly = true)
public MyOrderSalesDetailResponseDto findMyOrderFormDetail(Long order_id){
public MyOrderSalesDetailResponseDto findMyOrderFormDetail(Long order_id, User user){
List<OrderDetail> ordersDetails = orderDetailRepository.findByOrders_Id(order_id);
List<MyOrderSalesDetailItemDto> orderFormDetailDtos = ordersDetails.stream().map(MyOrderSalesDetailItemDto::new).collect(Collectors.toList());
Orders orders = orderRepository.findById(order_id).get();
Orders orders = orderRepository.findById(order_id).orElseThrow(()->new ResponseStatusException(HttpStatus.BAD_REQUEST));
if (user == null || user.getId() != orders.getUser().getId()){
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
}

String address = orders.getAddress();
if (orders.getProject().getReceive_type().equals("pickup"))
address = orders.getProject().getReceive_address();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public MySalesOrderDetailResponseDto findMySalesOrderDetail(Long order_id, User

List<OrderDetail> orderDetails = orderDetailRepository.findByOrders_Id(order_id);
String address = orders.getAddress();
if (orders.getProject().getReceive_type().equals("pickup"))
if (orders.getProject().getReceive_type().equals("PICKUP"))
address = orders.getProject().getReceive_address();
List<MySalesOrderDetailDto> orderDetailDtos = orderDetails.stream().map(MySalesOrderDetailDto::new).collect(Collectors.toList());
MySalesOrderDetailResponseDto responseDto = new MySalesOrderDetailResponseDto(orderDetailDtos, orders, address);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package wowmarket.wow_server.mypage.myproject.MySalesProject.controller;

import com.nimbusds.oauth2.sdk.Response;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand All @@ -10,10 +11,11 @@
import wowmarket.wow_server.domain.User;
import wowmarket.wow_server.mypage.myproject.MySalesProject.dto.MySalesDetailResponseDto;
import wowmarket.wow_server.mypage.myproject.MySalesProject.dto.MySalesListResponseDto;
import wowmarket.wow_server.mypage.myproject.MySalesProject.dto.MySalesProjectModifyRequestDto;
import wowmarket.wow_server.mypage.myproject.MySalesProject.service.MySalesProjectService;

@RestController
@RequestMapping("/myproject")
@RequestMapping("/myproject/sales")
@RequiredArgsConstructor
public class MySalesProjectController {
private final MySalesProjectService mySalesProjectService;
Expand All @@ -25,9 +27,10 @@ public MySalesListResponseDto getMySalesList(@RequestParam(value = "page", defau
return mySalesProjectService.findAllMySalesForm(pageable, user);
}

//판매 등록폼 종료
@PutMapping("/{project_id}")
public ResponseEntity finishMySales(@PathVariable Long project_id){
return mySalesProjectService.finishMySalesForm(project_id);
public ResponseEntity finishMySales(@PathVariable Long project_id, @AuthenticationPrincipal User user){
return mySalesProjectService.finishMySalesForm(project_id, user);
}

//판매 등록폼 상세보기
Expand All @@ -36,4 +39,10 @@ public MySalesDetailResponseDto getMySalesDetail(@PathVariable Long project_id){
return mySalesProjectService.findMySalesDetail(project_id);
}

//판매 등록폼 수정하기
@PutMapping("/{project_id}/modify")
public ResponseEntity modifyMySalesProject(@PathVariable Long project_id, @RequestBody MySalesProjectModifyRequestDto requestDto, @AuthenticationPrincipal User user){
return mySalesProjectService.modifyMySalesProject(project_id, requestDto, user);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ public class MySalesItemDto {
private Long itemId;
private String itemName;
private Long price;
private int limits;
private int goal;

public MySalesItemDto(Item item){
this.itemId = item.getId();
this.itemName = item.getName();
this.price = item.getPrice();
this.goal = item.getGoal();
this.limits = item.getLimits();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package wowmarket.wow_server.mypage.myproject.MySalesProject.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import wowmarket.wow_server.domain.Category;
import wowmarket.wow_server.domain.ReceiveType;

import java.time.LocalDateTime;
import java.util.List;

@Getter
@NoArgsConstructor
public class MySalesProjectModifyRequestDto {
private String projectName;
private String description;
private String thumbnail;
private Long categoryId;
private String image1;
private String image2;
private String image3;
private List<MySalesItemDto> itemList;
private LocalDateTime startDate;
private LocalDateTime endDate;
private Long receiveType;
private String receiveAddress;
private String sellerBank;
private String sellerAccount;
private String sellerAccountName;
private String sellerName;
private Long deliveryFee;
private String sellerPhoneNumber;
private String sellerEmail;
private String sellerEtc;

@Builder
public MySalesProjectModifyRequestDto(String projectName, String description, String sellerName, String phoneNumber, String email, String sellerEtc,
Long categoryId, String thumbnail, String image1, String image2, String image3, LocalDateTime startDate,
LocalDateTime endDate, Long receiveType, String receiveAddress, Long deliveryFee, String bank, String account,
String accountHolderName, List<MySalesItemDto> itemList){
this.projectName = projectName;
this.description = description;
this.sellerName = sellerName;
this.sellerPhoneNumber = phoneNumber;
this.sellerEmail = email;
this.sellerEtc = sellerEtc;
this.categoryId = categoryId;
this.thumbnail = thumbnail;
this.image1 = image1;
this.image2 = image2;
this.image3 = image3;
this.startDate = startDate;
this.endDate = endDate;
this.receiveType = receiveType;
this.receiveAddress = receiveAddress;
this.deliveryFee = deliveryFee;
this.sellerBank = bank;
this.sellerAccount = account;
this.sellerAccountName = accountHolderName;
this.itemList = itemList;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package wowmarket.wow_server.mypage.myproject.MySalesProject.service;

import com.nimbusds.oauth2.sdk.Response;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -8,14 +9,12 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.server.ResponseStatusException;
import wowmarket.wow_server.domain.Category;
import wowmarket.wow_server.domain.Item;
import wowmarket.wow_server.domain.Project;
import wowmarket.wow_server.domain.User;
import wowmarket.wow_server.global.jwt.SecurityUtil;
import wowmarket.wow_server.mypage.myproject.MySalesProject.dto.MySalesDetailResponseDto;
import wowmarket.wow_server.mypage.myproject.MySalesProject.dto.MySalesFormDto;
import wowmarket.wow_server.mypage.myproject.MySalesProject.dto.MySalesItemDto;
import wowmarket.wow_server.mypage.myproject.MySalesProject.dto.MySalesListResponseDto;
import wowmarket.wow_server.mypage.myproject.MySalesProject.dto.*;
import wowmarket.wow_server.repository.*;

import java.util.List;
Expand All @@ -26,7 +25,7 @@
public class MySalesProjectService {
private final ProjectRepository projectRepository;
private final ItemRepository itemRepository;
private final UserRepository userRepository;
private final CategoryRepository categoryRepository;

@Transactional(readOnly = true)
public MySalesListResponseDto findAllMySalesForm(Pageable pageable, User user){
Expand All @@ -40,9 +39,12 @@ public MySalesListResponseDto findAllMySalesForm(Pageable pageable, User user){
}

@Transactional
public ResponseEntity finishMySalesForm(Long project_id){
public ResponseEntity finishMySalesForm(Long project_id, User user){
Project project = projectRepository.findById(project_id)
.orElseThrow(()->new ResponseStatusException(HttpStatus.BAD_REQUEST));
if (user == null || project.getUser().getId() != user.getId()){
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
}
if (project.isEnd() == false)
project.setEnd(true);
return new ResponseEntity(HttpStatus.OK);
Expand All @@ -58,4 +60,25 @@ public MySalesDetailResponseDto findMySalesDetail(Long project_id){
return responseDto;
}

@Transactional
public ResponseEntity modifyMySalesProject(Long projectId, MySalesProjectModifyRequestDto requestDto, User user){
Project project = projectRepository.findById(projectId).orElseThrow(()->new IllegalArgumentException("해당 project id가 없습니다."));
if (user == null || project.getUser().getId() != user.getId()){
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
}
Category category = categoryRepository.findById(requestDto.getCategoryId()).orElseThrow(() -> new IllegalArgumentException("해당 category id가 없습니다."));
project.modify(requestDto, category);


for(int i=0;i<requestDto.getItemList().size();i++){
MySalesItemDto itemDto = requestDto.getItemList().get(i);
Item item = itemRepository.findItemById(itemDto.getItemId());
item.modify(itemDto);
itemRepository.save(item);
}

projectRepository.save(project);
return new ResponseEntity(HttpStatus.OK);
}

}

0 comments on commit 4c196c8

Please sign in to comment.