diff --git a/src/main/java/wowmarket/wow_server/converter/ReceiveTypeConverter.java b/src/main/java/wowmarket/wow_server/converter/ReceiveTypeConverter.java new file mode 100644 index 0000000..482b8f0 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/converter/ReceiveTypeConverter.java @@ -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 { + + @Override + public Long convertToDatabaseColumn(ReceiveType receiveType) { + if (receiveType == null) + return null; + return receiveType.getCode(); + } + + @Override + public ReceiveType convertToEntityAttribute(Long dbData) { + return ReceiveType.ofReceiveType(dbData); + } +} diff --git a/src/main/java/wowmarket/wow_server/domain/Category.java b/src/main/java/wowmarket/wow_server/domain/Category.java index 57f0ee5..6502258 100644 --- a/src/main/java/wowmarket/wow_server/domain/Category.java +++ b/src/main/java/wowmarket/wow_server/domain/Category.java @@ -15,4 +15,5 @@ public class Category { private Long id; private String name; + } diff --git a/src/main/java/wowmarket/wow_server/domain/Item.java b/src/main/java/wowmarket/wow_server/domain/Item.java index 9d33e91..035305e 100644 --- a/src/main/java/wowmarket/wow_server/domain/Item.java +++ b/src/main/java/wowmarket/wow_server/domain/Item.java @@ -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 @@ -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(); + } + } diff --git a/src/main/java/wowmarket/wow_server/domain/Project.java b/src/main/java/wowmarket/wow_server/domain/Project.java index d772bb0..da9e7f8 100644 --- a/src/main/java/wowmarket/wow_server/domain/Project.java +++ b/src/main/java/wowmarket/wow_server/domain/Project.java @@ -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; @@ -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; // 배송 시 배송 방법 @@ -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; + } + } diff --git a/src/main/java/wowmarket/wow_server/domain/ReceiveType.java b/src/main/java/wowmarket/wow_server/domain/ReceiveType.java index 3aa6abc..b16010f 100644 --- a/src/main/java/wowmarket/wow_server/domain/ReceiveType.java +++ b/src/main/java/wowmarket/wow_server/domain/ReceiveType.java @@ -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("존재하지 않는 수령방법입니다.")); + } } diff --git a/src/main/java/wowmarket/wow_server/mypage/myorder/sales/controller/MyOrderSalesController.java b/src/main/java/wowmarket/wow_server/mypage/myorder/sales/controller/MyOrderSalesController.java index 4c6afad..d82192a 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myorder/sales/controller/MyOrderSalesController.java +++ b/src/main/java/wowmarket/wow_server/mypage/myorder/sales/controller/MyOrderSalesController.java @@ -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); } diff --git a/src/main/java/wowmarket/wow_server/mypage/myorder/sales/service/MyOrderSalesService.java b/src/main/java/wowmarket/wow_server/mypage/myorder/sales/service/MyOrderSalesService.java index bf474ae..f90b474 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myorder/sales/service/MyOrderSalesService.java +++ b/src/main/java/wowmarket/wow_server/mypage/myorder/sales/service/MyOrderSalesService.java @@ -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 ordersDetails = orderDetailRepository.findByOrders_Id(order_id); List 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(); diff --git a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesOrder/service/MySalesOrderService.java b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesOrder/service/MySalesOrderService.java index 0840874..e772d5a 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesOrder/service/MySalesOrderService.java +++ b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesOrder/service/MySalesOrderService.java @@ -70,7 +70,7 @@ public MySalesOrderDetailResponseDto findMySalesOrderDetail(Long order_id, User List 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 orderDetailDtos = orderDetails.stream().map(MySalesOrderDetailDto::new).collect(Collectors.toList()); MySalesOrderDetailResponseDto responseDto = new MySalesOrderDetailResponseDto(orderDetailDtos, orders, address); diff --git a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/controller/MySalesProjectController.java b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/controller/MySalesProjectController.java index 913c06a..c1c2a68 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/controller/MySalesProjectController.java +++ b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/controller/MySalesProjectController.java @@ -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; @@ -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; @@ -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); } //판매 등록폼 상세보기 @@ -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); + } + } diff --git a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesItemDto.java b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesItemDto.java index 9f4a6f7..601dbc3 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesItemDto.java +++ b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesItemDto.java @@ -10,6 +10,7 @@ public class MySalesItemDto { private Long itemId; private String itemName; private Long price; + private int limits; private int goal; public MySalesItemDto(Item item){ @@ -17,5 +18,6 @@ public MySalesItemDto(Item item){ this.itemName = item.getName(); this.price = item.getPrice(); this.goal = item.getGoal(); + this.limits = item.getLimits(); } } diff --git a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesProjectModifyRequestDto.java b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesProjectModifyRequestDto.java new file mode 100644 index 0000000..fd66f50 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/dto/MySalesProjectModifyRequestDto.java @@ -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 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 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; + } +} diff --git a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/service/MySalesProjectService.java b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/service/MySalesProjectService.java index 7d2ae41..76782e5 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/service/MySalesProjectService.java +++ b/src/main/java/wowmarket/wow_server/mypage/myproject/MySalesProject/service/MySalesProjectService.java @@ -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; @@ -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; @@ -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){ @@ -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); @@ -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