#33 tdd(order-service): payment - package
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
package com.example.productorderservice.order;
|
||||
|
||||
import com.example.productorderservice.product.Product;
|
||||
|
||||
interface OrderPort {
|
||||
Product getProductById(Long productId);
|
||||
|
||||
void save(Order order);
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.example.productorderservice.order;
|
||||
package com.example.productorderservice.order.adapter;
|
||||
|
||||
import com.example.productorderservice.product.Product;
|
||||
import com.example.productorderservice.product.ProductRepository;
|
||||
import com.example.productorderservice.order.application.port.OrderPort;
|
||||
import com.example.productorderservice.order.domain.Order;
|
||||
import com.example.productorderservice.product.domain.Product;
|
||||
import com.example.productorderservice.product.adapter.ProductRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.productorderservice.order;
|
||||
package com.example.productorderservice.order.adapter;
|
||||
|
||||
import com.example.productorderservice.order.domain.Order;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.productorderservice.order;
|
||||
package com.example.productorderservice.order.application.controller;
|
||||
|
||||
import com.example.productorderservice.order.application.service.CreateOrderRequest;
|
||||
import com.example.productorderservice.order.application.service.OrderService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.example.productorderservice.order.application.port;
|
||||
|
||||
import com.example.productorderservice.order.domain.Order;
|
||||
import com.example.productorderservice.product.domain.Product;
|
||||
|
||||
public interface OrderPort {
|
||||
Product getProductById(Long productId);
|
||||
|
||||
void save(Order order);
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.example.productorderservice.order;
|
||||
package com.example.productorderservice.order.application.service;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
record CreateOrderRequest(Long productId, int quantity) {
|
||||
CreateOrderRequest {
|
||||
public record CreateOrderRequest(Long productId, int quantity) {
|
||||
public CreateOrderRequest {
|
||||
Assert.notNull(productId, "상품 ID는 필수입니다.");
|
||||
Assert.isTrue(quantity > 0, "수량은 0보다 커야 합니다.");
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.example.productorderservice.order;
|
||||
package com.example.productorderservice.order.application.service;
|
||||
|
||||
import com.example.productorderservice.product.Product;
|
||||
import com.example.productorderservice.order.application.port.OrderPort;
|
||||
import com.example.productorderservice.order.domain.Order;
|
||||
import com.example.productorderservice.product.domain.Product;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.example.productorderservice.order;
|
||||
package com.example.productorderservice.order.domain;
|
||||
|
||||
import com.example.productorderservice.product.Product;
|
||||
import com.example.productorderservice.product.domain.Product;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.example.productorderservice.payment;
|
||||
|
||||
import com.example.productorderservice.order.Order;
|
||||
|
||||
interface PaymentPort {
|
||||
Order getOrder(Long orderId);
|
||||
|
||||
void pay(int totalPrice, String cardNumber);
|
||||
|
||||
void save(Payment payment);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.productorderservice.payment;
|
||||
package com.example.productorderservice.payment.adapter;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.example.productorderservice.payment;
|
||||
package com.example.productorderservice.payment.adapter;
|
||||
|
||||
import com.example.productorderservice.order.Order;
|
||||
import com.example.productorderservice.order.OrderRepository;
|
||||
import com.example.productorderservice.product.DiscountPolicy;
|
||||
import com.example.productorderservice.product.Product;
|
||||
import com.example.productorderservice.order.domain.Order;
|
||||
import com.example.productorderservice.order.adapter.OrderRepository;
|
||||
import com.example.productorderservice.payment.application.port.PaymentPort;
|
||||
import com.example.productorderservice.payment.domain.Payment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.productorderservice.payment;
|
||||
package com.example.productorderservice.payment.adapter;
|
||||
|
||||
interface PaymentGateway {
|
||||
void execute(int totalPrice, String cardNumber);
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.productorderservice.payment;
|
||||
package com.example.productorderservice.payment.adapter;
|
||||
|
||||
import com.example.productorderservice.payment.domain.Payment;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.productorderservice.payment;
|
||||
package com.example.productorderservice.payment.application.controller;
|
||||
|
||||
import com.example.productorderservice.payment.application.service.PaymentRequest;
|
||||
import com.example.productorderservice.payment.application.service.PaymentService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.example.productorderservice.payment.application.port;
|
||||
|
||||
import com.example.productorderservice.order.domain.Order;
|
||||
import com.example.productorderservice.payment.domain.Payment;
|
||||
|
||||
public interface PaymentPort {
|
||||
Order getOrder(Long orderId);
|
||||
|
||||
void pay(int totalPrice, String cardNumber);
|
||||
|
||||
void save(Payment payment);
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.example.productorderservice.payment;
|
||||
package com.example.productorderservice.payment.application.service;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
record PaymentRequest(Long orderId, String cardNumber) {
|
||||
public record PaymentRequest(Long orderId, String cardNumber) {
|
||||
|
||||
PaymentRequest {
|
||||
public PaymentRequest {
|
||||
Assert.notNull(orderId, "주문 ID는 필수입니다.");
|
||||
Assert.hasText(cardNumber, "카드번호는 필수입니다.");
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.example.productorderservice.payment;
|
||||
package com.example.productorderservice.payment.application.service;
|
||||
|
||||
import com.example.productorderservice.order.Order;
|
||||
import com.example.productorderservice.order.domain.Order;
|
||||
import com.example.productorderservice.payment.application.port.PaymentPort;
|
||||
import com.example.productorderservice.payment.domain.Payment;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.example.productorderservice.payment;
|
||||
package com.example.productorderservice.payment.domain;
|
||||
|
||||
import com.example.productorderservice.order.Order;
|
||||
import com.example.productorderservice.order.domain.Order;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -11,6 +11,7 @@ import javax.persistence.*;
|
||||
@Entity
|
||||
@Getter
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public
|
||||
class Payment {
|
||||
|
||||
@Id
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.example.productorderservice.product;
|
||||
|
||||
interface ProductPort {
|
||||
void save(Product product);
|
||||
|
||||
Product getProduct(long productId);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.productorderservice.product;
|
||||
package com.example.productorderservice.product.adapter;
|
||||
|
||||
import com.example.productorderservice.product.application.port.ProductPort;
|
||||
import com.example.productorderservice.product.domain.Product;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@@ -1,11 +1,9 @@
|
||||
package com.example.productorderservice.product;
|
||||
package com.example.productorderservice.product.adapter;
|
||||
|
||||
import com.example.productorderservice.product.domain.Product;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
public
|
||||
interface ProductRepository extends JpaRepository<Product, Long> {
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.example.productorderservice.product;
|
||||
package com.example.productorderservice.product.application.controller;
|
||||
|
||||
import com.example.productorderservice.product.application.service.AddProductRequest;
|
||||
import com.example.productorderservice.product.application.service.GetProductResponse;
|
||||
import com.example.productorderservice.product.application.service.ProductService;
|
||||
import com.example.productorderservice.product.application.service.UpdateProductRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.example.productorderservice.product.application.port;
|
||||
|
||||
import com.example.productorderservice.product.domain.Product;
|
||||
|
||||
public interface ProductPort {
|
||||
void save(Product product);
|
||||
|
||||
Product getProduct(long productId);
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.example.productorderservice.product;
|
||||
package com.example.productorderservice.product.application.service;
|
||||
|
||||
import com.example.productorderservice.product.domain.DiscountPolicy;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
record AddProductRequest(String name, int price, DiscountPolicy discountPolicy) {
|
||||
AddProductRequest {
|
||||
public record AddProductRequest(String name, int price, DiscountPolicy discountPolicy) {
|
||||
public AddProductRequest {
|
||||
Assert.hasText(name, "상품명은 필수입니다.");
|
||||
Assert.isTrue(price > 0, "상품 가격은 0보다 커야 합니다.");
|
||||
Assert.notNull(discountPolicy, "할인 정책은 필수입니다.");
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.example.productorderservice.product;
|
||||
package com.example.productorderservice.product.application.service;
|
||||
|
||||
import com.example.productorderservice.product.domain.DiscountPolicy;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
record GetProductResponse(
|
||||
public record GetProductResponse(
|
||||
long id,
|
||||
String name,
|
||||
int price,
|
||||
DiscountPolicy discountPolicy
|
||||
) {
|
||||
|
||||
GetProductResponse {
|
||||
public GetProductResponse {
|
||||
Assert.notNull(id, "상품 ID는 필수입니다.");
|
||||
Assert.hasText(name, "상품명은 필수입니다.");
|
||||
Assert.isTrue(price > 0, "상품 가격은 0보다 커야 합니다.");
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.productorderservice.product;
|
||||
package com.example.productorderservice.product.application.service;
|
||||
|
||||
import com.example.productorderservice.product.application.port.ProductPort;
|
||||
import com.example.productorderservice.product.domain.Product;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -7,7 +9,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public class ProductService {
|
||||
private final ProductPort productPort;
|
||||
|
||||
ProductService(ProductPort productPort) {
|
||||
public ProductService(ProductPort productPort) {
|
||||
this.productPort = productPort;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.example.productorderservice.product;
|
||||
package com.example.productorderservice.product.application.service;
|
||||
|
||||
import com.example.productorderservice.product.domain.DiscountPolicy;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
record UpdateProductRequest(String name, int price, DiscountPolicy discountPolicy) {
|
||||
public record UpdateProductRequest(String name, int price, DiscountPolicy discountPolicy) {
|
||||
|
||||
UpdateProductRequest {
|
||||
public UpdateProductRequest {
|
||||
Assert.hasText(name, "상품명은 필수입니다.");
|
||||
Assert.isTrue(price > 0, "상품 가격은 0보다 커야 합니다.");
|
||||
Assert.notNull(discountPolicy, "할인 정책은 필수입니다.");
|
||||
@@ -1,19 +1,19 @@
|
||||
package com.example.productorderservice.product;
|
||||
package com.example.productorderservice.product.domain;
|
||||
|
||||
public enum DiscountPolicy {
|
||||
NONE {
|
||||
@Override
|
||||
int applyDiscount(int price) {
|
||||
public int applyDiscount(int price) {
|
||||
return price;
|
||||
}
|
||||
},
|
||||
FIX_1000_AMOUNT {
|
||||
@Override
|
||||
int applyDiscount(int price) {
|
||||
public int applyDiscount(int price) {
|
||||
return Math.max(price - 1000, 0);
|
||||
}
|
||||
}
|
||||
|
||||
;
|
||||
abstract int applyDiscount(int price);
|
||||
public abstract int applyDiscount(int price);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.productorderservice.product;
|
||||
package com.example.productorderservice.product.domain;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
@@ -1,13 +1,10 @@
|
||||
package com.example.productorderservice.order;
|
||||
|
||||
import com.example.productorderservice.ApiTest;
|
||||
import com.example.productorderservice.order.application.service.CreateOrderRequest;
|
||||
import com.example.productorderservice.product.ProductSteps;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.response.ExtractableResponse;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.example.productorderservice.order;
|
||||
|
||||
import com.example.productorderservice.product.ProductService;
|
||||
import com.example.productorderservice.order.application.service.CreateOrderRequest;
|
||||
import com.example.productorderservice.order.application.service.OrderService;
|
||||
import com.example.productorderservice.product.application.service.ProductService;
|
||||
import com.example.productorderservice.product.ProductSteps;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.productorderservice.order;
|
||||
|
||||
import com.example.productorderservice.order.application.service.CreateOrderRequest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.response.ExtractableResponse;
|
||||
import io.restassured.response.Response;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.example.productorderservice.order;
|
||||
|
||||
import com.example.productorderservice.product.DiscountPolicy;
|
||||
import com.example.productorderservice.product.Product;
|
||||
import com.example.productorderservice.order.domain.Order;
|
||||
import com.example.productorderservice.product.domain.DiscountPolicy;
|
||||
import com.example.productorderservice.product.domain.Product;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.example.productorderservice.payment;
|
||||
|
||||
import com.example.productorderservice.order.OrderService;
|
||||
import com.example.productorderservice.order.application.service.OrderService;
|
||||
import com.example.productorderservice.order.OrderSteps;
|
||||
import com.example.productorderservice.product.ProductService;
|
||||
import com.example.productorderservice.payment.application.service.PaymentRequest;
|
||||
import com.example.productorderservice.payment.application.service.PaymentService;
|
||||
import com.example.productorderservice.product.application.service.ProductService;
|
||||
import com.example.productorderservice.product.ProductSteps;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.productorderservice.payment;
|
||||
|
||||
import com.example.productorderservice.payment.application.service.PaymentRequest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.response.ExtractableResponse;
|
||||
import io.restassured.response.Response;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.productorderservice.product;
|
||||
|
||||
import com.example.productorderservice.product.domain.DiscountPolicy;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package com.example.productorderservice.product;
|
||||
|
||||
import com.example.productorderservice.ApiTest;
|
||||
import io.restassured.RestAssured;
|
||||
import com.example.productorderservice.product.adapter.ProductRepository;
|
||||
import io.restassured.response.ExtractableResponse;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.example.productorderservice.product;
|
||||
|
||||
import com.example.productorderservice.product.application.port.ProductPort;
|
||||
import com.example.productorderservice.product.application.service.ProductService;
|
||||
import com.example.productorderservice.product.application.service.UpdateProductRequest;
|
||||
import com.example.productorderservice.product.domain.DiscountPolicy;
|
||||
import com.example.productorderservice.product.domain.Product;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.example.productorderservice.product;
|
||||
|
||||
import com.example.productorderservice.product.application.service.AddProductRequest;
|
||||
import com.example.productorderservice.product.application.service.GetProductResponse;
|
||||
import com.example.productorderservice.product.application.service.ProductService;
|
||||
import com.example.productorderservice.product.application.service.UpdateProductRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.example.productorderservice.product;
|
||||
|
||||
import com.example.productorderservice.product.application.service.AddProductRequest;
|
||||
import com.example.productorderservice.product.application.service.UpdateProductRequest;
|
||||
import com.example.productorderservice.product.domain.DiscountPolicy;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.response.ExtractableResponse;
|
||||
import io.restassured.response.Response;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.productorderservice.product;
|
||||
|
||||
import com.example.productorderservice.product.domain.DiscountPolicy;
|
||||
import com.example.productorderservice.product.domain.Product;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
Reference in New Issue
Block a user