Skip to content

Commit

Permalink
Merge pull request #31 from marinesnow34/payment
Browse files Browse the repository at this point in the history
Feat: 토스 주문 요청 결제 ID 생성 구현
  • Loading branch information
marinesnow34 authored Nov 19, 2023
2 parents f1d8af2 + 7b46846 commit 8169e9b
Show file tree
Hide file tree
Showing 25 changed files with 472 additions and 110 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/readyvery/readyverydemo/domain/Coupon.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -45,7 +46,7 @@ public class Coupon extends BaseTimeEntity {
@JoinColumn(name = "store_idx")
private Store store;

// @OneToOne(mappedBy = "coupon", fetch = LAZY)
// private Order order;
@OneToOne(mappedBy = "coupon", fetch = FetchType.LAZY)
private Order order;

}
2 changes: 2 additions & 0 deletions src/main/java/com/readyvery/readyverydemo/domain/Foodie.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ public class Foodie extends BaseTimeEntity {
@OneToMany(mappedBy = "foodie", cascade = CascadeType.ALL)
private List<CouponMenu> couponMenus = new ArrayList<CouponMenu>();

@OneToMany(mappedBy = "foodie", cascade = CascadeType.ALL)
private List<OrderItem> orderItems = new ArrayList<OrderItem>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ public class FoodieOption extends BaseTimeEntity {
@OneToMany(mappedBy = "foodieOption", cascade = CascadeType.ALL)
private List<CartOption> cartOptions = new ArrayList<CartOption>();

// order item option 연관 관계 매핑
@OneToMany(mappedBy = "foodieOption", cascade = CascadeType.ALL)
private List<OrderItemOption> orderItemOptions = new ArrayList<OrderItemOption>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ public class FoodieOptionCategory extends BaseTimeEntity {
@OneToMany(mappedBy = "foodieOptionCategory", cascade = CascadeType.ALL)
private List<CartOption> cartOptions = new ArrayList<CartOption>();

// order item option 연관 관계 매핑
@OneToMany(mappedBy = "foodieOptionCategory", cascade = CascadeType.ALL)
private List<OrderItemOption> orderItemOptions = new ArrayList<OrderItemOption>();
}
91 changes: 91 additions & 0 deletions src/main/java/com/readyvery/readyverydemo/domain/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.readyvery.readyverydemo.domain;

import java.util.ArrayList;
import java.util.List;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Getter
@Entity
@Builder
@Table(name = "ORDERS")
@AllArgsConstructor
@NoArgsConstructor
@Slf4j
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "order_idx")
private Long id;

// 총 결제 가격
@Column
private Long amount;

// 결제 키 값
@Column
private String paymentKey;

// 주문 id
@Column
private String orderId;

// 주문 명
@Column
private String orderName;

// 토스 결제 가격
@Column
private Long totalAmount;

// 결제 방법
@Column
private String method;

// 주문 번호
@Column
private String orderNumber;

// 주문 상태
@Column
@Enumerated(EnumType.STRING)
private Progress progress;

// 가게 아이템 연관 관계
@OneToMany(mappedBy = "order")
private List<OrderItem> orderItems = new ArrayList<OrderItem>();

// 가게 연관 관계
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "store_idx")
private Store store;

// 유저 연관 관계
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_idx")
private UserInfo userInfo;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "coupon_idx")
private Coupon coupon;

@OneToOne(mappedBy = "order", fetch = FetchType.LAZY)
private Receipt receipt;
}
49 changes: 49 additions & 0 deletions src/main/java/com/readyvery/readyverydemo/domain/OrderItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.readyvery.readyverydemo.domain;

import java.util.ArrayList;
import java.util.List;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Getter
@Entity
@Builder
@Table(name = "ORDER_ITEM")
@AllArgsConstructor
@NoArgsConstructor
@Slf4j
public class OrderItem {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "order_item_idx")
private Long id;

@Column
private Long count;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_idx")
private Order order;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "foodie_idx")
private Foodie foodie;

@OneToMany(mappedBy = "orderItem")
private List<OrderItemOption> orderItemOptions = new ArrayList<OrderItemOption>();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.readyvery.readyverydemo.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Getter
@Entity
@Builder
@Table(name = "ORDER_ITEM_OPTION")
@AllArgsConstructor
@NoArgsConstructor
@Slf4j
public class OrderItemOption {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "order_item_option_idx")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_item_idx")
private OrderItem orderItem;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "foodie_option_idx")
private FoodieOption foodieOption;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "foodie_option_category_idx")
private FoodieOptionCategory foodieOptionCategory;
}
18 changes: 18 additions & 0 deletions src/main/java/com/readyvery/readyverydemo/domain/Progress.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.readyvery.readyverydemo.domain;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum Progress {
CANCEL("CANCEL", "주문 취소"),
REQUEST("REQUEST", "토스 결제 요청"),
ORDER("ORDER", "주문 접수"),
MAKE("MAKE", "음식 제조 중"),
COMPLETE("COMPLETE", "배달 완료"),
PICKUP("PICKUP", "픽업 완료");

private final String key;
private final String value;
}
27 changes: 27 additions & 0 deletions src/main/java/com/readyvery/readyverydemo/domain/Receipt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.readyvery.readyverydemo.domain;

import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Getter
@Entity
@Builder
@Table(name = "RECEIPT")
@AllArgsConstructor
@NoArgsConstructor
@Slf4j
public class Receipt {
@Id
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_idx")
private Order order;
}
9 changes: 6 additions & 3 deletions src/main/java/com/readyvery/readyverydemo/domain/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,19 @@ public class Store extends BaseTimeEntity {

//가게 메뉴 카테고리 연관관계 매핑
@OneToMany(mappedBy = "store", cascade = CascadeType.ALL)
private List<FoodieCategory> foodieCategories = new ArrayList<>();
private List<FoodieCategory> foodieCategories = new ArrayList<FoodieCategory>();

//가게 메뉴 연관관계 매핑
// @OneToMany(mappedBy = "store", cascade = CascadeType.ALL)
// private List<Foodie> foodies = new ArrayList<>();

//가게 장바구니 연관관계 매핑
@OneToMany(mappedBy = "store", cascade = CascadeType.ALL)
private List<Cart> carts = new ArrayList<>();
private List<Cart> carts = new ArrayList<Cart>();

@OneToMany(mappedBy = "store", cascade = CascadeType.ALL)
private List<StoreImg> imgs = new ArrayList<>();
private List<StoreImg> imgs = new ArrayList<StoreImg>();

@OneToMany(mappedBy = "store", cascade = CascadeType.ALL)
private List<Order> orders = new ArrayList<Order>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public class UserInfo extends BaseTimeEntity {
@OneToMany(mappedBy = "userInfo", cascade = CascadeType.ALL)
private List<Cart> carts = new ArrayList<Cart>();

// 유저 주문 연관관계 매핑
@OneToMany(mappedBy = "userInfo", cascade = CascadeType.ALL)
private List<Order> orders = new ArrayList<Order>();

// 유저 쿠폰 연관관계 매핑
@OneToMany(mappedBy = "userInfo", cascade = CascadeType.ALL)
private List<Coupon> coupons = new ArrayList<Coupon>();

// 리프레시토큰 업데이트
public void updateRefresh(String updateRefreshToken) {
this.refreshToken = updateRefreshToken;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.readyvery.readyverydemo.domain.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.readyvery.readyverydemo.domain.Order;

public interface OrderRepository extends JpaRepository<Order, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.readyvery.readyverydemo.src.order.dto.CartItemDeleteRes;
import com.readyvery.readyverydemo.src.order.dto.CartResetRes;
import com.readyvery.readyverydemo.src.order.dto.FoodyDetailRes;
import com.readyvery.readyverydemo.src.order.dto.PaymentReq;
import com.readyvery.readyverydemo.src.order.dto.TosspaymentMakeRes;

import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -55,6 +57,13 @@ public ResponseEntity<CartAddRes> addCart(@AuthenticationPrincipal CustomUserDet
return new ResponseEntity<>(cartAddRes, HttpStatus.OK);
}

@PostMapping("/toss")
public ResponseEntity<TosspaymentMakeRes> requestTossPayment(@AuthenticationPrincipal CustomUserDetails userDetails,
@RequestBody PaymentReq paymentReq) {
TosspaymentMakeRes tosspaymentMakeRes = orderService.requestTossPayment(userDetails, paymentReq);
return new ResponseEntity<>(tosspaymentMakeRes, HttpStatus.OK);
}

@PutMapping("/cart")
public ResponseEntity<CartEidtRes> updateCart(@AuthenticationPrincipal CustomUserDetails userDetails,
@RequestBody CartEditReq cartEditReq) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.readyvery.readyverydemo.src.order.dto.CartItemDeleteRes;
import com.readyvery.readyverydemo.src.order.dto.CartResetRes;
import com.readyvery.readyverydemo.src.order.dto.FoodyDetailRes;
import com.readyvery.readyverydemo.src.order.dto.PaymentReq;
import com.readyvery.readyverydemo.src.order.dto.TosspaymentMakeRes;

public interface OrderService {
FoodyDetailRes getFoody(Long storeId, Long foodyId, Long inout);
Expand All @@ -23,4 +25,6 @@ public interface OrderService {
CartResetRes resetCart(CustomUserDetails userDetails);

CartGetRes getCart(CustomUserDetails userDetails, Long inout);

TosspaymentMakeRes requestTossPayment(CustomUserDetails userDetails, PaymentReq paymentReq);
}
Loading

0 comments on commit 8169e9b

Please sign in to comment.