Skip to content

Commit

Permalink
Merge pull request #145 from kakao-tech-campus-2nd-step3/feature/ISSU…
Browse files Browse the repository at this point in the history
…E-111

111번 다시 merge
  • Loading branch information
amm0124 authored Nov 11, 2024
2 parents 4e8322e + e44e0f4 commit f62d7be
Show file tree
Hide file tree
Showing 72 changed files with 2,069 additions and 740 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.3.1'
id 'io.spring.dependency-management' version '1.1.5'
id 'com.apollographql.apollo3' version '4.0.0-beta.7'

}

group = 'camp.nextstep.edu'
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/poomasi/domain/auth/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class SecurityConfig {
private final CustomSuccessHandler customSuccessHandler;
private final UserDetailsServiceImpl userDetailsService;


@Autowired
private OAuth2UserDetailServiceImpl oAuth2UserDetailServiceImpl;

Expand Down Expand Up @@ -74,7 +73,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti

// 기본 경로 및 테스트 경로
http.authorizeHttpRequests((authorize) -> authorize
.requestMatchers(HttpMethod.GET, "/api/farm/**").permitAll()
.requestMatchers(HttpMethod.POST, "/api/farm/**").permitAll()
.requestMatchers(HttpMethod.GET, "/api/product/**").permitAll()
.requestMatchers(HttpMethod.GET, "/api/review/**").permitAll()
.requestMatchers(HttpMethod.GET, "/health").permitAll()
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/poomasi/domain/farm/entity/Farm.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.time.LocalDateTime;

import poomasi.domain.order.entity._farm.OrderedFarm;
import poomasi.domain.review.entity.Review;

@Entity
Expand Down Expand Up @@ -77,7 +78,11 @@ public class Farm {

@OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true)
@JoinColumn(name = "entityId")
List<Review> reviewList = new ArrayList<>();
private List<Review> reviewList = new ArrayList<>();

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ordered_farm_id")
private OrderedFarm orderedFarm;

@Builder
public Farm(Long id, String name, Long ownerId, String address, String addressDetail, Double latitude, Double longitude, String description, int experiencePrice, Integer maxCapacity, Integer maxReservation) {
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/poomasi/domain/member/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import poomasi.domain.order.entity.Order;
import poomasi.domain.store.entity.Store;
import poomasi.domain.member._profile.entity.MemberProfile;
import poomasi.domain.store.entity.Store;
import poomasi.domain.order.entity._product.ProductOrder;
import poomasi.domain.store.entity.Store;
import poomasi.domain.member._profile.entity.MemberProfile;
import poomasi.domain.store.entity.Store;
Expand Down Expand Up @@ -59,7 +62,7 @@ public class Member {
private LocalDateTime deletedAt;

@OneToMany(mappedBy = "member", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Order> orderLists;
private List<ProductOrder> productOrderLists;

@Setter
@Column(nullable = true)
Expand All @@ -77,6 +80,11 @@ public Member(String name, String email, String password, LoginType loginType, R
this.role = role;
}

public Member(String email, Role role) {
this.email = email;
this.role = role;
}

public void setMemberProfile(MemberProfile memberProfile) {
this.memberProfile = memberProfile;
if (memberProfile != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package poomasi.domain.order._aftersales.controller;


import com.siot.IamportRestClient.exception.IamportResponseException;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
import poomasi.domain.order._aftersales.dto.cancel.request.FarmCancelRequest;
import poomasi.domain.order._aftersales.dto.cancel.request.ProductCancelRequest;
import poomasi.domain.order._aftersales.dto.refund.request.ProductRefundRequest;
import poomasi.domain.order._aftersales.dto.refund.request.ProductRefundRequestApprovalRequest;
import poomasi.domain.order._aftersales.dto.refund.request.ProductRefundRequestDeniedRequest;
import poomasi.domain.order._aftersales.service.FarmAfterSalesService;
import poomasi.domain.order._aftersales.service.ProductAfterSalesService;

import java.io.IOException;

@RestController
@RequestMapping("/api/aftersales")
@RequiredArgsConstructor
public class AfterSalesController {

private final ProductAfterSalesService productAfterSalesService;
private final FarmAfterSalesService farmAfterSalesService;

//-------------------------product cancel---------------------//
@Secured({"ROLE_CUSTOMER", "ROLE_FARMER"})
@PostMapping("/product/cancel")
public ResponseEntity<?> productCancel(@RequestBody ProductCancelRequest productCancelRequest) throws IOException, IamportResponseException {
return ResponseEntity.ok(
productAfterSalesService.cancel(productCancelRequest)
);
}

//-------------------------product refund---------------------//
@Secured({"ROLE_CUSTOMER", "ROLE_FARMER"})
@PostMapping("/refund-request")
public ResponseEntity<?> requestRefund(@RequestBody ProductRefundRequest productRefundRequest) {
return ResponseEntity.ok(
productAfterSalesService.
createRefundRequest(productRefundRequest)
);
}

@Secured({"ROLE_FARMER"})
@PostMapping("/approve-refund-request")
public ResponseEntity<?> approveRefundRequest(@RequestBody ProductRefundRequestApprovalRequest productRefundRequestApprovalRequest) throws IOException, IamportResponseException {
return ResponseEntity.ok(
productAfterSalesService.processRefundApproval(productRefundRequestApprovalRequest)
);
}


@Secured({"ROLE_FARMER"})
@PostMapping("/deniedrefund-request")
public ResponseEntity<?> deniedRefundRequest(@RequestBody ProductRefundRequestDeniedRequest productRefundRequestDeniedRequest) {
return ResponseEntity.ok(
productAfterSalesService.processRefundDenied(productRefundRequestDeniedRequest)
);
}


//-------------------------farm cancel---------------------//
@Secured({"ROLE_CUSTOMER", "ROLE_FARMER"})
@PostMapping("/farm/cancel")
public ResponseEntity<?> farmCancel(@RequestBody FarmCancelRequest farmCancelRequest) throws IOException, IamportResponseException {
return ResponseEntity.ok(
farmAfterSalesService.farmCancel(farmCancelRequest)
);
}


//------------웹훅 api 받아서 해야 함---------//





}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package poomasi.domain.order._aftersales.dto.cancel.request;

public record FarmCancelRequest(Long reservationId) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package poomasi.domain.order._aftersales.dto.cancel.request;

public record ProductCancelRequest(Long orderedProductId, Integer cancelRequestQuantity, String cancelReason) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package poomasi.domain.order._aftersales.dto.cancel.response;

public record FarmCancelResponse(Long reservationId, String status) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package poomasi.domain.order._aftersales.dto.cancel.response;

import poomasi.domain.order._aftersales.entity._product.ProductAfterSalesStatus;
import poomasi.domain.order.entity._product.OrderedProductStatus;

import java.math.BigDecimal;

public record ProductCancelResponse(
Long orderedProductId,
OrderedProductStatus orderedProductStatus,

Long productAfterSalesDetailId,
Integer cancelQuantity,
ProductAfterSalesStatus productAfterSalesStatus,
BigDecimal finalCancelAmount) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package poomasi.domain.order._aftersales.dto.exchange.request;

public record ProductExchangeRequest(Long orderedProductId, String exchangeReason) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package poomasi.domain.order._aftersales.dto.exchange.response;

public record ProductExchangeResponse(Long orderedProductId, String message) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package poomasi.domain.order._aftersales.dto.refund.request;

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.Size;

public record ProductRefundRequest(
@NotNull Long orderedProductId, // 필수 필드
@Positive Integer refundRequestQuantity, //필수
@Size(max = 500) String refundReason, // 필수 필드
@Size(max = 20) String request // nullable 필드
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package poomasi.domain.order._aftersales.dto.refund.request;

public record ProductRefundRequestApprovalRequest(Long productAfterSalesDetailId,
String invoiceNumber) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package poomasi.domain.order._aftersales.dto.refund.request;

public record ProductRefundRequestDeniedRequest(Long productAfterSalesDetailId,
String refundDeinedReason) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package poomasi.domain.order._aftersales.dto.refund.response;

import java.math.BigDecimal;

public record ProductRefundRequestApprovalResponse(
Long orderedProductId,
Integer count,
BigDecimal refundAmount,
Long productAfterSalesDetailId,
String invoiceNumber
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package poomasi.domain.order._aftersales.dto.refund.response;

import poomasi.domain.order._aftersales.entity._product.ProductAfterSalesStatus;

public record ProductRefundRequestDeniedResponse(Long productAfterSalesDetailId,
ProductAfterSalesStatus productAfterSalesStatus,
String productRefundDeniedReason) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package poomasi.domain.order._aftersales.dto.refund.response;

import poomasi.domain.order._aftersales.entity._product.ProductAfterSalesStatus;
import poomasi.domain.order.entity._product.OrderedProductStatus;

import java.math.BigDecimal;

public record ProductRefundRequestResponse(
Long orderedProductId,
OrderedProductStatus orderedProductStatus,

Long productAfterSalesDetailId,
Integer refundQuantity,
ProductAfterSalesStatus productAfterSalesTypem,
BigDecimal finalRefundAmount
) {
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package poomasi.domain.order._aftersales.entity._farm;



public class FarmAfterSales {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package poomasi.domain.order._aftersales.entity._product;

import jakarta.persistence.*;
import jdk.jfr.Description;
import jdk.jfr.Timestamp;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import poomasi.domain.order.entity._product.OrderedProduct;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Description("상품 판매 후 교환/환불/추소 history")
@Entity
@Getter
@Table(name="product_after_sales_detail")
@NoArgsConstructor
public class ProductAfterSalesDetail {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "created_at")
@CreationTimestamp
private LocalDateTime createdAt = LocalDateTime.now();

@Column(name = "updated_at")
@UpdateTimestamp
private LocalDateTime updateAt = LocalDateTime.now();

@Column(name = "deleted_at")
@Timestamp
private LocalDateTime deletedAt;

@ManyToOne
private OrderedProduct orderedProduct;

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "product_refund_detail_id", nullable = true) // 외래 키 설정
private ProductRefundDetail productRefundDetail;

//TODO : payment에 있는 것을 변경해야 함
private String impUid;

@Description("환불/교환/취소 금액")
private BigDecimal adjustAmount;

@Description("취소/교환/환불 수량")
private Integer adjustmentQuantity;

@Description("환불/교환/취소 요청 사유")
private String reason;

@Enumerated(EnumType.STRING)
private ProductAfterSalesStatus productAfterSalesStatus;

@Builder
public ProductAfterSalesDetail(OrderedProduct orderedProduct,
BigDecimal adjustAmount,
String reason,
Integer adjustmentQuantity,
ProductAfterSalesStatus productAfterSalesStatus) {
this.orderedProduct = orderedProduct;
this.adjustAmount = adjustAmount;
this.reason = reason;
this.adjustmentQuantity = adjustmentQuantity;
this.productAfterSalesStatus = productAfterSalesStatus;
}

public void setOrderedProduct(OrderedProduct orderedProduct) {
this.orderedProduct = orderedProduct;
}

public void setProductAfterSalesStatus(ProductAfterSalesStatus productAfterSalesStatus){
this.productAfterSalesStatus = productAfterSalesStatus;
}

public String getProductRefundDeniedReason(){
return this.productRefundDetail.getProductRefundDeniedReason();
}

public void setProductRefundDeniedReason(String productRefundDeniedReason){
this.productRefundDetail.setProductRefundDeniedReason(productRefundDeniedReason);
}

public void setProductRefundDetail(ProductRefundDetail productRefundDetail) {
this.productRefundDetail = productRefundDetail;
productRefundDetail.setProductAfterSalesDetail(this);
}

public void changeRefundApproveStatus(String invoiceNumber){
this.productAfterSalesStatus = ProductAfterSalesStatus.REFUND_APPROVED;
this.productRefundDetail.setInvoiceNumber(invoiceNumber);
}

}

Loading

0 comments on commit f62d7be

Please sign in to comment.