Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ configurations {
}

repositories {
maven { url 'https://jitpack.io' }
mavenCentral()
}

Expand Down Expand Up @@ -59,6 +60,9 @@ dependencies {
// google maps
implementation group: 'com.google.maps', name: 'google-maps-services', version: '2.2.0'

// payment
implementation 'com.github.iamport:iamport-rest-client-java:0.2.23'

compileOnly 'org.projectlombok:lombok'

runtimeOnly 'com.mysql:mysql-connector-j'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.gongspot.project.domain.order.entity;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.dsl.PathInits;


/**
* QOrder is a Querydsl query type for Order
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QOrder extends EntityPathBase<Order> {

private static final long serialVersionUID = 2108355418L;

private static final PathInits INITS = PathInits.DIRECT2;

public static final QOrder order = new QOrder("order1");

public final com.gongspot.project.common.entity.QBaseEntity _super = new com.gongspot.project.common.entity.QBaseEntity(this);

//inherited
public final DateTimePath<java.time.LocalDateTime> createdAt = _super.createdAt;

//inherited
public final DateTimePath<java.time.LocalDateTime> deletedAt = _super.deletedAt;

public final StringPath merchantUid = createString("merchantUid");

public final StringPath ordererName = createString("ordererName");

public final NumberPath<Long> orderId = createNumber("orderId", Long.class);

public final EnumPath<PaymentStatus> paymentStatus = createEnum("paymentStatus", PaymentStatus.class);

public final EnumPath<PayMethod> payMethod = createEnum("payMethod", PayMethod.class);

public final com.gongspot.project.domain.point.entity.QPoint point;

public final QProduct product;

public final NumberPath<java.math.BigDecimal> totalPrice = createNumber("totalPrice", java.math.BigDecimal.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> updatedAt = _super.updatedAt;

public final com.gongspot.project.domain.user.entity.QUser user;

public QOrder(String variable) {
this(Order.class, forVariable(variable), INITS);
}

public QOrder(Path<? extends Order> path) {
this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS));
}

public QOrder(PathMetadata metadata) {
this(metadata, PathInits.getFor(metadata, INITS));
}

public QOrder(PathMetadata metadata, PathInits inits) {
this(Order.class, metadata, inits);
}

public QOrder(Class<? extends Order> type, PathMetadata metadata, PathInits inits) {
super(type, metadata, inits);
this.point = inits.isInitialized("point") ? new com.gongspot.project.domain.point.entity.QPoint(forProperty("point"), inits.get("point")) : null;
this.product = inits.isInitialized("product") ? new QProduct(forProperty("product")) : null;
this.user = inits.isInitialized("user") ? new com.gongspot.project.domain.user.entity.QUser(forProperty("user")) : null;
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.gongspot.project.domain.order.entity;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;


/**
* QProduct is a Querydsl query type for Product
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QProduct extends EntityPathBase<Product> {

private static final long serialVersionUID = -197368325L;

public static final QProduct product = new QProduct("product");

public final NumberPath<Long> id = createNumber("id", Long.class);

public final StringPath name = createString("name");

public final NumberPath<Integer> point = createNumber("point", Integer.class);

public final NumberPath<java.math.BigDecimal> price = createNumber("price", java.math.BigDecimal.class);

public QProduct(String variable) {
super(Product.class, forVariable(variable));
}

public QProduct(Path<? extends Product> path) {
super(path.getType(), path.getMetadata());
}

public QProduct(PathMetadata metadata) {
super(Product.class, metadata);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ public enum ErrorStatus implements BaseErrorCode {
FILE_SIZE_EXCEEDED(HttpStatus.BAD_REQUEST, "FILE4003", "ํŒŒ์ผ ํฌ๊ธฐ๊ฐ€ ์ œํ•œ์„ ์ดˆ๊ณผํ–ˆ์Šต๋‹ˆ๋‹ค."),

//New Place
NEW_PLACE_NOT_FOUND(HttpStatus.NOT_FOUND, "NEWPLACE4001", "์ƒˆ๋กœ์šด ๊ณต๊ฐ„์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
NEW_PLACE_NOT_FOUND(HttpStatus.NOT_FOUND, "NEWPLACE4001", "์ƒˆ๋กœ์šด ๊ณต๊ฐ„์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),

// ์ƒํ’ˆ
PRODUCT_NOT_FOUND(HttpStatus.NOT_FOUND, "PRODUCT4001", "ํ•ด๋‹น ์ƒํ’ˆ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
PAYMENT_AMOUNT_MISMATCH(HttpStatus.BAD_REQUEST, "PRODUCT4002", "๊ฒฐ์ œ ๊ธˆ์•ก์ด ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
PAYMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "PRODUCT4003", "๊ฒฐ์ œ ๋‚ด์—ญ์ด ์—†์Šต๋‹ˆ๋‹ค."),
PAYMENT_VERIFICATION_FAILED(HttpStatus.BAD_REQUEST, "PRODUCT4004", "๊ฒฐ์ œ ์ธ์ฆ์ด ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค."),
; // ์œ„์— ์ ์„ ๊ฒƒ !

private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.gongspot.project.domain.order.controller;

import com.gongspot.project.domain.order.dto.OrderRequestDTO;
import com.gongspot.project.domain.order.entity.Order;
import com.gongspot.project.domain.order.service.OrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
@RequiredArgsConstructor
@Slf4j
public class OrderController {

private final OrderService orderService;

@PostMapping("/payment/validate")
public String validatePayment(@RequestBody OrderRequestDTO request) {

Order validatedOrder = orderService.processPaymentDone(request);

log.info("๊ฒฐ์ œ ๊ฒ€์ฆ ๋ฐ ์ฃผ๋ฌธ ์ฒ˜๋ฆฌ ์„ฑ๊ณต. ์ฃผ๋ฌธ ๋ฒˆํ˜ธ: {}", validatedOrder.getMerchantUid());

return "๊ฒฐ์ œ ์„ฑ๊ณต ๋ฐ ์„œ๋ฒ„ ๊ฒ€์ฆ ์™„๋ฃŒ";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.gongspot.project.domain.order.dto;

import com.gongspot.project.domain.order.entity.PayMethod;
import lombok.*;

import java.math.BigDecimal;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class OrderRequestDTO {

private String impUid;
private Long userId;
private Long productId;
private PayMethod payMethod;
private BigDecimal totalPrice;
private String merchantUid;

}
86 changes: 86 additions & 0 deletions src/main/java/com/gongspot/project/domain/order/entity/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.gongspot.project.domain.order.entity;

import com.gongspot.project.common.entity.BaseEntity;
import com.gongspot.project.domain.point.entity.Point;
import com.gongspot.project.domain.user.entity.User;
import jakarta.persistence.*;
import lombok.*;
import java.math.BigDecimal;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Entity
@Table(name = "order")
public class Order extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "order_id")
private Long orderId; // PK

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private User user;

@Column(name = "order_name")
private String ordererName; // ์ฃผ๋ฌธ์ž ์ด๋ฆ„

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "product_id", nullable = false)
private Product product;

@Enumerated(EnumType.STRING)
@Column(name = "pay_method")
private PayMethod payMethod; // ๊ฒฐ์ œ ๋ฐฉ์‹

@Column(length = 100, name = "merchant_uid")
private String merchantUid; // ์ฃผ๋ฌธ๋ฒˆํ˜ธ

@Column(name = "total_price", nullable = false)
private BigDecimal totalPrice; // ๊ฒฐ์ œ ๊ธˆ์•ก

@Enumerated(EnumType.STRING)
@Column(name = "payment_status")
private PaymentStatus paymentStatus;

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "point_id")
private Point point;

@Builder(access = AccessLevel.PRIVATE)
private Order(User user, Product product, String merchantUid, PayMethod payMethod, String ordererName, BigDecimal totalPrice) {
this.user = user;
this.product = product;
this.merchantUid = merchantUid;
this.payMethod = payMethod;
this.ordererName = ordererName;
this.totalPrice = totalPrice;
this.paymentStatus = PaymentStatus.PENDING; // ์ดˆ๊ธฐ ์ƒํƒœ๋Š” PENDING
}

public static Order createOrder(User user, Product product) {
return Order.builder()
.user(user)
.product(product)
.ordererName(user.getNickname())
.totalPrice(product.getPrice())
.build();
}

public void markAsPaid(String merchantUid, PayMethod payMethod) {
this.merchantUid = merchantUid;
this.payMethod = payMethod;
this.paymentStatus = PaymentStatus.SUCCESS;
}


public void markAsCanceled() {
this.paymentStatus = PaymentStatus.CANCELLED;
}


public void addPoint(Point point) {
this.point = point;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.gongspot.project.domain.order.entity;

public enum PayMethod {
CARD, // ์‹ ์šฉ/์ฒดํฌ์นด๋“œ
BANK, // ๊ณ„์ขŒ์ด์ฒด
PHONE, // ํœด๋Œ€ํฐ ๊ฒฐ์ œ
VIRTUAL, // ๊ฐ€์ƒ๊ณ„์ขŒ
KAKAO, // ์นด์นด์˜คํŽ˜์ด
NAVER, // ๋„ค์ด๋ฒ„ํŽ˜์ด
PAYCO // ํŽ˜์ด์ฝ”
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gongspot.project.domain.order.entity;

public enum PaymentStatus {
PENDING,
SUCCESS,
FAILED,
CANCELLED,
READY
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.gongspot.project.domain.order.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.math.BigDecimal;

@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "product")
public class Product {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "product_id")
private Long id;

@Column(name = "name", nullable = false)
private String name;

@Column(name = "price", nullable = false)
private BigDecimal price;

@Column(name = "point", nullable = false)
private Integer point;

public Product(String name, BigDecimal price, Integer point) {
this.name = name;
this.price = price;
this.point = point;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.gongspot.project.domain.order.repository;

import com.gongspot.project.domain.order.entity.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface OrderRepository extends JpaRepository<Order, Long> {
Order findByMerchantUid(String merchantUid);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.gongspot.project.domain.order.repository;

import com.gongspot.project.domain.order.entity.Product;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {
Product findByName(String name);
}
Loading