Skip to content

Commit

Permalink
Merge branch 'weekly_4' into feat/27/swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
westzeroright authored Sep 29, 2024
2 parents 90c2682 + 8f5e4a1 commit 3645548
Show file tree
Hide file tree
Showing 48 changed files with 1,110 additions and 141 deletions.
9 changes: 2 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ apply {
dependencies {
/** spring boot starter */
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'

/** Json Web Token */
implementation "io.jsonwebtoken:jjwt-api:${jjwt_version}"
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${swagger_version}"

testImplementation 'org.springframework.boot:spring-boot-starter-test'
// testImplementation 'org.springframework.security:spring-security-test'

/** thymeleaf and spring security integration */
// implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'

/** lombok */
compileOnly 'org.projectlombok:lombok'
Expand All @@ -57,8 +54,6 @@ dependencies {

runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly "io.jsonwebtoken:jjwt-impl:${jjwt_version}"
runtimeOnly "io.jsonwebtoken:jjwt-jackson:${jjwt_version}"

testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.ordertogether.team14_be.auth.JwtUtil;
import com.ordertogether.team14_be.auth.application.dto.KakaoUserInfo;
import com.ordertogether.team14_be.auth.presentation.KakaoClient;
import com.ordertogether.team14_be.memebr.application.service.MemberService;
import com.ordertogether.team14_be.member.application.service.MemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.ordertogether.team14_be.common.util;

import java.util.UUID;
import lombok.experimental.UtilityClass;

@UtilityClass
public final class IdempotentKeyGenerator {

public static String generate(String seed) {
return UUID.nameUUIDFromBytes(seed.getBytes()).toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ordertogether.team14_be.common.web.response;

import jakarta.annotation.Nullable;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class ApiResponse<T> {

private Integer status;
private String message;
private T data;

public static <T> ApiResponse<T> with(HttpStatus httpStatus, String message, @Nullable T data) {
return new ApiResponse<>(httpStatus.value(), message, data);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package com.ordertogether.team14_be.config;

import com.ordertogether.team14_be.common.persistence.auditing.AuditorProvider;
import com.ordertogether.team14_be.payment.persistence.jpa.repository.JpaPaymentEventRepository;
import com.ordertogether.team14_be.payment.persistence.jpa.repository.JpaPaymentOrderRepository;
import com.ordertogether.team14_be.payment.persistence.jpa.repository.JpaProductRepository;
import com.ordertogether.team14_be.payment.persistence.jpa.repository.SimpleJpaPaymentEventRepository;
import com.ordertogether.team14_be.payment.persistence.jpa.repository.SimpleJpaPaymentOrderRepository;
import com.ordertogether.team14_be.payment.persistence.jpa.repository.SimpleJpaProductRepository;
import com.ordertogether.team14_be.payment.persistence.repository.PaymentEventRepository;
import com.ordertogether.team14_be.payment.persistence.repository.PaymentOrderRepository;
import com.ordertogether.team14_be.payment.persistence.repository.ProductRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;
Expand All @@ -15,4 +24,24 @@ public class PersistenceConfig {
public AuditorAware<Long> auditorProvider() {
return new AuditorProvider();
}

@Bean
public PaymentEventRepository paymentEventRepository(
SimpleJpaPaymentEventRepository simpleJpaPaymentEventRepository) {
return new JpaPaymentEventRepository(simpleJpaPaymentEventRepository);
}

@Bean
public PaymentOrderRepository paymentOrderRepository(
SimpleJpaPaymentOrderRepository simpleJpaPaymentOrderRepository,
SimpleJpaProductRepository simpleJpaProductRepository) {
return new JpaPaymentOrderRepository(
simpleJpaPaymentOrderRepository, simpleJpaProductRepository);
}

@Bean
public ProductRepository productRepository(
SimpleJpaProductRepository simpleJpaProductRepository) {
return new JpaProductRepository(simpleJpaProductRepository);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.ordertogether.team14_be.memebr.application.service;
package com.ordertogether.team14_be.member.application.service;

import com.ordertogether.team14_be.memebr.persistence.MemberRepository;
import com.ordertogether.team14_be.memebr.persistence.entity.Member;
import com.ordertogether.team14_be.member.persistence.MemberRepository;
import com.ordertogether.team14_be.member.persistence.entity.Member;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ordertogether.team14_be.memebr.persistence;
package com.ordertogether.team14_be.member.persistence;

import com.ordertogether.team14_be.memebr.persistence.entity.Member;
import com.ordertogether.team14_be.member.persistence.entity.Member;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ordertogether.team14_be.memebr.persistence.entity;
package com.ordertogether.team14_be.member.persistence.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
package com.ordertogether.team14_be.payment.domain;

import com.ordertogether.team14_be.common.persistence.entity.BaseTimeEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import java.math.BigDecimal;
import java.util.List;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

@Entity
@Builder
@Getter
@SuperBuilder
@ToString
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PaymentEvent extends BaseTimeEntity {
public class PaymentEvent {

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

@Column(nullable = false)
private Long buyerId; // 구매자 식별자
private Long buyerId;

private List<PaymentOrder> paymentOrders;

@Column(nullable = false)
private String orderId;

private String orderName;

@Column(nullable = false)
private String paymentKey; // PSP 결제 식별자
private String paymentKey;

@Builder.Default private PaymentStatus paymentStatus = PaymentStatus.READY;

@Builder.Default private Boolean isPaymentDone = false;
public Long totalAmount() {
return paymentOrders.stream()
.map(PaymentOrder::getAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add)
.longValue();
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,42 @@
package com.ordertogether.team14_be.payment.domain;

import com.ordertogether.team14_be.common.persistence.entity.BaseTimeEntity;
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.ManyToOne;
import java.math.BigDecimal;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import java.util.Objects;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

@Entity
@Builder
@Getter
@SuperBuilder
@ToString
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PaymentOrder extends BaseTimeEntity {
public class PaymentOrder {

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

@Column(nullable = false)
private Long sellerId; // 판매자 식별자
private Long productId;

@ManyToOne(fetch = FetchType.LAZY)
private Product productId;

@Column(nullable = false)
private String orderId;

@Column(precision = 10, scale = 2)
private BigDecimal amount; // 결제 금액
private String orderName;

private BigDecimal amount;

public PaymentOrder updateProductInfo(Product product) {
if (isProductMismatch(product)) {
throw new IllegalArgumentException("상품 정보가 일치하지 않습니다.");
}

this.orderName = product.getName();
this.amount = product.getPrice();

@Enumerated(EnumType.STRING)
@Builder.Default
private PaymentOrderStatus paymentOrderStatus = PaymentOrderStatus.READY;
return this;
}

@Builder.Default private Byte retryCount = 0; // 재시도 횟수
public boolean isMissingProductInfo() {
return Objects.isNull(orderName) && Objects.isNull(amount);
}

@Builder.Default private Byte retryThreshold = 5; // 재시도 허용 임계값
private boolean isProductMismatch(Product product) {
return !Objects.equals(productId, product.getId());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.ordertogether.team14_be.payment.domain;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/** 결제 상태 */
@Getter
@RequiredArgsConstructor
public enum PaymentStatus {
READY("결제 준비"),
EXECUTING("결제 진행 중"),
SUCCESS("결제 성공"),
FAIL("결제 실패");

private final String description;
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
package com.ordertogether.team14_be.payment.domain;

import com.ordertogether.team14_be.common.persistence.entity.BaseTimeEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import java.math.BigDecimal;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

@Entity
@Builder
@Getter
@SuperBuilder
@ToString
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Product extends BaseTimeEntity {
public class Product {

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

@Column(nullable = false)
private String name;

@Column(nullable = false)
private BigDecimal price;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.ordertogether.team14_be.payment.persistence.jpa.entity;

import com.ordertogether.team14_be.common.persistence.entity.BaseTimeEntity;
import com.ordertogether.team14_be.payment.domain.PaymentStatus;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

@Entity
@Getter
@SuperBuilder
@ToString
@Table(name = "payment_event")
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PaymentEventEntity extends BaseTimeEntity {

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

@Column(nullable = false)
private Long buyerId; // 구매자 식별자

@Column(nullable = false)
private String orderId;

@Column(nullable = false)
private String orderName;

@Column(nullable = false)
private String paymentKey; // PSP 결제 식별자

@Builder.Default
@Enumerated(EnumType.STRING)
private PaymentStatus paymentStatus = PaymentStatus.READY;
}
Loading

0 comments on commit 3645548

Please sign in to comment.