Skip to content

Commit

Permalink
Merge pull request #211 from AppLinkers/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
yuseogi0218 authored Jan 30, 2024
2 parents c44cc30 + 1c1be23 commit e860e4a
Show file tree
Hide file tree
Showing 28 changed files with 424 additions and 70 deletions.
2 changes: 1 addition & 1 deletion laser-ordermanage-server-submodule-config
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public S3Service(S3Client s3Client) {
@Value("${cloud.aws.s3.bucket}")
private String bucketName;

public String upload(String folder, MultipartFile multipartFile) {
String key = folder + "/" + UUID.randomUUID() + "_" + multipartFile.getOriginalFilename();
public String upload(String folder, MultipartFile multipartFile, String fileName) {
String key = folder + "/" + UUID.randomUUID() + "-" + fileName;
try {
RequestBody requestBody = RequestBody.fromInputStream(multipartFile.getInputStream(), multipartFile.getSize());
return putObject(requestBody, key);
Expand All @@ -37,9 +37,9 @@ public String upload(String folder, MultipartFile multipartFile) {
}
}

public String upload(String folder, String filePath) {
public String upload(String folder, String filePath, String fileName) {
File file = new File(filePath);
String key = folder + "/" + UUID.randomUUID() + "_" + file.getName();
String key = folder + "/" + UUID.randomUUID() + "-" + fileName;
try {
RequestBody requestBody = RequestBody.fromFile(file);
String fileUrl = putObject(requestBody, key);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.laser.ordermanage.customer.api;

import com.laser.ordermanage.customer.dto.request.CustomerUpdateUserAccountRequest;
import com.laser.ordermanage.customer.service.CustomerOrderService;
import com.laser.ordermanage.customer.service.CustomerUserAccountService;
import com.laser.ordermanage.user.service.UserAuthService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -14,6 +17,8 @@
@RestController
public class CustomerUserAccountAPI {

private final UserAuthService userAuthService;
private final CustomerOrderService customerOrderService;
private final CustomerUserAccountService customerUserAccountService;

/**
Expand Down Expand Up @@ -41,4 +46,27 @@ public ResponseEntity<?> updateUserAccount(@RequestBody @Valid CustomerUpdateUse

return ResponseEntity.ok().build();
}

/**
* 고객 회원의 회원 탈퇴
* - 로그아웃 수행
* - 거래 데이터 삭제 및 고객과의 연관관계 제거
* - 거래 단계 (견적 대기, 견적 승인, 제작 중, 제작 완료) : 데이터 삭제
* - 거래 단계 (거래 완료) : 고객과의 연관관계 제거 및 삭제 표시
* - 고객 데이터삭제 (고객, 배송지, 사용자)
*/
@DeleteMapping("")
public ResponseEntity<?> deleteUserAccount(HttpServletRequest httpServletRequest) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

userAuthService.logout(httpServletRequest);

customerOrderService.deleteOrderByStageNotCompleted(user.getUsername());

customerOrderService.deleteOrderByStageCompleted(user.getUsername());

customerUserAccountService.deleteUser(user.getUsername());

return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Customer {
@Column(name = "id", updatable = false)
private Long id;

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
@JoinColumn(name = "user_id", nullable = false, updatable = false)
private UserEntity user;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.laser.ordermanage.user.dto.request;
package com.laser.ordermanage.customer.dto.request;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface DeliveryAddressRepositoryCustom {
List<CustomerGetDeliveryAddressResponse> findByCustomer(String email);

Optional<String> findUserEmailById(Long deliveryAddressId);

void deleteByCustomer(Long customerId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ public Optional<String> findUserEmailById(Long deliveryAddressId) {
return Optional.ofNullable(userEmail);
}

@Override
public void deleteByCustomer(Long customerId) {
queryFactory
.delete(deliveryAddress)
.where(deliveryAddress.customer.id.eq(customerId))
.execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.laser.ordermanage.order.domain.type.DrawingFileType;
import com.laser.ordermanage.order.domain.type.PurchaseOrderFileType;
import com.laser.ordermanage.order.exception.OrderErrorCode;
import com.laser.ordermanage.order.repository.CommentRepository;
import com.laser.ordermanage.order.repository.DrawingRepository;
import com.laser.ordermanage.order.repository.OrderRepository;
import com.laser.ordermanage.order.repository.PurchaseOrderRepository;
Expand All @@ -31,6 +32,7 @@
@Service
public class CustomerOrderService {

private final CommentRepository commentRepository;
private final DrawingRepository drawingRepository;
private final OrderRepository orderRepository;
private final CustomerRepository customerRepository;
Expand Down Expand Up @@ -227,13 +229,41 @@ public CustomerCreateOrUpdateOrderPurchaseOrderResponse updateOrderPurchaseOrder
return CustomerCreateOrUpdateOrderPurchaseOrderResponse.from(purchaseOrder);
}

@Transactional
public void deleteOrderByStageNotCompleted(String email) {
// 거래 목록 조회 (견적 대기, 견적 승인, 제작 중, 제작 완료)
List<Long> orderIdList = orderRepository.findIdByCustomerAndStageNotCompleted(email);

// 거래 도면 데이터 삭제
drawingRepository.deleteAllByOrderList(orderIdList);

// 거래 댓글 데이터 삭제
commentRepository.deleteAllByOrderList(orderIdList);

// 거래 데이터 삭제 및 연관 데이터 삭제 (거래 제조 서비스, 거래 후처리 서비스, 거래 배송지, 견적서, 발주서)
orderRepository.deleteAllByIdIn(orderIdList);
}

@Transactional
public void deleteOrderByStageCompleted(String email) {
// 거래 목록 조회 (거래 완료)
List<Order> orderList = orderRepository.findByCustomerAndStageCompleted(email);
List<Long> orderIdList = orderList.stream().map(order -> order.getId()).toList();

// 거래 댓글과 사용자의 연관관계 제거
commentRepository.updateCommentUserAsNullByUserAndOrder(email, orderIdList);

// 거래와 고객의 연관관계 제거 및 삭제 표시
orderList.forEach(order -> order.delete());
}

private File<PurchaseOrderFileType> uploadPurchaseOrderFile(MultipartFile file) {
String fileName = file.getOriginalFilename();
Long fileSize = file.getSize();
PurchaseOrderFileType fileType = PurchaseOrderFileType.ofExtension(FileUtil.getExtension(file));

// 발주서 파일 업로드
String fileUrl = s3Service.upload("purchase-order", file);
String fileUrl = s3Service.upload("purchase-order", file, "purchase-order." + fileType.getExtension());

File<PurchaseOrderFileType> purchaseOrderFile = File.<PurchaseOrderFileType>builder()
.name(fileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.laser.ordermanage.customer.dto.request.CustomerUpdateUserAccountRequest;
import com.laser.ordermanage.customer.dto.response.CustomerGetUserAccountResponse;
import com.laser.ordermanage.customer.repository.CustomerRepository;
import com.laser.ordermanage.customer.repository.DeliveryAddressRepository;
import com.laser.ordermanage.user.repository.UserEntityRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -13,6 +14,7 @@
@Service
public class CustomerUserAccountService {

private final DeliveryAddressRepository deliveryAddressRepository;
private final CustomerRepository customerRepository;
private final UserEntityRepository userRepository;

Expand All @@ -28,4 +30,15 @@ public void updateUserAccount(String email, CustomerUpdateUserAccountRequest req

customer.updateProperties(request);
}

@Transactional
public void deleteUser(String email) {
Customer customer = customerRepository.findFirstByUserEmail(email);

// 고객 회원의 배송지 목록 삭제
deliveryAddressRepository.deleteByCustomer(customer.getId());

// 고객 회원 데이터 삭제 (고객, 사용자)
customerRepository.delete(customer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private File<QuotationFileType> uploadQuotationFile(MultipartFile file) {
QuotationFileType fileType = QuotationFileType.ofExtension(FileUtil.getExtension(file));

// 견적서 파일 업로드
String fileUrl = s3Service.upload("quotation", file);
String fileUrl = s3Service.upload("quotation", file, "quotation." + fileType.getExtension());

File<QuotationFileType> quotationFile = File.<QuotationFileType>builder()
.name(fileName)
Expand All @@ -198,7 +198,7 @@ private File<SignatureFileType> uploadAcquirerSignatureFile(MultipartFile file)
SignatureFileType fileType = SignatureFileType.ofExtension(FileUtil.getExtension(file));

// 인수자 서명 파일 업로드
String fileUrl = s3Service.upload("acquirer-signature", file);
String fileUrl = s3Service.upload("acquirer-signature", file, "acquirer-signature." + fileType.getExtension());

File<SignatureFileType> signatureFile = File.<SignatureFileType>builder()
.name(fileName)
Expand Down
26 changes: 2 additions & 24 deletions src/main/java/com/laser/ordermanage/order/api/DrawingAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Validated
@RequiredArgsConstructor
@RequestMapping("/drawing")
Expand All @@ -32,28 +30,8 @@ public class DrawingAPI {
* - 썸네일 이미지 파일 AWS S3 에 업로드
*/
@PostMapping("")
public ResponseEntity<?> uploadDrawingFile(@RequestParam @ValidFile(message = "도면 파일은 필수 입력값입니다.") MultipartFile file) throws IOException {
// File 확장자 확인
DrawingFileType fileType = DrawingFileType.ofExtension(FileUtil.getExtension(file));

String fileName = file.getOriginalFilename();
Long fileSize = file.getSize();
// 도면 파일 업로드
String drawingFileUrl = drawingService.uploadDrawingFile(file);

// 썸네일 추출
String tempThumbnailFilePath = drawingService.extractThumbnail(file, fileType);

// 썸네일 파일 업로드
String thumbnailUrl = drawingService.uploadThumbnailFile(tempThumbnailFilePath);

UploadDrawingFileResponse uploadDrawingFileResponse = UploadDrawingFileResponse.builder()
.thumbnailUrl(thumbnailUrl)
.fileName(fileName)
.fileType(fileType.getExtension())
.fileUrl(drawingFileUrl)
.fileSize(fileSize)
.build();
public ResponseEntity<?> uploadDrawingFile(@RequestParam @ValidFile(message = "도면 파일은 필수 입력값입니다.") MultipartFile file) {
UploadDrawingFileResponse uploadDrawingFileResponse = drawingService.uploadDrawingFile(file);

return ResponseEntity.ok(uploadDrawingFileResponse);
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/laser/ordermanage/order/api/OrderAPI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.laser.ordermanage.order.api;

import com.laser.ordermanage.order.dto.request.CreateCommentRequest;
import com.laser.ordermanage.order.dto.response.DeleteOrderResponse;
import com.laser.ordermanage.order.service.OrderEmailService;
import com.laser.ordermanage.order.service.OrderService;
import jakarta.validation.Valid;
Expand Down Expand Up @@ -72,4 +73,24 @@ public ResponseEntity<?> createOrderComment(
return ResponseEntity.ok().build();
}

/**
* 거래 삭제
* - 거래에 대한 현재 로그인한 회원의 접근 권한 확인 (공장 or 거래의 고객 회원)
* - 거래 삭제 가능 단계 확인 (견적 대기, 견적 승인)
* - 거래 데이터 삭제 및 연관 데이터 삭제 (거래 제조 서비스, 거래 후처리 서비스, 도면, 거래 배송지, 견적서, 발주서, 댓글)
* - 거래 삭제에 대한 이메일 전송
*/
@DeleteMapping("/{order-id}")
public ResponseEntity<?> deleteOrder(@PathVariable("order-id") Long orderId) {

User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

orderService.checkAuthorityCustomerOfOrderOrFactory(user, orderId);

DeleteOrderResponse deletedOrder = orderService.deleteOrder(orderId);

orderEmailService.sendEmailForDeleteOrder(user, deletedOrder);

return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Comment extends CreatedAtEntity {
private Long id;

@ManyToOne
@JoinColumn(name = "user_id", nullable = false, updatable = false)
@JoinColumn(name = "user_id")
private UserEntity user;

@ManyToOne
Expand Down
30 changes: 24 additions & 6 deletions src/main/java/com/laser/ordermanage/order/domain/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public class Order extends CreatedAtEntity {
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "customer_id", nullable = false)
@JoinColumn(name = "customer_id")
private Customer customer;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
@JoinColumn(name = "delivery_address_id", nullable = false)
private OrderDeliveryAddress deliveryAddress;

Expand All @@ -48,12 +48,13 @@ public class Order extends CreatedAtEntity {
private static final EnumSet<Stage> ENABLE_UPDATE_IS_URGENT_STAGE_LIST = EnumSet.of(Stage.NEW, Stage.QUOTE_APPROVAL, Stage.IN_PRODUCTION, Stage.PRODUCTION_COMPLETED);
private static final EnumSet<Stage> ENABLE_UPDATE_DELIVERY_ADDRESS_STAGE_LIST = EnumSet.of(Stage.NEW, Stage.QUOTE_APPROVAL, Stage.IN_PRODUCTION);
private static final EnumSet<Stage> ENABLE_MANAGE_DRAWING_STAGE_LIST = EnumSet.of(Stage.NEW, Stage.QUOTE_APPROVAL, Stage.IN_PRODUCTION);
private static final EnumSet<Stage> ENABLE_DELETE_ORDER = EnumSet.of(Stage.NEW, Stage.QUOTE_APPROVAL);

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
@JoinColumn(name = "manufacturing_id", nullable = false)
private OrderManufacturing manufacturing;

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
@JoinColumn(name = "post_processing_id", nullable = false)
private OrderPostProcessing postProcessing;

Expand All @@ -71,18 +72,22 @@ public class Order extends CreatedAtEntity {
@Column(name = "is_new_issue", nullable = false, length = 1)
private Boolean isNewIssue;

@OneToOne(fetch = FetchType.LAZY)
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
@JoinColumn(name = "quotation_id")
private Quotation quotation;

@OneToOne(fetch = FetchType.LAZY)
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
@JoinColumn(name = "purchase_order_id")
private PurchaseOrder purchaseOrder;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "acquirer_id")
private Acquirer acquirer;

@Convert(converter = BooleanToYNConverter.class)
@Column(name = "is_deleted", nullable = false, length = 1)
private Boolean isDeleted = Boolean.FALSE;

@Builder
public Order(Customer customer, OrderDeliveryAddress deliveryAddress, String name, String imgUrl, OrderManufacturing manufacturing, OrderPostProcessing postProcessing, String request, Boolean isNewIssue) {
this.customer = customer;
Expand Down Expand Up @@ -179,4 +184,17 @@ public void changeStageToCompleted() {
public boolean hasAcquirer() {
return acquirer != null;
}

public boolean enableDelete() {
return ENABLE_DELETE_ORDER.contains(this.stage);
}

public void delete() {
this.customer = null;
this.isDeleted = Boolean.TRUE;
}

public boolean hasCustomer() {
return customer != null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.laser.ordermanage.order.dto.response;


import lombok.Builder;

@Builder
public record DeleteOrderResponse (
String name,
String customerUserEmail
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ public interface CommentRepositoryCustom {

List<GetCommentResponse> findCommentByOrder(Long orderId);

void deleteAllByOrder(Long orderId);

void deleteAllByOrderList(List<Long> orderIdList);

void updateCommentUserAsNullByUserAndOrder(String email, List<Long> orderIdList);
}
Loading

0 comments on commit e860e4a

Please sign in to comment.