From c297b33a173fc10ec3cb9065b32304bfe262bbce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 20 Sep 2024 21:33:19 +0900 Subject: [PATCH 01/85] =?UTF-8?q?feat:=20PaymentOrder=20=EC=99=80=20Paymen?= =?UTF-8?q?tEvent=20=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ordertogether/team14_be/payment/domain/PaymentOrder.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java index 47f7c92c..8b2d9aec 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java +++ b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java @@ -26,6 +26,9 @@ public class PaymentOrder extends BaseEntity { @Column(nullable = false) private Long sellerId; // 판매자 식별자 + @ManyToOne(fetch = FetchType.LAZY) + private PaymentEvent paymentEvent; + @ManyToOne(fetch = FetchType.LAZY) private Product productId; From 1a5ddea8bc181f2dc2a90916928abd57df9e9060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Tue, 24 Sep 2024 14:14:58 +0900 Subject: [PATCH 02/85] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EC=A3=BC?= =?UTF-8?q?=EB=AC=B8=20=EC=97=94=ED=8B=B0=ED=8B=B0=EC=99=80=20=EC=83=81?= =?UTF-8?q?=ED=92=88=20=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ordertogether/team14_be/payment/domain/PaymentOrder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java index eaef2452..b252ff86 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java +++ b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java @@ -34,8 +34,8 @@ public class PaymentOrder extends BaseTimeEntity { @Column(nullable = false) private Long sellerId; // 판매자 식별자 - @ManyToOne(fetch = FetchType.LAZY) - private Product productId; + @Column(nullable = false) + private Long productId; @Column(nullable = false) private String orderId; From 2f08714cb884c68806177f2fb02b05181544b8af Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Wed, 25 Sep 2024 21:35:28 +0900 Subject: [PATCH 03/85] =?UTF-8?q?feat:=20Soft=20delete=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4=20isDeleted=20=EC=86=8D=EC=84=B1=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/entity/Spot.java | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java b/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java index edbcf92f..3f8953be 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java +++ b/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java @@ -1,36 +1,42 @@ package com.ordertogether.team14_be.spot.entity; import jakarta.persistence.*; +import java.math.BigDecimal; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import java.math.BigDecimal; - @Entity @Builder @AllArgsConstructor @NoArgsConstructor @Getter +@Table(indexes = {@Index(name = "idx_lat_lng", columnList = "lat, lng")}) public class Spot { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(precision = 10, scale = 8) + private BigDecimal lat; + + @Column(precision = 11, scale = 8) + private BigDecimal lng; - @Column(precision = 10, scale = 8) - private BigDecimal lat; + private String category; + private String store_name; + private Integer minimum_order_amount; - @Column(precision = 11, scale = 8) - private BigDecimal lng; - private String category; - private String store_name; - private Integer minimum_order_amount; + @Lob + @Column(columnDefinition = "MEDIUMTEXT") + private String together_order_link; - @Lob - @Column(columnDefinition = "MEDIUMTEXT") - private String together_order_link; - private String pick_up_location; - private String delivery_status; + private String pick_up_location; + private String delivery_status; + @Builder.Default private Boolean isDeleted = false; + public void setDeleted(boolean isDeleted) { + this.isDeleted = isDeleted; + } } From 65cff8b3e7fc8216b4d1a93260f659738517e4a7 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Wed, 25 Sep 2024 21:41:27 +0900 Subject: [PATCH 04/85] =?UTF-8?q?refactor:=20isDeleted=EA=B0=80=20false?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=83=EB=A7=8C=20=EC=A1=B0=ED=9A=8C=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/service/SpotService.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java b/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java index 225b29d3..0c539c19 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java +++ b/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java @@ -4,8 +4,10 @@ import com.ordertogether.team14_be.spot.entity.Spot; import com.ordertogether.team14_be.spot.repository.SpotRepository; import jakarta.persistence.EntityNotFoundException; +import jakarta.transaction.Transactional; import java.math.BigDecimal; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,11 +24,12 @@ public SpotService(SpotRepository spotRepository) { // Spot 전체 조회하기 public List getSpot(BigDecimal lat, BigDecimal lng) { - return spotRepository.findByLatAndLng(lat, lng).stream() + return spotRepository.findByLatAndLngAndIsDeletedFalse(lat, lng).stream() .map(this::toDto) .collect(Collectors.toList()); } + @Transactional public SpotDto createSpot(SpotDto spotDto) { Spot spot = spotDto.toEntity(); return toDto(spotRepository.save(spot)); @@ -37,17 +40,24 @@ public SpotDto getSpot(Long id) { Spot spot = spotRepository .findById(id) - .orElseThrow(() -> new EntityNotFoundException("Spot not found")); + .orElseThrow(() -> new EntityNotFoundException("Spot을 찾을 수 없습니다.")); return toDto(spot); } + @Transactional public SpotDto updateSpot(SpotDto spotDto) { Spot spot = spotRepository.save(spotDto.toEntity()); return toDto(spot); } + @Transactional public void deleteSpot(Long id) { - spotRepository.deleteById(id); + Optional spotToDelete = spotRepository.findByIdAndIsDeletedFalse(id); + spotToDelete.ifPresent( + spot -> { + spot.setDeleted(true); + spotRepository.save(spot); + }); } // Service Layer에서 toDto만들어서 매핑시키기 @@ -55,7 +65,7 @@ public SpotDto toDto(Spot spotInStream) { Spot spot = spotRepository .findById(spotInStream.getId()) - .orElseThrow(() -> new EntityNotFoundException("Spot not found")); + .orElseThrow(() -> new EntityNotFoundException("Spot을 찾을 수 없습니다.")); return SpotDto.builder() .id(spot.getId()) @@ -67,6 +77,7 @@ public SpotDto toDto(Spot spotInStream) { .together_order_link(spot.getTogether_order_link()) .pick_up_location(spot.getPick_up_location()) .delivery_status(spot.getDelivery_status()) + .isDeleted(spot.getIsDeleted()) .build(); } } From 219cba3005e5cb34feaa915be21f839f4c56d576 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Wed, 25 Sep 2024 21:41:55 +0900 Subject: [PATCH 05/85] =?UTF-8?q?refactor:=20isDeleted=EA=B0=80=20false?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=83=EB=A7=8C=20=EC=A1=B0=ED=9A=8C=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/repository/SpotRepository.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java b/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java index 13649a86..6971c5c2 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java +++ b/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java @@ -1,13 +1,15 @@ package com.ordertogether.team14_be.spot.repository; import com.ordertogether.team14_be.spot.entity.Spot; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - import java.math.BigDecimal; import java.util.List; +import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; @Repository public interface SpotRepository extends JpaRepository { - List findByLatAndLng(BigDecimal lat, BigDecimal lng); + List findByLatAndLngAndIsDeletedFalse(BigDecimal lat, BigDecimal lng); + + Optional findByIdAndIsDeletedFalse(Long id); } From 8f101f033c533355bc16bedb859cd7157583b13c Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Wed, 25 Sep 2024 21:42:32 +0900 Subject: [PATCH 06/85] =?UTF-8?q?refactor:=20isDeleted=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/dto/SpotDto.java | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java b/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java index 61f6047a..87e803bf 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java +++ b/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java @@ -2,42 +2,45 @@ import com.ordertogether.team14_be.spot.entity.Spot; import jakarta.persistence.Column; +import java.math.BigDecimal; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import java.math.BigDecimal; - @Builder @NoArgsConstructor @AllArgsConstructor @Getter public class SpotDto { - private Long id; - @Column(precision = 10, scale = 8) - private BigDecimal lat; - @Column(precision = 11, scale = 8) - private BigDecimal lng; - private String category; - private String store_name; - private int minimum_order_amount; - private String together_order_link; - private String pick_up_location; - private String delivery_status; + private Long id; + + @Column(precision = 10, scale = 8) + private BigDecimal lat; + + @Column(precision = 11, scale = 8) + private BigDecimal lng; - public Spot toEntity() { - return Spot.builder() - .id(id) - .lat(lat) - .lng(lng) - .category(category) - .store_name(store_name) - .minimum_order_amount(minimum_order_amount) - .together_order_link(together_order_link) - .pick_up_location(pick_up_location) - .delivery_status(delivery_status) - .build(); - } + private String category; + private String store_name; + private int minimum_order_amount; + private String together_order_link; + private String pick_up_location; + private String delivery_status; + private boolean isDeleted; + public Spot toEntity() { + return Spot.builder() + .id(id) + .lat(lat) + .lng(lng) + .category(category) + .store_name(store_name) + .minimum_order_amount(minimum_order_amount) + .together_order_link(together_order_link) + .pick_up_location(pick_up_location) + .delivery_status(delivery_status) + .isDeleted(isDeleted) + .build(); + } } From db397bbe0284307bb0a9b75a201f6667f42f7558 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Wed, 25 Sep 2024 21:43:16 +0900 Subject: [PATCH 07/85] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spot/controller/SpotController.java | 81 +++++++++---------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/controller/SpotController.java b/src/main/java/com/ordertogether/team14_be/spot/controller/SpotController.java index 902a8fa6..95716650 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/controller/SpotController.java +++ b/src/main/java/com/ordertogether/team14_be/spot/controller/SpotController.java @@ -2,52 +2,51 @@ import com.ordertogether.team14_be.spot.dto.SpotDto; import com.ordertogether.team14_be.spot.service.SpotService; +import java.math.BigDecimal; +import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.util.List; - @RestController public class SpotController { - private final SpotService spotService; - - @Autowired - public SpotController(SpotService spotService) { - this.spotService = spotService; - } - - //Spot 전체 조회하기 - @GetMapping("/api/v1/spot/{lat}/{lng}") - public ResponseEntity> getSpot(@PathVariable BigDecimal lat, @PathVariable BigDecimal lng) { - return ResponseEntity.ok(spotService.getSpot(lat, lng)); - } - - //Spot 생성하기 - @PostMapping("/api/v1/spot") - public ResponseEntity createSpot(@RequestBody SpotDto spotDto) { - return ResponseEntity.ok(spotService.createSpot(spotDto)); - } - - //Spot 상세 조회하기 - @GetMapping("/api/v1/spot/{id}") - public ResponseEntity getSpot(@PathVariable Long id) { - return ResponseEntity.ok(spotService.getSpot(id)); - } - - //Spot 수정하기 - @PutMapping("/api/v1/spot") - public ResponseEntity updateSpot(@RequestBody SpotDto spotDto) { - return ResponseEntity.ok(spotService.updateSpot(spotDto)); - } - - //Spot 삭제하기 - @DeleteMapping("/api/v1/spot/{id}") - public ResponseEntity deleteSpot(@PathVariable Long id) { - spotService.deleteSpot(id); - return ResponseEntity.ok().build(); - } - + private final SpotService spotService; + + @Autowired + public SpotController(SpotService spotService) { + this.spotService = spotService; + } + + // Spot 전체 조회하기 + @GetMapping("/api/v1/spot/{lat}/{lng}") + public ResponseEntity> getSpot( + @PathVariable BigDecimal lat, @PathVariable BigDecimal lng) { + return ResponseEntity.ok(spotService.getSpot(lat, lng)); + } + + // Spot 생성하기 + @PostMapping("/api/v1/spot") + public ResponseEntity createSpot(@RequestBody SpotDto spotDto) { + return ResponseEntity.ok(spotService.createSpot(spotDto)); + } + + // Spot 상세 조회하기 + @GetMapping("/api/v1/spot/{id}") + public ResponseEntity getSpot(@PathVariable Long id) { + return ResponseEntity.ok(spotService.getSpot(id)); + } + + // Spot 수정하기 + @PutMapping("/api/v1/spot") + public ResponseEntity updateSpot(@RequestBody SpotDto spotDto) { + return ResponseEntity.ok(spotService.updateSpot(spotDto)); + } + + // Spot 삭제하기 + @DeleteMapping("/api/v1/spot/{id}") + public ResponseEntity deleteSpot(@PathVariable Long id) { + spotService.deleteSpot(id); + return ResponseEntity.ok().build(); + } } From 52456c429087e6407d5fea2a13a060a60503bab3 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Wed, 25 Sep 2024 21:35:28 +0900 Subject: [PATCH 08/85] =?UTF-8?q?feat:=20Soft=20delete=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4=20isDeleted=20=EC=86=8D=EC=84=B1=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/entity/Spot.java | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java b/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java index b5045259..3f8953be 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java +++ b/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java @@ -12,25 +12,31 @@ @AllArgsConstructor @NoArgsConstructor @Getter +@Table(indexes = {@Index(name = "idx_lat_lng", columnList = "lat, lng")}) public class Spot { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; - @Column(precision = 10, scale = 8) - private BigDecimal lat; + @Column(precision = 10, scale = 8) + private BigDecimal lat; - @Column(precision = 11, scale = 8) - private BigDecimal lng; + @Column(precision = 11, scale = 8) + private BigDecimal lng; - private String category; - private String store_name; - private Integer minimum_order_amount; + private String category; + private String store_name; + private Integer minimum_order_amount; - @Lob - @Column(columnDefinition = "MEDIUMTEXT") - private String together_order_link; + @Lob + @Column(columnDefinition = "MEDIUMTEXT") + private String together_order_link; - private String pick_up_location; - private String delivery_status; + private String pick_up_location; + private String delivery_status; + @Builder.Default private Boolean isDeleted = false; + + public void setDeleted(boolean isDeleted) { + this.isDeleted = isDeleted; + } } From e0859ac2d2f8eebc6a450f736d4e81509dc560df Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Wed, 25 Sep 2024 21:41:27 +0900 Subject: [PATCH 09/85] =?UTF-8?q?refactor:=20isDeleted=EA=B0=80=20false?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=83=EB=A7=8C=20=EC=A1=B0=ED=9A=8C=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/service/SpotService.java | 107 ++++++++++-------- 1 file changed, 59 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java b/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java index 10adef37..0c539c19 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java +++ b/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java @@ -4,8 +4,10 @@ import com.ordertogether.team14_be.spot.entity.Spot; import com.ordertogether.team14_be.spot.repository.SpotRepository; import jakarta.persistence.EntityNotFoundException; +import jakarta.transaction.Transactional; import java.math.BigDecimal; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -13,60 +15,69 @@ @Service public class SpotService { - private final SpotRepository spotRepository; + private final SpotRepository spotRepository; - @Autowired - public SpotService(SpotRepository spotRepository) { - this.spotRepository = spotRepository; - } + @Autowired + public SpotService(SpotRepository spotRepository) { + this.spotRepository = spotRepository; + } - // Spot 전체 조회하기 - public List getSpot(BigDecimal lat, BigDecimal lng) { - return spotRepository.findByLatAndLng(lat, lng).stream() - .map(this::toDto) - .collect(Collectors.toList()); - } + // Spot 전체 조회하기 + public List getSpot(BigDecimal lat, BigDecimal lng) { + return spotRepository.findByLatAndLngAndIsDeletedFalse(lat, lng).stream() + .map(this::toDto) + .collect(Collectors.toList()); + } - public SpotDto createSpot(SpotDto spotDto) { - Spot spot = spotDto.toEntity(); - return toDto(spotRepository.save(spot)); - } + @Transactional + public SpotDto createSpot(SpotDto spotDto) { + Spot spot = spotDto.toEntity(); + return toDto(spotRepository.save(spot)); + } - // Spot 상세 조회하기 - public SpotDto getSpot(Long id) { - Spot spot = - spotRepository - .findById(id) - .orElseThrow(() -> new EntityNotFoundException("Spot not found")); - return toDto(spot); - } + // Spot 상세 조회하기 + public SpotDto getSpot(Long id) { + Spot spot = + spotRepository + .findById(id) + .orElseThrow(() -> new EntityNotFoundException("Spot을 찾을 수 없습니다.")); + return toDto(spot); + } - public SpotDto updateSpot(SpotDto spotDto) { - Spot spot = spotRepository.save(spotDto.toEntity()); - return toDto(spot); - } + @Transactional + public SpotDto updateSpot(SpotDto spotDto) { + Spot spot = spotRepository.save(spotDto.toEntity()); + return toDto(spot); + } - public void deleteSpot(Long id) { - spotRepository.deleteById(id); - } + @Transactional + public void deleteSpot(Long id) { + Optional spotToDelete = spotRepository.findByIdAndIsDeletedFalse(id); + spotToDelete.ifPresent( + spot -> { + spot.setDeleted(true); + spotRepository.save(spot); + }); + } - // Service Layer에서 toDto만들어서 매핑시키기 - public SpotDto toDto(Spot spotInStream) { - Spot spot = - spotRepository - .findById(spotInStream.getId()) - .orElseThrow(() -> new EntityNotFoundException("Spot not found")); + // Service Layer에서 toDto만들어서 매핑시키기 + public SpotDto toDto(Spot spotInStream) { + Spot spot = + spotRepository + .findById(spotInStream.getId()) + .orElseThrow(() -> new EntityNotFoundException("Spot을 찾을 수 없습니다.")); - return SpotDto.builder() - .id(spot.getId()) - .lat(spot.getLat()) - .lng(spot.getLng()) - .category(spot.getCategory()) - .store_name(spot.getStore_name()) - .minimum_order_amount(spot.getMinimum_order_amount()) - .together_order_link(spot.getTogether_order_link()) - .pick_up_location(spot.getPick_up_location()) - .delivery_status(spot.getDelivery_status()) - .build(); - } + return SpotDto.builder() + .id(spot.getId()) + .lat(spot.getLat()) + .lng(spot.getLng()) + .category(spot.getCategory()) + .store_name(spot.getStore_name()) + .minimum_order_amount(spot.getMinimum_order_amount()) + .together_order_link(spot.getTogether_order_link()) + .pick_up_location(spot.getPick_up_location()) + .delivery_status(spot.getDelivery_status()) + .isDeleted(spot.getIsDeleted()) + .build(); + } } From 01a71b2f49a904ad2d80bd5ca40e7837f84ebd92 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Wed, 25 Sep 2024 21:41:55 +0900 Subject: [PATCH 10/85] =?UTF-8?q?refactor:=20isDeleted=EA=B0=80=20false?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=83=EB=A7=8C=20=EC=A1=B0=ED=9A=8C=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/repository/SpotRepository.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java b/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java index aa11f75c..6971c5c2 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java +++ b/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java @@ -3,10 +3,13 @@ import com.ordertogether.team14_be.spot.entity.Spot; import java.math.BigDecimal; import java.util.List; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface SpotRepository extends JpaRepository { - List findByLatAndLng(BigDecimal lat, BigDecimal lng); + List findByLatAndLngAndIsDeletedFalse(BigDecimal lat, BigDecimal lng); + + Optional findByIdAndIsDeletedFalse(Long id); } From f93760e77ed11956bd6014e2617f4e771e212db2 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Wed, 25 Sep 2024 21:42:32 +0900 Subject: [PATCH 11/85] =?UTF-8?q?refactor:=20isDeleted=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/dto/SpotDto.java | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java b/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java index e4deb6bb..87e803bf 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java +++ b/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java @@ -13,32 +13,34 @@ @AllArgsConstructor @Getter public class SpotDto { - private Long id; + private Long id; - @Column(precision = 10, scale = 8) - private BigDecimal lat; + @Column(precision = 10, scale = 8) + private BigDecimal lat; - @Column(precision = 11, scale = 8) - private BigDecimal lng; + @Column(precision = 11, scale = 8) + private BigDecimal lng; - private String category; - private String store_name; - private int minimum_order_amount; - private String together_order_link; - private String pick_up_location; - private String delivery_status; + private String category; + private String store_name; + private int minimum_order_amount; + private String together_order_link; + private String pick_up_location; + private String delivery_status; + private boolean isDeleted; - public Spot toEntity() { - return Spot.builder() - .id(id) - .lat(lat) - .lng(lng) - .category(category) - .store_name(store_name) - .minimum_order_amount(minimum_order_amount) - .together_order_link(together_order_link) - .pick_up_location(pick_up_location) - .delivery_status(delivery_status) - .build(); - } + public Spot toEntity() { + return Spot.builder() + .id(id) + .lat(lat) + .lng(lng) + .category(category) + .store_name(store_name) + .minimum_order_amount(minimum_order_amount) + .together_order_link(together_order_link) + .pick_up_location(pick_up_location) + .delivery_status(delivery_status) + .isDeleted(isDeleted) + .build(); + } } From 5b815d693025a2580083128c8349d3e5e6292f40 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 26 Sep 2024 12:53:52 +0900 Subject: [PATCH 12/85] =?UTF-8?q?refactor:=20BaseEntity=20=EC=83=81?= =?UTF-8?q?=EC=86=8D=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/entity/Spot.java | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java b/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java index 3f8953be..d6e7fd2f 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java +++ b/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java @@ -1,42 +1,41 @@ package com.ordertogether.team14_be.spot.entity; +import com.ordertogether.team14_be.payment.domain.BaseEntity; import jakarta.persistence.*; + import java.math.BigDecimal; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; + +import lombok.*; +import lombok.experimental.SuperBuilder; @Entity -@Builder -@AllArgsConstructor +@SuperBuilder // 상속받은 필드도 빌더에서 사용 @NoArgsConstructor +@AllArgsConstructor(access = AccessLevel.PROTECTED) @Getter @Table(indexes = {@Index(name = "idx_lat_lng", columnList = "lat, lng")}) -public class Spot { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; +public class Spot extends BaseEntity { - @Column(precision = 10, scale = 8) - private BigDecimal lat; + @Column(precision = 10, scale = 8) + private BigDecimal lat; - @Column(precision = 11, scale = 8) - private BigDecimal lng; + @Column(precision = 11, scale = 8) + private BigDecimal lng; - private String category; - private String store_name; - private Integer minimum_order_amount; + private String category; + private String store_name; + private Integer minimum_order_amount; - @Lob - @Column(columnDefinition = "MEDIUMTEXT") - private String together_order_link; + @Lob + @Column(columnDefinition = "MEDIUMTEXT") + private String together_order_link; - private String pick_up_location; - private String delivery_status; - @Builder.Default private Boolean isDeleted = false; + private String pick_up_location; + private String delivery_status; + @Builder.Default + private Boolean isDeleted = false; - public void setDeleted(boolean isDeleted) { - this.isDeleted = isDeleted; - } + public void setDeleted(boolean isDeleted) { + this.isDeleted = isDeleted; + } } From 4bb4227845b902b9e760dc6df49362004227b557 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 26 Sep 2024 12:54:46 +0900 Subject: [PATCH 13/85] =?UTF-8?q?refactor:=20createdAt,=20updateAt=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/dto/SpotDto.java | 76 ++++++++++--------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java b/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java index 87e803bf..a1a6cb11 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java +++ b/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java @@ -2,45 +2,49 @@ import com.ordertogether.team14_be.spot.entity.Spot; import jakarta.persistence.Column; + import java.math.BigDecimal; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import java.time.LocalDateTime; + +import lombok.*; @Builder -@NoArgsConstructor -@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PROTECTED) @Getter public class SpotDto { - private Long id; - - @Column(precision = 10, scale = 8) - private BigDecimal lat; - - @Column(precision = 11, scale = 8) - private BigDecimal lng; - - private String category; - private String store_name; - private int minimum_order_amount; - private String together_order_link; - private String pick_up_location; - private String delivery_status; - private boolean isDeleted; - - public Spot toEntity() { - return Spot.builder() - .id(id) - .lat(lat) - .lng(lng) - .category(category) - .store_name(store_name) - .minimum_order_amount(minimum_order_amount) - .together_order_link(together_order_link) - .pick_up_location(pick_up_location) - .delivery_status(delivery_status) - .isDeleted(isDeleted) - .build(); - } + private Long id; + + @Column(precision = 10, scale = 8) + private BigDecimal lat; + + @Column(precision = 11, scale = 8) + private BigDecimal lng; + + private String category; + private String store_name; + private int minimum_order_amount; + private String together_order_link; + private String pick_up_location; + private String delivery_status; + private boolean isDeleted; + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + + public Spot toEntity() { + return Spot.builder() + .id(id) + .lat(lat) + .lng(lng) + .category(category) + .store_name(store_name) + .minimum_order_amount(minimum_order_amount) + .together_order_link(together_order_link) + .pick_up_location(pick_up_location) + .delivery_status(delivery_status) + .isDeleted(isDeleted) + .createdAt(createdAt) + .updatedAt(updatedAt) + .build(); + } } From c377286f7b848ee81b6071443badc7f0e3dc7b2f Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 26 Sep 2024 15:11:12 +0900 Subject: [PATCH 14/85] =?UTF-8?q?feat:=20ENUM=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=EC=9D=98=20category=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/enums/Category.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/spot/enums/Category.java diff --git a/src/main/java/com/ordertogether/team14_be/spot/enums/Category.java b/src/main/java/com/ordertogether/team14_be/spot/enums/Category.java new file mode 100644 index 00000000..1c41d4a3 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/spot/enums/Category.java @@ -0,0 +1,36 @@ +package com.ordertogether.team14_be.spot.enums; + +import com.ordertogether.team14_be.spot.converter.AbstractCodedEnumConverter; +import com.ordertogether.team14_be.spot.converter.CodedEnum; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public enum Category implements CodedEnum { + JOKBAL_BOSSAM("족발, 보쌈"), + JAPANESE_FOOD("돈까스, 회, 일식"), + MEAT("고기"), + KOREAN_STEW("찜, 탕, 찌개"), + WESTERN_STYLE("양식"), + CHINESE_FOOD("중식"), + ASIAN("아시안"), + CHICKEN("치킨"), + CARBOHYDRATE("백반, 죽, 국수"), + BURGER("버거"), + K_SNACK_FOOD("분식"), + CAFE("카페, 디저트"); + + private final String category; + + public String getCode() { + return category; + } + + @jakarta.persistence.Converter(autoApply = true) + static class Converter extends AbstractCodedEnumConverter { + public Converter() { + super(Category.class); + } + } +} From 213e0cf702c4c63b373c229fd8863e7990cf11ae Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 26 Sep 2024 15:12:00 +0900 Subject: [PATCH 15/85] =?UTF-8?q?refactor:=20category=EC=9D=98=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=EC=9D=84=20Category(ENUM=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4)=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/dto/SpotDto.java | 71 +++++++++---------- .../team14_be/spot/entity/Spot.java | 36 +++++----- 2 files changed, 52 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java b/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java index a1a6cb11..6f012336 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java +++ b/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java @@ -1,11 +1,10 @@ package com.ordertogether.team14_be.spot.dto; import com.ordertogether.team14_be.spot.entity.Spot; +import com.ordertogether.team14_be.spot.enums.Category; import jakarta.persistence.Column; - import java.math.BigDecimal; import java.time.LocalDateTime; - import lombok.*; @Builder @@ -13,38 +12,38 @@ @AllArgsConstructor(access = AccessLevel.PROTECTED) @Getter public class SpotDto { - private Long id; - - @Column(precision = 10, scale = 8) - private BigDecimal lat; - - @Column(precision = 11, scale = 8) - private BigDecimal lng; - - private String category; - private String store_name; - private int minimum_order_amount; - private String together_order_link; - private String pick_up_location; - private String delivery_status; - private boolean isDeleted; - private LocalDateTime createdAt; - private LocalDateTime updatedAt; - - public Spot toEntity() { - return Spot.builder() - .id(id) - .lat(lat) - .lng(lng) - .category(category) - .store_name(store_name) - .minimum_order_amount(minimum_order_amount) - .together_order_link(together_order_link) - .pick_up_location(pick_up_location) - .delivery_status(delivery_status) - .isDeleted(isDeleted) - .createdAt(createdAt) - .updatedAt(updatedAt) - .build(); - } + private Long id; + + @Column(precision = 10, scale = 8) + private BigDecimal lat; + + @Column(precision = 11, scale = 8) + private BigDecimal lng; + + private Category category; + private String store_name; + private int minimum_order_amount; + private String together_order_link; + private String pick_up_location; + private String delivery_status; + private boolean isDeleted; + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + + public Spot toEntity() { + return Spot.builder() + .id(id) + .lat(lat) + .lng(lng) + .category(category) + .store_name(store_name) + .minimum_order_amount(minimum_order_amount) + .together_order_link(together_order_link) + .pick_up_location(pick_up_location) + .delivery_status(delivery_status) + .isDeleted(isDeleted) + .createdAt(createdAt) + .updatedAt(updatedAt) + .build(); + } } diff --git a/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java b/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java index d6e7fd2f..b341cf91 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java +++ b/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java @@ -1,10 +1,9 @@ package com.ordertogether.team14_be.spot.entity; import com.ordertogether.team14_be.payment.domain.BaseEntity; +import com.ordertogether.team14_be.spot.enums.Category; import jakarta.persistence.*; - import java.math.BigDecimal; - import lombok.*; import lombok.experimental.SuperBuilder; @@ -16,26 +15,25 @@ @Table(indexes = {@Index(name = "idx_lat_lng", columnList = "lat, lng")}) public class Spot extends BaseEntity { - @Column(precision = 10, scale = 8) - private BigDecimal lat; + @Column(precision = 10, scale = 8) + private BigDecimal lat; - @Column(precision = 11, scale = 8) - private BigDecimal lng; + @Column(precision = 11, scale = 8) + private BigDecimal lng; - private String category; - private String store_name; - private Integer minimum_order_amount; + private Category category; + private String store_name; + private Integer minimum_order_amount; - @Lob - @Column(columnDefinition = "MEDIUMTEXT") - private String together_order_link; + @Lob + @Column(columnDefinition = "MEDIUMTEXT") + private String together_order_link; - private String pick_up_location; - private String delivery_status; - @Builder.Default - private Boolean isDeleted = false; + private String pick_up_location; + private String delivery_status; + @Builder.Default private Boolean isDeleted = false; - public void setDeleted(boolean isDeleted) { - this.isDeleted = isDeleted; - } + public void setDeleted(boolean isDeleted) { + this.isDeleted = isDeleted; + } } From 041ae28a4072b7b408843148cbf1e41dff8d4bc8 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 26 Sep 2024 15:15:10 +0900 Subject: [PATCH 16/85] =?UTF-8?q?feat:=20ENUM=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EC=9D=98=20converter=EC=97=90=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20CodedEnum=20=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ordertogether/team14_be/spot/converter/CodedEnum.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/spot/converter/CodedEnum.java diff --git a/src/main/java/com/ordertogether/team14_be/spot/converter/CodedEnum.java b/src/main/java/com/ordertogether/team14_be/spot/converter/CodedEnum.java new file mode 100644 index 00000000..aed91862 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/spot/converter/CodedEnum.java @@ -0,0 +1,5 @@ +package com.ordertogether.team14_be.spot.converter; + +public interface CodedEnum { + T getCode(); +} From 1901d03981c545ffbe34d5a8b9ae94026e9c18fa Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 26 Sep 2024 15:15:30 +0900 Subject: [PATCH 17/85] =?UTF-8?q?feat:=20ENUM=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EC=9D=98=20converter=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/AbstractCodedEnumConverter.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java diff --git a/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java b/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java new file mode 100644 index 00000000..552f64b5 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java @@ -0,0 +1,35 @@ +package com.ordertogether.team14_be.spot.converter; + +import jakarta.persistence.AttributeConverter; +import java.util.Arrays; +import java.util.Objects; + +public class AbstractCodedEnumConverter & CodedEnum, E> + implements AttributeConverter { + + private final Class clazz; + + public AbstractCodedEnumConverter(Class clazz) { + this.clazz = clazz; + } + + @Override + public E convertToDatabaseColumn( + T attribute) { // Converts the value stored in the entity attribute into the data + // representation to be stored in the database. + return attribute.getCode(); + } + + @Override + public T convertToEntityAttribute( + E dbData) { // Converts the data stored in the database column into the value to be stored + // in the entity attribute. + if (Objects.isNull(dbData)) { + return null; + } + return Arrays.stream(clazz.getEnumConstants()) + .filter(e -> e.getCode().equals(dbData)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("Unknown code: " + dbData)); + } +} From 3acc06606d7d49f6b84f68cc4b346c9df88349f4 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 26 Sep 2024 16:02:16 +0900 Subject: [PATCH 18/85] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/AbstractCodedEnumConverter.java | 46 +++---- .../team14_be/spot/converter/CodedEnum.java | 2 +- .../team14_be/spot/enums/Category.java | 44 +++---- .../spot/repository/SpotRepository.java | 4 +- .../team14_be/spot/service/SpotService.java | 114 +++++++++--------- 5 files changed, 105 insertions(+), 105 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java b/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java index 552f64b5..56412030 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java +++ b/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java @@ -5,31 +5,31 @@ import java.util.Objects; public class AbstractCodedEnumConverter & CodedEnum, E> - implements AttributeConverter { + implements AttributeConverter { - private final Class clazz; + private final Class clazz; - public AbstractCodedEnumConverter(Class clazz) { - this.clazz = clazz; - } + public AbstractCodedEnumConverter(Class clazz) { + this.clazz = clazz; + } - @Override - public E convertToDatabaseColumn( - T attribute) { // Converts the value stored in the entity attribute into the data - // representation to be stored in the database. - return attribute.getCode(); - } + @Override + public E convertToDatabaseColumn( + T attribute) { // Converts the value stored in the entity attribute into the data + // representation to be stored in the database. + return attribute.getCode(); + } - @Override - public T convertToEntityAttribute( - E dbData) { // Converts the data stored in the database column into the value to be stored - // in the entity attribute. - if (Objects.isNull(dbData)) { - return null; - } - return Arrays.stream(clazz.getEnumConstants()) - .filter(e -> e.getCode().equals(dbData)) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException("Unknown code: " + dbData)); - } + @Override + public T convertToEntityAttribute( + E dbData) { // Converts the data stored in the database column into the value to be stored + // in the entity attribute. + if (Objects.isNull(dbData)) { + return null; + } + return Arrays.stream(clazz.getEnumConstants()) + .filter(e -> e.getCode().equals(dbData)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("Unknown code: " + dbData)); + } } diff --git a/src/main/java/com/ordertogether/team14_be/spot/converter/CodedEnum.java b/src/main/java/com/ordertogether/team14_be/spot/converter/CodedEnum.java index aed91862..57f96996 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/converter/CodedEnum.java +++ b/src/main/java/com/ordertogether/team14_be/spot/converter/CodedEnum.java @@ -1,5 +1,5 @@ package com.ordertogether.team14_be.spot.converter; public interface CodedEnum { - T getCode(); + T getCode(); } diff --git a/src/main/java/com/ordertogether/team14_be/spot/enums/Category.java b/src/main/java/com/ordertogether/team14_be/spot/enums/Category.java index 1c41d4a3..5c26d0bc 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/enums/Category.java +++ b/src/main/java/com/ordertogether/team14_be/spot/enums/Category.java @@ -8,29 +8,29 @@ @AllArgsConstructor @Getter public enum Category implements CodedEnum { - JOKBAL_BOSSAM("족발, 보쌈"), - JAPANESE_FOOD("돈까스, 회, 일식"), - MEAT("고기"), - KOREAN_STEW("찜, 탕, 찌개"), - WESTERN_STYLE("양식"), - CHINESE_FOOD("중식"), - ASIAN("아시안"), - CHICKEN("치킨"), - CARBOHYDRATE("백반, 죽, 국수"), - BURGER("버거"), - K_SNACK_FOOD("분식"), - CAFE("카페, 디저트"); + JOKBAL_BOSSAM("족발, 보쌈"), + JAPANESE_FOOD("돈까스, 회, 일식"), + MEAT("고기"), + KOREAN_STEW("찜, 탕, 찌개"), + WESTERN_STYLE("양식"), + CHINESE_FOOD("중식"), + ASIAN("아시안"), + CHICKEN("치킨"), + CARBOHYDRATE("백반, 죽, 국수"), + BURGER("버거"), + K_SNACK_FOOD("분식"), + CAFE("카페, 디저트"); - private final String category; + private final String category; - public String getCode() { - return category; - } + public String getCode() { + return category; + } - @jakarta.persistence.Converter(autoApply = true) - static class Converter extends AbstractCodedEnumConverter { - public Converter() { - super(Category.class); - } - } + @jakarta.persistence.Converter(autoApply = true) + static class Converter extends AbstractCodedEnumConverter { + public Converter() { + super(Category.class); + } + } } diff --git a/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java b/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java index 6971c5c2..706897b5 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java +++ b/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java @@ -9,7 +9,7 @@ @Repository public interface SpotRepository extends JpaRepository { - List findByLatAndLngAndIsDeletedFalse(BigDecimal lat, BigDecimal lng); + List findByLatAndLngAndIsDeletedFalse(BigDecimal lat, BigDecimal lng); - Optional findByIdAndIsDeletedFalse(Long id); + Optional findByIdAndIsDeletedFalse(Long id); } diff --git a/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java b/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java index 0c539c19..436900ce 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java +++ b/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java @@ -15,69 +15,69 @@ @Service public class SpotService { - private final SpotRepository spotRepository; + private final SpotRepository spotRepository; - @Autowired - public SpotService(SpotRepository spotRepository) { - this.spotRepository = spotRepository; - } + @Autowired + public SpotService(SpotRepository spotRepository) { + this.spotRepository = spotRepository; + } - // Spot 전체 조회하기 - public List getSpot(BigDecimal lat, BigDecimal lng) { - return spotRepository.findByLatAndLngAndIsDeletedFalse(lat, lng).stream() - .map(this::toDto) - .collect(Collectors.toList()); - } + // Spot 전체 조회하기 + public List getSpot(BigDecimal lat, BigDecimal lng) { + return spotRepository.findByLatAndLngAndIsDeletedFalse(lat, lng).stream() + .map(this::toDto) + .collect(Collectors.toList()); + } - @Transactional - public SpotDto createSpot(SpotDto spotDto) { - Spot spot = spotDto.toEntity(); - return toDto(spotRepository.save(spot)); - } + @Transactional + public SpotDto createSpot(SpotDto spotDto) { + Spot spot = spotDto.toEntity(); + return toDto(spotRepository.save(spot)); + } - // Spot 상세 조회하기 - public SpotDto getSpot(Long id) { - Spot spot = - spotRepository - .findById(id) - .orElseThrow(() -> new EntityNotFoundException("Spot을 찾을 수 없습니다.")); - return toDto(spot); - } + // Spot 상세 조회하기 + public SpotDto getSpot(Long id) { + Spot spot = + spotRepository + .findById(id) + .orElseThrow(() -> new EntityNotFoundException("Spot을 찾을 수 없습니다.")); + return toDto(spot); + } - @Transactional - public SpotDto updateSpot(SpotDto spotDto) { - Spot spot = spotRepository.save(spotDto.toEntity()); - return toDto(spot); - } + @Transactional + public SpotDto updateSpot(SpotDto spotDto) { + Spot spot = spotRepository.save(spotDto.toEntity()); + return toDto(spot); + } - @Transactional - public void deleteSpot(Long id) { - Optional spotToDelete = spotRepository.findByIdAndIsDeletedFalse(id); - spotToDelete.ifPresent( - spot -> { - spot.setDeleted(true); - spotRepository.save(spot); - }); - } + @Transactional + public void deleteSpot(Long id) { + Optional spotToDelete = spotRepository.findByIdAndIsDeletedFalse(id); + spotToDelete.ifPresent( + spot -> { + spot.setDeleted(true); + spotRepository.save(spot); + }); + } - // Service Layer에서 toDto만들어서 매핑시키기 - public SpotDto toDto(Spot spotInStream) { - Spot spot = - spotRepository - .findById(spotInStream.getId()) - .orElseThrow(() -> new EntityNotFoundException("Spot을 찾을 수 없습니다.")); + // Service Layer에서 toDto만들어서 매핑시키기 + public SpotDto toDto(Spot spotInStream) { + Spot spot = + spotRepository + .findById(spotInStream.getId()) + .orElseThrow(() -> new EntityNotFoundException("Spot을 찾을 수 없습니다.")); - return SpotDto.builder() - .id(spot.getId()) - .lat(spot.getLat()) - .lng(spot.getLng()) - .category(spot.getCategory()) - .store_name(spot.getStore_name()) - .minimum_order_amount(spot.getMinimum_order_amount()) - .together_order_link(spot.getTogether_order_link()) - .pick_up_location(spot.getPick_up_location()) - .delivery_status(spot.getDelivery_status()) - .isDeleted(spot.getIsDeleted()) - .build(); - } + return SpotDto.builder() + .id(spot.getId()) + .lat(spot.getLat()) + .lng(spot.getLng()) + .category(spot.getCategory()) + .store_name(spot.getStore_name()) + .minimum_order_amount(spot.getMinimum_order_amount()) + .together_order_link(spot.getTogether_order_link()) + .pick_up_location(spot.getPick_up_location()) + .delivery_status(spot.getDelivery_status()) + .isDeleted(spot.getIsDeleted()) + .build(); + } } From bbe7d326dc2b52caa6b326eebac18a0ecd1e0025 Mon Sep 17 00:00:00 2001 From: rbm0524 Date: Thu, 26 Sep 2024 21:31:08 +0900 Subject: [PATCH 19/85] =?UTF-8?q?style:=20camel=20case=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/dto/SpotDto.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java b/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java index 22ecc53d..4a988d84 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java +++ b/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java @@ -21,11 +21,11 @@ public class SpotDto { private BigDecimal lng; private Category category; - private String store_name; - private int minimum_order_amount; - private String together_order_link; - private String pick_up_location; - private String delivery_status; + private String storeName; + private int minimumOrderAmount; + private String togetherOrderLink; + private String pickUpLocation; + private String deliveryStatus; private boolean isDeleted; private LocalDateTime createdAt; private LocalDateTime modifiedAt; @@ -38,11 +38,11 @@ public Spot toEntity() { .lat(lat) .lng(lng) .category(category) - .store_name(store_name) - .minimum_order_amount(minimum_order_amount) - .together_order_link(together_order_link) - .pick_up_location(pick_up_location) - .delivery_status(delivery_status) + .storeName(storeName) + .minimumOrderAmount(minimumOrderAmount) + .togetherOrderLink(togetherOrderLink) + .pickUpLocation(pickUpLocation) + .deliveryStatus(deliveryStatus) .isDeleted(isDeleted) .createdAt(createdAt) .modifiedAt(modifiedAt) From fa8a0e531fc9f891895416f431ddbe2fae33fa11 Mon Sep 17 00:00:00 2001 From: rbm0524 Date: Thu, 26 Sep 2024 21:36:24 +0900 Subject: [PATCH 20/85] =?UTF-8?q?refactor:=20setter=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=ED=95=98=EB=8D=98=20isDeleted=EB=A5=BC=20delete?= =?UTF-8?q?=EC=99=80=20restore=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/entity/Spot.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java b/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java index fa98f7f7..a658376c 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java +++ b/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java @@ -6,6 +6,7 @@ import java.math.BigDecimal; import lombok.*; import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.DynamicUpdate; @Entity @SuperBuilder // 상속받은 필드도 빌더에서 사용 @@ -13,6 +14,7 @@ @AllArgsConstructor(access = AccessLevel.PROTECTED) @Getter @Table(indexes = {@Index(name = "idx_lat_lng", columnList = "lat, lng")}) +@DynamicUpdate // 변경한 필드만 대응 public class Spot extends BaseEntity { @Id @@ -26,18 +28,22 @@ public class Spot extends BaseEntity { private BigDecimal lng; private Category category; - private String store_name; - private Integer minimum_order_amount; + private String storeName; + private Integer minimumOrderAmount; @Lob @Column(columnDefinition = "MEDIUMTEXT") - private String together_order_link; + private String togetherOrderLink; - private String pick_up_location; - private String delivery_status; + private String pickUpLocation; + private String deliveryStatus; @Builder.Default private Boolean isDeleted = false; - public void setDeleted(boolean isDeleted) { - this.isDeleted = isDeleted; + public void delete() { + this.isDeleted = true; + } + + public void restore() { + this.isDeleted = false; } } From 3cab244acd0a5dd57d75071e0defdee9aa877601 Mon Sep 17 00:00:00 2001 From: rbm0524 Date: Thu, 26 Sep 2024 21:36:46 +0900 Subject: [PATCH 21/85] =?UTF-8?q?refactor:=20dirty=20checking=ED=95=98?= =?UTF-8?q?=EB=AF=80=EB=A1=9C=20save=EA=B0=80=20=ED=95=84=EC=9A=94=20?= =?UTF-8?q?=EC=97=86=EC=96=B4=EC=84=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/service/SpotService.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java b/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java index 436900ce..09982254 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java +++ b/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java @@ -54,10 +54,7 @@ public SpotDto updateSpot(SpotDto spotDto) { public void deleteSpot(Long id) { Optional spotToDelete = spotRepository.findByIdAndIsDeletedFalse(id); spotToDelete.ifPresent( - spot -> { - spot.setDeleted(true); - spotRepository.save(spot); - }); + Spot::delete); } // Service Layer에서 toDto만들어서 매핑시키기 @@ -72,11 +69,11 @@ public SpotDto toDto(Spot spotInStream) { .lat(spot.getLat()) .lng(spot.getLng()) .category(spot.getCategory()) - .store_name(spot.getStore_name()) - .minimum_order_amount(spot.getMinimum_order_amount()) - .together_order_link(spot.getTogether_order_link()) - .pick_up_location(spot.getPick_up_location()) - .delivery_status(spot.getDelivery_status()) + .storeName(spot.getStoreName()) + .minimumOrderAmount(spot.getMinimumOrderAmount()) + .togetherOrderLink(spot.getTogetherOrderLink()) + .pickUpLocation(spot.getPickUpLocation()) + .deliveryStatus(spot.getDeliveryStatus()) .isDeleted(spot.getIsDeleted()) .build(); } From e8ce550b1fd5b37a4589bad32837e4ac2598774d Mon Sep 17 00:00:00 2001 From: rbm0524 Date: Thu, 26 Sep 2024 21:37:12 +0900 Subject: [PATCH 22/85] =?UTF-8?q?fix:=20Converter=20=EC=96=B4=EB=85=B8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EC=85=98=20=EB=B6=99=EC=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/converter/AbstractCodedEnumConverter.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java b/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java index 56412030..f4dc9b85 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java +++ b/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java @@ -1,9 +1,12 @@ package com.ordertogether.team14_be.spot.converter; import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + import java.util.Arrays; import java.util.Objects; +@Converter public class AbstractCodedEnumConverter & CodedEnum, E> implements AttributeConverter { From 8b69db5d34c3c3002d5e6d6a36041e7dc5a1470b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:26:33 +0900 Subject: [PATCH 23/85] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EC=97=90=20description=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../payment/domain/PaymentOrderStatus.java | 9 --------- .../team14_be/payment/domain/PaymentStatus.java | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) delete mode 100644 src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrderStatus.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/domain/PaymentStatus.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrderStatus.java b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrderStatus.java deleted file mode 100644 index f72b0506..00000000 --- a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrderStatus.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.ordertogether.team14_be.payment.domain; - -/** 결제 상태 */ -public enum PaymentOrderStatus { - READY, - EXECUTING, - SUCCESS, - FAIL; -} diff --git a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentStatus.java b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentStatus.java new file mode 100644 index 00000000..001acfaa --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentStatus.java @@ -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; +} From f9b2f928bca8d7fca5ed5ebca36c6d9f3c4eef00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:28:09 +0900 Subject: [PATCH 24/85] =?UTF-8?q?feat:=20Entity=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jpa/entity/PaymentEventEntity.java | 49 +++++++++++++++++++ .../jpa/entity/PaymentOrderEntity.java | 42 ++++++++++++++++ .../persistence/jpa/entity/ProductEntity.java | 36 ++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentEventEntity.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentOrderEntity.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/ProductEntity.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentEventEntity.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentEventEntity.java new file mode 100644 index 00000000..6a64f56d --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentEventEntity.java @@ -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; +} diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentOrderEntity.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentOrderEntity.java new file mode 100644 index 00000000..d86a1bf8 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentOrderEntity.java @@ -0,0 +1,42 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.entity; + +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 jakarta.persistence.Table; +import java.math.BigDecimal; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.SuperBuilder; + +@Entity +@Getter +@SuperBuilder +@ToString +@Table(name = "payment_order") +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class PaymentOrderEntity extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private Long productId; + + @Column(nullable = false) + private String orderId; + + @Column(nullable = false) + private String orderName; + + @Column(nullable = false, precision = 10, scale = 2) + private BigDecimal amount; // 결제 금액 +} diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/ProductEntity.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/ProductEntity.java new file mode 100644 index 00000000..f149e8bf --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/ProductEntity.java @@ -0,0 +1,36 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.entity; + +import com.ordertogether.team14_be.common.persistence.entity.BaseEntity; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import java.math.BigDecimal; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.SuperBuilder; + +@Entity +@Getter +@SuperBuilder +@ToString +@Table(name = "product") +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class ProductEntity extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String name; + + @Column(nullable = false) + private BigDecimal price; +} From 13fdf6908ba69dceefd42971cc397bd3137c7969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:28:59 +0900 Subject: [PATCH 25/85] =?UTF-8?q?feat:=20Domain=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../payment/domain/PaymentEvent.java | 39 ++++++------- .../payment/domain/PaymentOrder.java | 55 ++++++++----------- .../team14_be/payment/domain/Product.java | 22 +------- 3 files changed, 41 insertions(+), 75 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentEvent.java b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentEvent.java index 69dc6892..06333daa 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentEvent.java +++ b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentEvent.java @@ -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 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(); + } } diff --git a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java index b252ff86..599d7061 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java +++ b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java @@ -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; // 판매자 식별자 - - @Column(nullable = false) private Long 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()); + } } diff --git a/src/main/java/com/ordertogether/team14_be/payment/domain/Product.java b/src/main/java/com/ordertogether/team14_be/payment/domain/Product.java index 641fe49e..3cd03891 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/domain/Product.java +++ b/src/main/java/com/ordertogether/team14_be/payment/domain/Product.java @@ -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; } From f62e7880aa2117e470670c69b4737c924deb3c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:29:51 +0900 Subject: [PATCH 26/85] =?UTF-8?q?feat:=20Mapper=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jpa/mapper/PaymentEventMapper.java | 31 +++++++++++++++++ .../jpa/mapper/PaymentOrderMapper.java | 34 +++++++++++++++++++ .../persistence/jpa/mapper/ProductMapper.java | 25 ++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentEventMapper.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentOrderMapper.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/ProductMapper.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentEventMapper.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentEventMapper.java new file mode 100644 index 00000000..db590005 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentEventMapper.java @@ -0,0 +1,31 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.mapper; + +import com.ordertogether.team14_be.payment.domain.PaymentEvent; +import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentEventEntity; +import lombok.experimental.UtilityClass; + +@UtilityClass +public final class PaymentEventMapper { + + public static PaymentEventEntity mapToEntity(PaymentEvent domain) { + return PaymentEventEntity.builder() + .id(domain.getId()) + .buyerId(domain.getBuyerId()) + .orderId(domain.getOrderId()) + .orderName(domain.getOrderName()) + .paymentKey(domain.getPaymentKey()) + .paymentStatus(domain.getPaymentStatus()) + .build(); + } + + public static PaymentEvent mapToDomain(PaymentEventEntity entity) { + return PaymentEvent.builder() + .id(entity.getId()) + .buyerId(entity.getBuyerId()) + .orderId(entity.getOrderId()) + .orderName(entity.getOrderName()) + .paymentKey(entity.getPaymentKey()) + .paymentStatus(entity.getPaymentStatus()) + .build(); + } +} diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentOrderMapper.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentOrderMapper.java new file mode 100644 index 00000000..9331c173 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentOrderMapper.java @@ -0,0 +1,34 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.mapper; + +import com.ordertogether.team14_be.payment.domain.PaymentOrder; +import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentOrderEntity; +import java.util.List; +import lombok.experimental.UtilityClass; + +@UtilityClass +public final class PaymentOrderMapper { + + public static PaymentOrderEntity mapToEntity(PaymentOrder domain) { + return PaymentOrderEntity.builder() + .id(domain.getId()) + .productId(domain.getProductId()) + .orderId(domain.getOrderId()) + .orderName(domain.getOrderName()) + .amount(domain.getAmount()) + .build(); + } + + public static PaymentOrder mapToDomain(PaymentOrderEntity entity) { + return PaymentOrder.builder() + .id(entity.getId()) + .productId(entity.getProductId()) + .orderId(entity.getOrderId()) + .orderName(entity.getOrderName()) + .amount(entity.getAmount()) + .build(); + } + + public static List mapToDomain(List entities) { + return entities.stream().map(PaymentOrderMapper::mapToDomain).toList(); + } +} diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/ProductMapper.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/ProductMapper.java new file mode 100644 index 00000000..c7313d83 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/ProductMapper.java @@ -0,0 +1,25 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.mapper; + +import com.ordertogether.team14_be.payment.domain.Product; +import com.ordertogether.team14_be.payment.persistence.jpa.entity.ProductEntity; +import lombok.experimental.UtilityClass; + +@UtilityClass +public final class ProductMapper { + + public static ProductEntity mapToEntity(Product domain) { + return ProductEntity.builder() + .id(domain.getId()) + .name(domain.getName()) + .price(domain.getPrice()) + .build(); + } + + public static Product mapToDomain(ProductEntity entity) { + return Product.builder() + .id(entity.getId()) + .name(entity.getName()) + .price(entity.getPrice()) + .build(); + } +} From 7f22fcf35f2d9ec37d7e86c8e811c2ef7fac57f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:30:45 +0900 Subject: [PATCH 27/85] =?UTF-8?q?feat:=20ProductRepository=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ProductRepository.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/repository/ProductRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/ProductRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/ProductRepository.java new file mode 100644 index 00000000..e3364f7c --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/ProductRepository.java @@ -0,0 +1,16 @@ +package com.ordertogether.team14_be.payment.persistence.repository; + +import com.ordertogether.team14_be.payment.domain.Product; +import java.util.List; +import java.util.Optional; + +public interface ProductRepository { + + Product save(Product product); + + List saveAll(List products); + + Optional findById(Long id); + + List findByIdIn(List ids); +} From 8c4aed1e81b7cf777ba2450283e03f0e3034d4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:31:08 +0900 Subject: [PATCH 28/85] =?UTF-8?q?feat:=20PaymentOrderRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PaymentOrderRepository.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentOrderRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentOrderRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentOrderRepository.java new file mode 100644 index 00000000..7fa05b8b --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentOrderRepository.java @@ -0,0 +1,14 @@ +package com.ordertogether.team14_be.payment.persistence.repository; + +import com.ordertogether.team14_be.payment.domain.PaymentOrder; +import java.util.List; +import java.util.Optional; + +public interface PaymentOrderRepository { + + PaymentOrder save(PaymentOrder paymentOrder); + + List saveAll(List paymentOrders); + + Optional findById(Long id); +} From a7f17d8e25f9999414b4790394843e1c9b2b0d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:31:18 +0900 Subject: [PATCH 29/85] =?UTF-8?q?feat:=20PaymentEventRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PaymentEventRepository.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentEventRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentEventRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentEventRepository.java new file mode 100644 index 00000000..7084d746 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentEventRepository.java @@ -0,0 +1,13 @@ +package com.ordertogether.team14_be.payment.persistence.repository; + +import com.ordertogether.team14_be.payment.domain.PaymentEvent; +import java.util.Optional; + +public interface PaymentEventRepository { + + PaymentEvent save(PaymentEvent paymentEvent); + + Optional findById(Long id); + + Optional findByOrderId(String orderId); +} From c8329f4d255e026f2b49fcdfae960ff6bdd7c1d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:31:41 +0900 Subject: [PATCH 30/85] =?UTF-8?q?feat:=20SimpleJpaXXXRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/SimpleJpaPaymentEventRepository.java | 12 ++++++++++++ .../repository/SimpleJpaPaymentOrderRepository.java | 8 ++++++++ .../jpa/repository/SimpleJpaProductRepository.java | 12 ++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentEventRepository.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentOrderRepository.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaProductRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentEventRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentEventRepository.java new file mode 100644 index 00000000..dce6ca28 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentEventRepository.java @@ -0,0 +1,12 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.repository; + +import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentEventEntity; +import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SimpleJpaPaymentEventRepository extends JpaRepository { + + Optional findByOrderId(String orderId); +} diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentOrderRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentOrderRepository.java new file mode 100644 index 00000000..f5c5d38e --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentOrderRepository.java @@ -0,0 +1,8 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.repository; + +import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentOrderEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SimpleJpaPaymentOrderRepository extends JpaRepository {} diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaProductRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaProductRepository.java new file mode 100644 index 00000000..bf0a46b8 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaProductRepository.java @@ -0,0 +1,12 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.repository; + +import com.ordertogether.team14_be.payment.persistence.jpa.entity.ProductEntity; +import java.util.List; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SimpleJpaProductRepository extends JpaRepository { + + List findByIdIn(List ids); +} From 7a56111e1db0cbed984f08533fc0ff8b5314e9ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:32:06 +0900 Subject: [PATCH 31/85] =?UTF-8?q?feat:=20JpaProductRepository=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jpa/repository/JpaProductRepository.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaProductRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaProductRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaProductRepository.java new file mode 100644 index 00000000..feb9dd1d --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaProductRepository.java @@ -0,0 +1,43 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.repository; + +import com.ordertogether.team14_be.payment.domain.Product; +import com.ordertogether.team14_be.payment.persistence.jpa.entity.ProductEntity; +import com.ordertogether.team14_be.payment.persistence.jpa.mapper.ProductMapper; +import com.ordertogether.team14_be.payment.persistence.repository.ProductRepository; +import java.util.List; +import java.util.Optional; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class JpaProductRepository implements ProductRepository { + + private final SimpleJpaProductRepository simpleJpaProductRepository; + + @Override + public Product save(Product product) { + ProductEntity savedProduct = + simpleJpaProductRepository.save(ProductMapper.mapToEntity(product)); + return ProductMapper.mapToDomain(savedProduct); + } + + @Override + public List saveAll(List products) { + return simpleJpaProductRepository + .saveAll(products.stream().map(ProductMapper::mapToEntity).toList()) + .stream() + .map(ProductMapper::mapToDomain) + .toList(); + } + + @Override + public Optional findById(Long id) { + return simpleJpaProductRepository.findById(id).map(ProductMapper::mapToDomain); + } + + @Override + public List findByIdIn(List ids) { + return simpleJpaProductRepository.findByIdIn(ids).stream() + .map(ProductMapper::mapToDomain) + .toList(); + } +} From 4d10b1ff76ea48943e972111c32d6f1f75627585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:32:13 +0900 Subject: [PATCH 32/85] =?UTF-8?q?feat:=20JpaPaymentOrderRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/JpaPaymentOrderRepository.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentOrderRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentOrderRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentOrderRepository.java new file mode 100644 index 00000000..1eade54e --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentOrderRepository.java @@ -0,0 +1,64 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.repository; + +import com.ordertogether.team14_be.payment.domain.PaymentOrder; +import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentOrderEntity; +import com.ordertogether.team14_be.payment.persistence.jpa.entity.ProductEntity; +import com.ordertogether.team14_be.payment.persistence.jpa.mapper.PaymentOrderMapper; +import com.ordertogether.team14_be.payment.persistence.jpa.mapper.ProductMapper; +import com.ordertogether.team14_be.payment.persistence.repository.PaymentOrderRepository; +import java.util.List; +import java.util.Optional; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class JpaPaymentOrderRepository implements PaymentOrderRepository { + + private final SimpleJpaPaymentOrderRepository simpleJpaPaymentOrderRepository; + private final SimpleJpaProductRepository simpleJpaProductRepository; + + /** + * 결제 주문 정보를 저장한다.
+ * - 결제 주문 정보에 상품 정보가 없는 경우 상품 정보를 조회하여 결제 주문 정보에 추가한다. + * + * @param paymentOrder 결제 주문 정보 + * @return 저장된 결제 주문 정보 + */ + @Override + public PaymentOrder save(PaymentOrder paymentOrder) { + addMissingProductInfo(paymentOrder); + PaymentOrderEntity savedEntity = + simpleJpaPaymentOrderRepository.save(PaymentOrderMapper.mapToEntity(paymentOrder)); + + return PaymentOrderMapper.mapToDomain(savedEntity); + } + + private void addMissingProductInfo(PaymentOrder paymentOrder) { + if (paymentOrder.isMissingProductInfo()) { + ProductEntity productEntity = getProductEntity(paymentOrder); + paymentOrder.updateProductInfo(ProductMapper.mapToDomain(productEntity)); + } + } + + @Override + public List saveAll(List paymentOrders) { + List savedEntities = + simpleJpaPaymentOrderRepository.saveAll( + paymentOrders.stream().map(PaymentOrderMapper::mapToEntity).toList()); + + return PaymentOrderMapper.mapToDomain(savedEntities); + } + + @Override + public Optional findById(Long id) { + return simpleJpaPaymentOrderRepository.findById(id).map(PaymentOrderMapper::mapToDomain); + } + + private ProductEntity getProductEntity(PaymentOrder paymentOrder) { + return simpleJpaProductRepository + .findById(paymentOrder.getProductId()) + .orElseThrow( + () -> + new IllegalArgumentException( + String.format("상품 아이디 %s에 해당하는 상품이 없습니다.", paymentOrder.getProductId()))); + } +} From 25d4e7dcf7a6999411dc1c0ce009ea7510fb3553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:32:19 +0900 Subject: [PATCH 33/85] =?UTF-8?q?feat:=20JpaPaymentEventRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/JpaPaymentEventRepository.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentEventRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentEventRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentEventRepository.java new file mode 100644 index 00000000..7c286b90 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentEventRepository.java @@ -0,0 +1,33 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.repository; + +import com.ordertogether.team14_be.payment.domain.PaymentEvent; +import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentEventEntity; +import com.ordertogether.team14_be.payment.persistence.jpa.mapper.PaymentEventMapper; +import com.ordertogether.team14_be.payment.persistence.repository.PaymentEventRepository; +import java.util.Optional; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class JpaPaymentEventRepository implements PaymentEventRepository { + + private final SimpleJpaPaymentEventRepository simpleJpaPaymentEventRepository; + + @Override + public PaymentEvent save(PaymentEvent paymentEvent) { + PaymentEventEntity savedEntity = + simpleJpaPaymentEventRepository.save(PaymentEventMapper.mapToEntity(paymentEvent)); + return PaymentEventMapper.mapToDomain(savedEntity); + } + + @Override + public Optional findById(Long id) { + return simpleJpaPaymentEventRepository.findById(id).map(PaymentEventMapper::mapToDomain); + } + + @Override + public Optional findByOrderId(String orderId) { + return simpleJpaPaymentEventRepository + .findByOrderId(orderId) + .map(PaymentEventMapper::mapToDomain); + } +} From 6ac187ba9b6908dc447b044c5858bf96fed0aa70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:32:36 +0900 Subject: [PATCH 34/85] =?UTF-8?q?feat:=20=EB=A9=B1=EB=93=B1=EC=84=B1=20?= =?UTF-8?q?=ED=82=A4=20=EC=83=9D=EC=84=B1=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/util/IdempotentKeyGenerator.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/common/util/IdempotentKeyGenerator.java diff --git a/src/main/java/com/ordertogether/team14_be/common/util/IdempotentKeyGenerator.java b/src/main/java/com/ordertogether/team14_be/common/util/IdempotentKeyGenerator.java new file mode 100644 index 00000000..bfe518a5 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/common/util/IdempotentKeyGenerator.java @@ -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(); + } +} From 830036afea3bf84d32291f7e4b2ed8e91e6d3347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:33:14 +0900 Subject: [PATCH 35/85] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EC=A4=80?= =?UTF-8?q?=EB=B9=84=20DTO=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/request/PaymentPrepareRequest.java | 23 +++++++++++++ .../web/response/PaymentPrepareResponse.java | 33 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/web/request/PaymentPrepareRequest.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentPrepareResponse.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/request/PaymentPrepareRequest.java b/src/main/java/com/ordertogether/team14_be/payment/web/request/PaymentPrepareRequest.java new file mode 100644 index 00000000..aa79b894 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/web/request/PaymentPrepareRequest.java @@ -0,0 +1,23 @@ +package com.ordertogether.team14_be.payment.web.request; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.List; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class PaymentPrepareRequest { + + @JsonIgnore(false) + private Long buyerId; + + private final String idempotencySeed; + + private final List productIds; + + public PaymentPrepareRequest addBuyerId(Long buyerId) { + this.buyerId = buyerId; + return this; + } +} diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentPrepareResponse.java b/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentPrepareResponse.java new file mode 100644 index 00000000..566809a1 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentPrepareResponse.java @@ -0,0 +1,33 @@ +package com.ordertogether.team14_be.payment.web.response; + +import com.ordertogether.team14_be.payment.domain.PaymentEvent; +import com.ordertogether.team14_be.payment.domain.PaymentOrder; +import java.util.List; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@Getter +@Builder +@ToString +public class PaymentPrepareResponse { + + private Long paymentEventId; + private Long buyerId; + private List paymentOrders; + private String orderId; + private String orderName; + private String paymentKey; + + public static PaymentPrepareResponse of( + PaymentEvent paymentEvent, List paymentOrders) { + return PaymentPrepareResponse.builder() + .paymentEventId(paymentEvent.getId()) + .buyerId(paymentEvent.getBuyerId()) + .paymentOrders(paymentOrders.stream().map(PaymentOrderResponse::from).toList()) + .orderId(paymentEvent.getOrderId()) + .orderName(paymentEvent.getOrderName()) + .paymentKey(paymentEvent.getPaymentKey()) + .build(); + } +} From 90af11fd5dc03abbf2c0199e068892ee727a2731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:35:29 +0900 Subject: [PATCH 36/85] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EC=A3=BC?= =?UTF-8?q?=EB=AC=B8=20=EC=9D=91=EB=8B=B5=20DTO=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/response/PaymentOrderResponse.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentOrderResponse.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentOrderResponse.java b/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentOrderResponse.java new file mode 100644 index 00000000..352e8974 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentOrderResponse.java @@ -0,0 +1,32 @@ +package com.ordertogether.team14_be.payment.web.response; + +import com.ordertogether.team14_be.payment.domain.PaymentOrder; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@Getter +@Builder +@ToString +public class PaymentOrderResponse { + + private final Long paymentOrderId; + + private final Long productId; + + private final String orderId; + + private final String orderName; + + private final Long amount; + + public static PaymentOrderResponse from(PaymentOrder paymentOrder) { + return PaymentOrderResponse.builder() + .paymentOrderId(paymentOrder.getId()) + .productId(paymentOrder.getProductId()) + .orderId(paymentOrder.getOrderId()) + .orderName(paymentOrder.getOrderName()) + .amount(paymentOrder.getAmount().longValue()) + .build(); + } +} From f3cd2fdeeee7673d0e24e2ba0e321c6eba58fa92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:36:34 +0900 Subject: [PATCH 37/85] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EC=A4=80?= =?UTF-8?q?=EB=B9=84=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/PaymentPreparationService.java | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/service/PaymentPreparationService.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/service/PaymentPreparationService.java b/src/main/java/com/ordertogether/team14_be/payment/service/PaymentPreparationService.java new file mode 100644 index 00000000..1b2b33cb --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/service/PaymentPreparationService.java @@ -0,0 +1,94 @@ +package com.ordertogether.team14_be.payment.service; + +import com.ordertogether.team14_be.common.util.IdempotentKeyGenerator; +import com.ordertogether.team14_be.payment.domain.PaymentEvent; +import com.ordertogether.team14_be.payment.domain.PaymentOrder; +import com.ordertogether.team14_be.payment.domain.Product; +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 com.ordertogether.team14_be.payment.web.request.PaymentPrepareRequest; +import com.ordertogether.team14_be.payment.web.response.PaymentPrepareResponse; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +/** 결제 시작 전, 결제 정보를 저장하는 서비스 */ +public class PaymentPreparationService { + + private final PaymentEventRepository paymentEventRepository; + private final PaymentOrderRepository paymentOrderRepository; + private final ProductRepository productRepository; + + /** + * 결제 정보를 저장한다.
+ * {@link PaymentEvent} 와 {@link PaymentOrder} 를 저장한다. + * + * @param request 결제 정보 + * @return 저장된 결제 정보 + */ + @Transactional + public PaymentPrepareResponse prepare(PaymentPrepareRequest request) { + validateDuplicatePayment(request); + + List products = productRepository.findByIdIn(request.getProductIds()); + List paymentOrders = + paymentOrderRepository.saveAll(createPaymentOrders(products, request.getIdempotencySeed())); + PaymentEvent paymentEvent = paymentEventRepository.save(createPaymentEvent(request, products)); + + return PaymentPrepareResponse.of(paymentEvent, paymentOrders); + } + + /** + * 중복 결제 요청인지 확인한다. + * + * @param request 결제 정보 + * @throws IllegalArgumentException 중복 결제 요청일 경우 + */ + private void validateDuplicatePayment(PaymentPrepareRequest request) { + String idempotentKey = IdempotentKeyGenerator.generate(request.getIdempotencySeed()); + paymentEventRepository + .findByOrderId(idempotentKey) + .ifPresent( + paymentEvent -> { + throw new IllegalArgumentException( + "Seed: %s 를 통해 생성된 결제는 이미 %s 상태인 주문입니다." + .formatted( + request.getIdempotencySeed(), + paymentEvent.getPaymentStatus().getDescription())); + }); + } + + private List createPaymentOrders(List products, String idempotencySeed) { + return products.stream().map(product -> createPaymentOrder(product, idempotencySeed)).toList(); + } + + private PaymentOrder createPaymentOrder(Product product, String idempotencySeed) { + return PaymentOrder.builder() + .productId(product.getId()) + .orderId(IdempotentKeyGenerator.generate(idempotencySeed)) + .orderName(product.getName()) + .amount(product.getPrice()) + .build(); + } + + private PaymentEvent createPaymentEvent(PaymentPrepareRequest request, List products) { + String idempotencySeed = request.getIdempotencySeed(); + + return PaymentEvent.builder() + .buyerId(request.getBuyerId()) + .paymentOrders( + products.stream().map(product -> createPaymentOrder(product, idempotencySeed)).toList()) + .orderId(IdempotentKeyGenerator.generate(idempotencySeed)) + .orderName(createOrderName(products)) + .paymentKey(IdempotentKeyGenerator.generate(idempotencySeed)) + .build(); + } + + private String createOrderName(List products) { + return String.join(",", products.stream().map(Product::getName).toList()); + } +} From 0bd67c81ccec76bb2fcf8d5916cd0ecc040e08e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:13:13 +0900 Subject: [PATCH 38/85] =?UTF-8?q?test:=20PaymentDatabaseHelper=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/helper/PaymentDatabaseHelper.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/test/java/com/ordertogether/team14_be/helper/PaymentDatabaseHelper.java diff --git a/src/test/java/com/ordertogether/team14_be/helper/PaymentDatabaseHelper.java b/src/test/java/com/ordertogether/team14_be/helper/PaymentDatabaseHelper.java new file mode 100644 index 00000000..73e969bd --- /dev/null +++ b/src/test/java/com/ordertogether/team14_be/helper/PaymentDatabaseHelper.java @@ -0,0 +1,6 @@ +package com.ordertogether.team14_be.helper; + +public interface PaymentDatabaseHelper { + + void clean(); +} From a47a2b95a9ee58fa79747a0e214b2bde95a955df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:13:52 +0900 Subject: [PATCH 39/85] =?UTF-8?q?test:=20JpaDatabaseCleanup=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helper/jpa/JpaDatabaseCleanup.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/test/java/com/ordertogether/team14_be/helper/jpa/JpaDatabaseCleanup.java diff --git a/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaDatabaseCleanup.java b/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaDatabaseCleanup.java new file mode 100644 index 00000000..68e609ad --- /dev/null +++ b/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaDatabaseCleanup.java @@ -0,0 +1,51 @@ +package com.ordertogether.team14_be.helper.jpa; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; +import jakarta.persistence.Entity; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import java.util.List; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +@Component +@Profile("test") +public class JpaDatabaseCleanup implements InitializingBean { + + @PersistenceContext private EntityManager entityManager; + + private List tableNames; + + @Override + public void afterPropertiesSet() { + tableNames = + entityManager.getMetamodel().getEntities().stream() + .filter(e -> e.getJavaType().getAnnotation(Entity.class) != null) + .map(e -> removePostfix(e.getName(), "Entity")) + .map(SnakeCaseStrategy.INSTANCE::translate) + .toList(); + } + + private String removePostfix(String entityName, String postfix) { + if (entityName.endsWith(postfix)) { + return entityName.substring(0, entityName.length() - postfix.length()); + } + return entityName; + } + + @Transactional + public void execute() { + entityManager.flush(); + entityManager.createNativeQuery("SET FOREIGN_KEY_CHECKS = 0").executeUpdate(); + + for (String tableName : tableNames) { + entityManager.createNativeQuery("TRUNCATE TABLE " + tableName).executeUpdate(); + entityManager + .createNativeQuery("ALTER TABLE " + tableName + " AUTO_INCREMENT = 1") + .executeUpdate(); + } + entityManager.createNativeQuery("SET FOREIGN_KEY_CHECKS = 1").executeUpdate(); + } +} From f0b52b6ccf556e987b75854bdc045a0ca321f4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:14:08 +0900 Subject: [PATCH 40/85] =?UTF-8?q?test:=20JpaPaymentDatabaseHelper=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helper/jpa/JpaPaymentDatabaseHelper.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/java/com/ordertogether/team14_be/helper/jpa/JpaPaymentDatabaseHelper.java diff --git a/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaPaymentDatabaseHelper.java b/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaPaymentDatabaseHelper.java new file mode 100644 index 00000000..7f292b01 --- /dev/null +++ b/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaPaymentDatabaseHelper.java @@ -0,0 +1,17 @@ +package com.ordertogether.team14_be.helper.jpa; + +import com.ordertogether.team14_be.helper.PaymentDatabaseHelper; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class JpaPaymentDatabaseHelper implements PaymentDatabaseHelper { + + private final JpaDatabaseCleanup jpaDatabaseCleanup; + + @Override + public void clean() { + jpaDatabaseCleanup.execute(); + } +} From 9797493f68eba5074d6ea232a3eb5b790de05648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:14:56 +0900 Subject: [PATCH 41/85] =?UTF-8?q?test:=20test=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/application-test.yml | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/test/resources/application-test.yml diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml new file mode 100644 index 00000000..64108094 --- /dev/null +++ b/src/test/resources/application-test.yml @@ -0,0 +1,27 @@ +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: + url: jdbc:mysql://localhost:3306/delivery_sharing + + jpa: + hibernate: + ddl-auto: create + properties: + hibernate: + format_sql: true + defer-datasource-initialization: true + + sql: + init: + mode: always + +logging: + level: + org: + hibernate: + SQL: debug + orm: + jdbc: + bind: trace \ No newline at end of file From 6ed63aa6e2beb71d79d95c7054dd6b5a29a1904a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:15:57 +0900 Subject: [PATCH 42/85] =?UTF-8?q?test:=20=EA=B2=B0=EC=A0=9C=20=EC=A4=80?= =?UTF-8?q?=EB=B9=84=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 결제 준비에 대한 정상 케이스 - 중복 결제 준비 요청에 대한 예외 발생 케이스 --- .../PaymentPreparationServiceTest.java | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/test/java/com/ordertogether/team14_be/payment/service/PaymentPreparationServiceTest.java diff --git a/src/test/java/com/ordertogether/team14_be/payment/service/PaymentPreparationServiceTest.java b/src/test/java/com/ordertogether/team14_be/payment/service/PaymentPreparationServiceTest.java new file mode 100644 index 00000000..c71eef59 --- /dev/null +++ b/src/test/java/com/ordertogether/team14_be/payment/service/PaymentPreparationServiceTest.java @@ -0,0 +1,81 @@ +package com.ordertogether.team14_be.payment.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; + +import com.ordertogether.team14_be.helper.PaymentDatabaseHelper; +import com.ordertogether.team14_be.payment.domain.Product; +import com.ordertogether.team14_be.payment.persistence.repository.ProductRepository; +import com.ordertogether.team14_be.payment.web.request.PaymentPrepareRequest; +import com.ordertogether.team14_be.payment.web.response.PaymentPrepareResponse; +import java.math.BigDecimal; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("test") +@SpringBootTest +class PaymentPreparationServiceTest { + + @Autowired private PaymentPreparationService paymentPreparationService; + @Autowired private ProductRepository productRepository; + + @Autowired private PaymentDatabaseHelper paymentDatabaseHelper; + + @BeforeEach + void setup() { + paymentDatabaseHelper.clean(); + + productRepository.saveAll( + List.of( + Product.builder().id(1L).name("Product 1").price(BigDecimal.valueOf(10000)).build(), + Product.builder().id(2L).name("Product 2").price(BigDecimal.valueOf(20000)).build(), + Product.builder().id(3L).name("Product 3").price(BigDecimal.valueOf(30000)).build())); + } + + @Test + @DisplayName("결제 정보를 성공적으로 저장할 수 있다.") + void shouldSuccessWhenNormalRequest() { + // given + PaymentPrepareRequest request = + new PaymentPrepareRequest("idempotency-seed", List.of(1L, 2L, 3L)).addBuyerId(1L); + + // then + PaymentPrepareResponse response = paymentPreparationService.prepare(request); + + // when + assertThat(response.getPaymentEventId()).isNotNull(); + assertThat(response.getBuyerId()).isEqualTo(1L); + assertThat(response.getPaymentOrders()).hasSize(3); + assertThat(response.getOrderId()).isNotNull(); + assertThat(response.getOrderName()).isEqualTo("Product 1,Product 2,Product 3"); + assertThat(response.getPaymentKey()).isNotNull(); + response.getPaymentOrders().stream() + .forEach( + paymentOrder -> { + assertAll( + () -> assertThat(paymentOrder.getPaymentOrderId()).isNotNull(), + () -> assertThat(paymentOrder.getProductId()).isIn(1L, 2L, 3L), + () -> assertThat(paymentOrder.getOrderId()).isEqualTo(response.getOrderId())); + }); + } + + @Test + @DisplayName("이미 저장된 결제 정보는 저장 요청 시, 예외가 발생한다.") + void shouldThrowExceptionWhenAlreadyCompleteRequest() { + // given + PaymentPrepareRequest request = + new PaymentPrepareRequest("idempotency-seed", List.of(1L, 2L, 3L)).addBuyerId(1L); + paymentPreparationService.prepare(request); + + // then + // when + assertThatThrownBy(() -> paymentPreparationService.prepare(request)) + .isInstanceOf(IllegalArgumentException.class); + } +} From cf56992c5dd7d08070f22d37c524cc57156bb5ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:17:01 +0900 Subject: [PATCH 43/85] =?UTF-8?q?feat:=20application.yml=20data.sql=20?= =?UTF-8?q?=EC=88=98=ED=96=89=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 45727403..a49c1937 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -14,6 +14,11 @@ spring: properties: hibernate: format_sql: true + defer-datasource-initialization: true + + sql: + init: + mode: always logging: level: From 343b1f2f37268a9a06bf1804244d14aa7858f53c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:17:16 +0900 Subject: [PATCH 44/85] =?UTF-8?q?feat:=20data.sql=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/data.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/main/resources/data.sql diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql new file mode 100644 index 00000000..59b6346f --- /dev/null +++ b/src/main/resources/data.sql @@ -0,0 +1,3 @@ +INSERT INTO product (id, name, price, created_at, modified_at, created_by, modified_by) VALUES (1, 'Product 1', 10000, now(), now(), 1, 1); +INSERT INTO product (id, name, price, created_at, modified_at, created_by, modified_by) VALUES (2, 'Product 2', 20000, now(), now(), 1, 1); +INSERT INTO product (id, name, price, created_at, modified_at, created_by, modified_by) VALUES (3, 'Product 3', 30000, now(), now(), 1, 1); From 011df666dd3717d4145aea6cea2cf23d2fb5726e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:18:00 +0900 Subject: [PATCH 45/85] =?UTF-8?q?chore:=20build.gradle=20=EC=8A=A4?= =?UTF-8?q?=ED=94=84=EB=A7=81=20=EC=8B=9C=ED=81=90=EB=A6=AC=ED=8B=B0=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 5 ----- 1 file changed, 5 deletions(-) diff --git a/build.gradle b/build.gradle index 41dc442b..6624001a 100644 --- a/build.gradle +++ b/build.gradle @@ -33,15 +33,10 @@ 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' 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' From ff569e3005b000efb28ac64fac299bc0217cd3fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:18:34 +0900 Subject: [PATCH 46/85] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20Repository?= =?UTF-8?q?=20=EB=B9=88=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/config/PersistenceConfig.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main/java/com/ordertogether/team14_be/config/PersistenceConfig.java b/src/main/java/com/ordertogether/team14_be/config/PersistenceConfig.java index d9de0f5e..8d24b129 100644 --- a/src/main/java/com/ordertogether/team14_be/config/PersistenceConfig.java +++ b/src/main/java/com/ordertogether/team14_be/config/PersistenceConfig.java @@ -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; @@ -15,4 +24,24 @@ public class PersistenceConfig { public AuditorAware 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); + } } From d6d72fd686e7920b18e0ef55e58e6fefe8229ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:19:05 +0900 Subject: [PATCH 47/85] =?UTF-8?q?feat:=20PaymentController=20=EA=B2=B0?= =?UTF-8?q?=EC=A0=9C=20=EC=A4=80=EB=B9=84=20=EC=97=94=EB=93=9C=ED=8F=AC?= =?UTF-8?q?=EC=9D=B8=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/PaymentController.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/web/controller/PaymentController.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/controller/PaymentController.java b/src/main/java/com/ordertogether/team14_be/payment/web/controller/PaymentController.java new file mode 100644 index 00000000..5b17246e --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/web/controller/PaymentController.java @@ -0,0 +1,31 @@ +package com.ordertogether.team14_be.payment.web.controller; + +import com.ordertogether.team14_be.common.web.response.ApiResponse; +import com.ordertogether.team14_be.payment.service.PaymentPreparationService; +import com.ordertogether.team14_be.payment.web.request.PaymentPrepareRequest; +import com.ordertogether.team14_be.payment.web.response.PaymentPrepareResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/v1/payments") +@RequiredArgsConstructor +public class PaymentController { + + private final PaymentPreparationService paymentPreparationService; + + @PostMapping + public ResponseEntity> preparePayment( + @RequestBody PaymentPrepareRequest request) { + // todo: 1L -> UserDetail.getUserId() + request.addBuyerId(1L); + PaymentPrepareResponse data = paymentPreparationService.prepare(request); + + return ResponseEntity.ok(ApiResponse.with(HttpStatus.OK, "결제 정보를 저장하였습니다.", data)); + } +} From fd82d4baf5d4c4eeb1119eed7856ba9fb02bbdfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:19:30 +0900 Subject: [PATCH 48/85] =?UTF-8?q?feat:=20Api=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EB=B3=B8=EB=AC=B8=20=EA=B5=AC=EC=A1=B0=20=EC=84=A0=EC=96=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/web/response/ApiResponse.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/common/web/response/ApiResponse.java diff --git a/src/main/java/com/ordertogether/team14_be/common/web/response/ApiResponse.java b/src/main/java/com/ordertogether/team14_be/common/web/response/ApiResponse.java new file mode 100644 index 00000000..23ccb295 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/common/web/response/ApiResponse.java @@ -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 { + + private Integer status; + private String message; + private T data; + + public static ApiResponse with(HttpStatus httpStatus, String message, @Nullable T data) { + return new ApiResponse<>(httpStatus.value(), message, data); + } +} From f1d41530f8753db8d13e16e895453e4b120d05a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Tue, 24 Sep 2024 14:14:58 +0900 Subject: [PATCH 49/85] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EC=A3=BC?= =?UTF-8?q?=EB=AC=B8=20=EC=97=94=ED=8B=B0=ED=8B=B0=EC=99=80=20=EC=83=81?= =?UTF-8?q?=ED=92=88=20=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ordertogether/team14_be/payment/domain/PaymentOrder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java index eaef2452..b252ff86 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java +++ b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java @@ -34,8 +34,8 @@ public class PaymentOrder extends BaseTimeEntity { @Column(nullable = false) private Long sellerId; // 판매자 식별자 - @ManyToOne(fetch = FetchType.LAZY) - private Product productId; + @Column(nullable = false) + private Long productId; @Column(nullable = false) private String orderId; From b5d1c148f52243a4e6712838553a567d9162da8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:26:33 +0900 Subject: [PATCH 50/85] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EC=97=90=20description=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../payment/domain/PaymentOrderStatus.java | 9 --------- .../team14_be/payment/domain/PaymentStatus.java | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) delete mode 100644 src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrderStatus.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/domain/PaymentStatus.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrderStatus.java b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrderStatus.java deleted file mode 100644 index f72b0506..00000000 --- a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrderStatus.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.ordertogether.team14_be.payment.domain; - -/** 결제 상태 */ -public enum PaymentOrderStatus { - READY, - EXECUTING, - SUCCESS, - FAIL; -} diff --git a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentStatus.java b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentStatus.java new file mode 100644 index 00000000..001acfaa --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentStatus.java @@ -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; +} From e005f12ccfd609f53b910dc51b9d2c9ba1096fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:28:09 +0900 Subject: [PATCH 51/85] =?UTF-8?q?feat:=20Entity=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jpa/entity/PaymentEventEntity.java | 49 +++++++++++++++++++ .../jpa/entity/PaymentOrderEntity.java | 42 ++++++++++++++++ .../persistence/jpa/entity/ProductEntity.java | 36 ++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentEventEntity.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentOrderEntity.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/ProductEntity.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentEventEntity.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentEventEntity.java new file mode 100644 index 00000000..6a64f56d --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentEventEntity.java @@ -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; +} diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentOrderEntity.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentOrderEntity.java new file mode 100644 index 00000000..d86a1bf8 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/PaymentOrderEntity.java @@ -0,0 +1,42 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.entity; + +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 jakarta.persistence.Table; +import java.math.BigDecimal; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.SuperBuilder; + +@Entity +@Getter +@SuperBuilder +@ToString +@Table(name = "payment_order") +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class PaymentOrderEntity extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private Long productId; + + @Column(nullable = false) + private String orderId; + + @Column(nullable = false) + private String orderName; + + @Column(nullable = false, precision = 10, scale = 2) + private BigDecimal amount; // 결제 금액 +} diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/ProductEntity.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/ProductEntity.java new file mode 100644 index 00000000..f149e8bf --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/entity/ProductEntity.java @@ -0,0 +1,36 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.entity; + +import com.ordertogether.team14_be.common.persistence.entity.BaseEntity; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import java.math.BigDecimal; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.SuperBuilder; + +@Entity +@Getter +@SuperBuilder +@ToString +@Table(name = "product") +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class ProductEntity extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String name; + + @Column(nullable = false) + private BigDecimal price; +} From 62e7c7f9b4939ce4abbdae9610e2cddf6f7f5986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:28:59 +0900 Subject: [PATCH 52/85] =?UTF-8?q?feat:=20Domain=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../payment/domain/PaymentEvent.java | 39 ++++++------- .../payment/domain/PaymentOrder.java | 55 ++++++++----------- .../team14_be/payment/domain/Product.java | 22 +------- 3 files changed, 41 insertions(+), 75 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentEvent.java b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentEvent.java index 69dc6892..06333daa 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentEvent.java +++ b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentEvent.java @@ -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 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(); + } } diff --git a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java index b252ff86..599d7061 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java +++ b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentOrder.java @@ -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; // 판매자 식별자 - - @Column(nullable = false) private Long 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()); + } } diff --git a/src/main/java/com/ordertogether/team14_be/payment/domain/Product.java b/src/main/java/com/ordertogether/team14_be/payment/domain/Product.java index 641fe49e..3cd03891 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/domain/Product.java +++ b/src/main/java/com/ordertogether/team14_be/payment/domain/Product.java @@ -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; } From 3eddd28490dad7cb9770d5210c8822e22a60a3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:29:51 +0900 Subject: [PATCH 53/85] =?UTF-8?q?feat:=20Mapper=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jpa/mapper/PaymentEventMapper.java | 31 +++++++++++++++++ .../jpa/mapper/PaymentOrderMapper.java | 34 +++++++++++++++++++ .../persistence/jpa/mapper/ProductMapper.java | 25 ++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentEventMapper.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentOrderMapper.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/ProductMapper.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentEventMapper.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentEventMapper.java new file mode 100644 index 00000000..db590005 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentEventMapper.java @@ -0,0 +1,31 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.mapper; + +import com.ordertogether.team14_be.payment.domain.PaymentEvent; +import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentEventEntity; +import lombok.experimental.UtilityClass; + +@UtilityClass +public final class PaymentEventMapper { + + public static PaymentEventEntity mapToEntity(PaymentEvent domain) { + return PaymentEventEntity.builder() + .id(domain.getId()) + .buyerId(domain.getBuyerId()) + .orderId(domain.getOrderId()) + .orderName(domain.getOrderName()) + .paymentKey(domain.getPaymentKey()) + .paymentStatus(domain.getPaymentStatus()) + .build(); + } + + public static PaymentEvent mapToDomain(PaymentEventEntity entity) { + return PaymentEvent.builder() + .id(entity.getId()) + .buyerId(entity.getBuyerId()) + .orderId(entity.getOrderId()) + .orderName(entity.getOrderName()) + .paymentKey(entity.getPaymentKey()) + .paymentStatus(entity.getPaymentStatus()) + .build(); + } +} diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentOrderMapper.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentOrderMapper.java new file mode 100644 index 00000000..9331c173 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/PaymentOrderMapper.java @@ -0,0 +1,34 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.mapper; + +import com.ordertogether.team14_be.payment.domain.PaymentOrder; +import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentOrderEntity; +import java.util.List; +import lombok.experimental.UtilityClass; + +@UtilityClass +public final class PaymentOrderMapper { + + public static PaymentOrderEntity mapToEntity(PaymentOrder domain) { + return PaymentOrderEntity.builder() + .id(domain.getId()) + .productId(domain.getProductId()) + .orderId(domain.getOrderId()) + .orderName(domain.getOrderName()) + .amount(domain.getAmount()) + .build(); + } + + public static PaymentOrder mapToDomain(PaymentOrderEntity entity) { + return PaymentOrder.builder() + .id(entity.getId()) + .productId(entity.getProductId()) + .orderId(entity.getOrderId()) + .orderName(entity.getOrderName()) + .amount(entity.getAmount()) + .build(); + } + + public static List mapToDomain(List entities) { + return entities.stream().map(PaymentOrderMapper::mapToDomain).toList(); + } +} diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/ProductMapper.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/ProductMapper.java new file mode 100644 index 00000000..c7313d83 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/mapper/ProductMapper.java @@ -0,0 +1,25 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.mapper; + +import com.ordertogether.team14_be.payment.domain.Product; +import com.ordertogether.team14_be.payment.persistence.jpa.entity.ProductEntity; +import lombok.experimental.UtilityClass; + +@UtilityClass +public final class ProductMapper { + + public static ProductEntity mapToEntity(Product domain) { + return ProductEntity.builder() + .id(domain.getId()) + .name(domain.getName()) + .price(domain.getPrice()) + .build(); + } + + public static Product mapToDomain(ProductEntity entity) { + return Product.builder() + .id(entity.getId()) + .name(entity.getName()) + .price(entity.getPrice()) + .build(); + } +} From a0293aea33dd4be2b0b8659497230566df932a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:30:45 +0900 Subject: [PATCH 54/85] =?UTF-8?q?feat:=20ProductRepository=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ProductRepository.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/repository/ProductRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/ProductRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/ProductRepository.java new file mode 100644 index 00000000..e3364f7c --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/ProductRepository.java @@ -0,0 +1,16 @@ +package com.ordertogether.team14_be.payment.persistence.repository; + +import com.ordertogether.team14_be.payment.domain.Product; +import java.util.List; +import java.util.Optional; + +public interface ProductRepository { + + Product save(Product product); + + List saveAll(List products); + + Optional findById(Long id); + + List findByIdIn(List ids); +} From 4a215c10e30ba13f8a50be27f23d8aebfd8d6fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:31:08 +0900 Subject: [PATCH 55/85] =?UTF-8?q?feat:=20PaymentOrderRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PaymentOrderRepository.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentOrderRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentOrderRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentOrderRepository.java new file mode 100644 index 00000000..7fa05b8b --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentOrderRepository.java @@ -0,0 +1,14 @@ +package com.ordertogether.team14_be.payment.persistence.repository; + +import com.ordertogether.team14_be.payment.domain.PaymentOrder; +import java.util.List; +import java.util.Optional; + +public interface PaymentOrderRepository { + + PaymentOrder save(PaymentOrder paymentOrder); + + List saveAll(List paymentOrders); + + Optional findById(Long id); +} From 48a85d79420ecdfbd6feb3386c3eef447230ef18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:31:18 +0900 Subject: [PATCH 56/85] =?UTF-8?q?feat:=20PaymentEventRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PaymentEventRepository.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentEventRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentEventRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentEventRepository.java new file mode 100644 index 00000000..7084d746 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentEventRepository.java @@ -0,0 +1,13 @@ +package com.ordertogether.team14_be.payment.persistence.repository; + +import com.ordertogether.team14_be.payment.domain.PaymentEvent; +import java.util.Optional; + +public interface PaymentEventRepository { + + PaymentEvent save(PaymentEvent paymentEvent); + + Optional findById(Long id); + + Optional findByOrderId(String orderId); +} From 85802aac65cf63beccbd1310afc58f0add167f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:31:41 +0900 Subject: [PATCH 57/85] =?UTF-8?q?feat:=20SimpleJpaXXXRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/SimpleJpaPaymentEventRepository.java | 12 ++++++++++++ .../repository/SimpleJpaPaymentOrderRepository.java | 8 ++++++++ .../jpa/repository/SimpleJpaProductRepository.java | 12 ++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentEventRepository.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentOrderRepository.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaProductRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentEventRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentEventRepository.java new file mode 100644 index 00000000..dce6ca28 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentEventRepository.java @@ -0,0 +1,12 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.repository; + +import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentEventEntity; +import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SimpleJpaPaymentEventRepository extends JpaRepository { + + Optional findByOrderId(String orderId); +} diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentOrderRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentOrderRepository.java new file mode 100644 index 00000000..f5c5d38e --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentOrderRepository.java @@ -0,0 +1,8 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.repository; + +import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentOrderEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SimpleJpaPaymentOrderRepository extends JpaRepository {} diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaProductRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaProductRepository.java new file mode 100644 index 00000000..bf0a46b8 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaProductRepository.java @@ -0,0 +1,12 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.repository; + +import com.ordertogether.team14_be.payment.persistence.jpa.entity.ProductEntity; +import java.util.List; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SimpleJpaProductRepository extends JpaRepository { + + List findByIdIn(List ids); +} From ba8d275585968221423aef17e6ef394784063b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:32:06 +0900 Subject: [PATCH 58/85] =?UTF-8?q?feat:=20JpaProductRepository=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jpa/repository/JpaProductRepository.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaProductRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaProductRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaProductRepository.java new file mode 100644 index 00000000..feb9dd1d --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaProductRepository.java @@ -0,0 +1,43 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.repository; + +import com.ordertogether.team14_be.payment.domain.Product; +import com.ordertogether.team14_be.payment.persistence.jpa.entity.ProductEntity; +import com.ordertogether.team14_be.payment.persistence.jpa.mapper.ProductMapper; +import com.ordertogether.team14_be.payment.persistence.repository.ProductRepository; +import java.util.List; +import java.util.Optional; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class JpaProductRepository implements ProductRepository { + + private final SimpleJpaProductRepository simpleJpaProductRepository; + + @Override + public Product save(Product product) { + ProductEntity savedProduct = + simpleJpaProductRepository.save(ProductMapper.mapToEntity(product)); + return ProductMapper.mapToDomain(savedProduct); + } + + @Override + public List saveAll(List products) { + return simpleJpaProductRepository + .saveAll(products.stream().map(ProductMapper::mapToEntity).toList()) + .stream() + .map(ProductMapper::mapToDomain) + .toList(); + } + + @Override + public Optional findById(Long id) { + return simpleJpaProductRepository.findById(id).map(ProductMapper::mapToDomain); + } + + @Override + public List findByIdIn(List ids) { + return simpleJpaProductRepository.findByIdIn(ids).stream() + .map(ProductMapper::mapToDomain) + .toList(); + } +} From 32ac0b9e3b418e7cb9a5bf270ba2809dc7cab3ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:32:13 +0900 Subject: [PATCH 59/85] =?UTF-8?q?feat:=20JpaPaymentOrderRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/JpaPaymentOrderRepository.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentOrderRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentOrderRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentOrderRepository.java new file mode 100644 index 00000000..1eade54e --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentOrderRepository.java @@ -0,0 +1,64 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.repository; + +import com.ordertogether.team14_be.payment.domain.PaymentOrder; +import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentOrderEntity; +import com.ordertogether.team14_be.payment.persistence.jpa.entity.ProductEntity; +import com.ordertogether.team14_be.payment.persistence.jpa.mapper.PaymentOrderMapper; +import com.ordertogether.team14_be.payment.persistence.jpa.mapper.ProductMapper; +import com.ordertogether.team14_be.payment.persistence.repository.PaymentOrderRepository; +import java.util.List; +import java.util.Optional; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class JpaPaymentOrderRepository implements PaymentOrderRepository { + + private final SimpleJpaPaymentOrderRepository simpleJpaPaymentOrderRepository; + private final SimpleJpaProductRepository simpleJpaProductRepository; + + /** + * 결제 주문 정보를 저장한다.
+ * - 결제 주문 정보에 상품 정보가 없는 경우 상품 정보를 조회하여 결제 주문 정보에 추가한다. + * + * @param paymentOrder 결제 주문 정보 + * @return 저장된 결제 주문 정보 + */ + @Override + public PaymentOrder save(PaymentOrder paymentOrder) { + addMissingProductInfo(paymentOrder); + PaymentOrderEntity savedEntity = + simpleJpaPaymentOrderRepository.save(PaymentOrderMapper.mapToEntity(paymentOrder)); + + return PaymentOrderMapper.mapToDomain(savedEntity); + } + + private void addMissingProductInfo(PaymentOrder paymentOrder) { + if (paymentOrder.isMissingProductInfo()) { + ProductEntity productEntity = getProductEntity(paymentOrder); + paymentOrder.updateProductInfo(ProductMapper.mapToDomain(productEntity)); + } + } + + @Override + public List saveAll(List paymentOrders) { + List savedEntities = + simpleJpaPaymentOrderRepository.saveAll( + paymentOrders.stream().map(PaymentOrderMapper::mapToEntity).toList()); + + return PaymentOrderMapper.mapToDomain(savedEntities); + } + + @Override + public Optional findById(Long id) { + return simpleJpaPaymentOrderRepository.findById(id).map(PaymentOrderMapper::mapToDomain); + } + + private ProductEntity getProductEntity(PaymentOrder paymentOrder) { + return simpleJpaProductRepository + .findById(paymentOrder.getProductId()) + .orElseThrow( + () -> + new IllegalArgumentException( + String.format("상품 아이디 %s에 해당하는 상품이 없습니다.", paymentOrder.getProductId()))); + } +} From 5204586739c23936037ae1568687b133d512dbd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:32:19 +0900 Subject: [PATCH 60/85] =?UTF-8?q?feat:=20JpaPaymentEventRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/JpaPaymentEventRepository.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentEventRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentEventRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentEventRepository.java new file mode 100644 index 00000000..7c286b90 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentEventRepository.java @@ -0,0 +1,33 @@ +package com.ordertogether.team14_be.payment.persistence.jpa.repository; + +import com.ordertogether.team14_be.payment.domain.PaymentEvent; +import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentEventEntity; +import com.ordertogether.team14_be.payment.persistence.jpa.mapper.PaymentEventMapper; +import com.ordertogether.team14_be.payment.persistence.repository.PaymentEventRepository; +import java.util.Optional; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class JpaPaymentEventRepository implements PaymentEventRepository { + + private final SimpleJpaPaymentEventRepository simpleJpaPaymentEventRepository; + + @Override + public PaymentEvent save(PaymentEvent paymentEvent) { + PaymentEventEntity savedEntity = + simpleJpaPaymentEventRepository.save(PaymentEventMapper.mapToEntity(paymentEvent)); + return PaymentEventMapper.mapToDomain(savedEntity); + } + + @Override + public Optional findById(Long id) { + return simpleJpaPaymentEventRepository.findById(id).map(PaymentEventMapper::mapToDomain); + } + + @Override + public Optional findByOrderId(String orderId) { + return simpleJpaPaymentEventRepository + .findByOrderId(orderId) + .map(PaymentEventMapper::mapToDomain); + } +} From 84fe111b8013f759e963226775bfdfb82abb01e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:32:36 +0900 Subject: [PATCH 61/85] =?UTF-8?q?feat:=20=EB=A9=B1=EB=93=B1=EC=84=B1=20?= =?UTF-8?q?=ED=82=A4=20=EC=83=9D=EC=84=B1=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/util/IdempotentKeyGenerator.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/common/util/IdempotentKeyGenerator.java diff --git a/src/main/java/com/ordertogether/team14_be/common/util/IdempotentKeyGenerator.java b/src/main/java/com/ordertogether/team14_be/common/util/IdempotentKeyGenerator.java new file mode 100644 index 00000000..bfe518a5 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/common/util/IdempotentKeyGenerator.java @@ -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(); + } +} From c912dc43638a15ebbcd529f6332258b79e844aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:33:14 +0900 Subject: [PATCH 62/85] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EC=A4=80?= =?UTF-8?q?=EB=B9=84=20DTO=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/request/PaymentPrepareRequest.java | 23 +++++++++++++ .../web/response/PaymentPrepareResponse.java | 33 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/web/request/PaymentPrepareRequest.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentPrepareResponse.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/request/PaymentPrepareRequest.java b/src/main/java/com/ordertogether/team14_be/payment/web/request/PaymentPrepareRequest.java new file mode 100644 index 00000000..aa79b894 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/web/request/PaymentPrepareRequest.java @@ -0,0 +1,23 @@ +package com.ordertogether.team14_be.payment.web.request; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.List; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class PaymentPrepareRequest { + + @JsonIgnore(false) + private Long buyerId; + + private final String idempotencySeed; + + private final List productIds; + + public PaymentPrepareRequest addBuyerId(Long buyerId) { + this.buyerId = buyerId; + return this; + } +} diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentPrepareResponse.java b/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentPrepareResponse.java new file mode 100644 index 00000000..566809a1 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentPrepareResponse.java @@ -0,0 +1,33 @@ +package com.ordertogether.team14_be.payment.web.response; + +import com.ordertogether.team14_be.payment.domain.PaymentEvent; +import com.ordertogether.team14_be.payment.domain.PaymentOrder; +import java.util.List; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@Getter +@Builder +@ToString +public class PaymentPrepareResponse { + + private Long paymentEventId; + private Long buyerId; + private List paymentOrders; + private String orderId; + private String orderName; + private String paymentKey; + + public static PaymentPrepareResponse of( + PaymentEvent paymentEvent, List paymentOrders) { + return PaymentPrepareResponse.builder() + .paymentEventId(paymentEvent.getId()) + .buyerId(paymentEvent.getBuyerId()) + .paymentOrders(paymentOrders.stream().map(PaymentOrderResponse::from).toList()) + .orderId(paymentEvent.getOrderId()) + .orderName(paymentEvent.getOrderName()) + .paymentKey(paymentEvent.getPaymentKey()) + .build(); + } +} From 483a5affa13a136a6039877e4503ffb2233e880e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:35:29 +0900 Subject: [PATCH 63/85] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EC=A3=BC?= =?UTF-8?q?=EB=AC=B8=20=EC=9D=91=EB=8B=B5=20DTO=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/response/PaymentOrderResponse.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentOrderResponse.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentOrderResponse.java b/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentOrderResponse.java new file mode 100644 index 00000000..352e8974 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentOrderResponse.java @@ -0,0 +1,32 @@ +package com.ordertogether.team14_be.payment.web.response; + +import com.ordertogether.team14_be.payment.domain.PaymentOrder; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@Getter +@Builder +@ToString +public class PaymentOrderResponse { + + private final Long paymentOrderId; + + private final Long productId; + + private final String orderId; + + private final String orderName; + + private final Long amount; + + public static PaymentOrderResponse from(PaymentOrder paymentOrder) { + return PaymentOrderResponse.builder() + .paymentOrderId(paymentOrder.getId()) + .productId(paymentOrder.getProductId()) + .orderId(paymentOrder.getOrderId()) + .orderName(paymentOrder.getOrderName()) + .amount(paymentOrder.getAmount().longValue()) + .build(); + } +} From 682d2143ddf92013d05148ded7ea5648d714b24c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 01:36:34 +0900 Subject: [PATCH 64/85] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EC=A4=80?= =?UTF-8?q?=EB=B9=84=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/PaymentPreparationService.java | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/service/PaymentPreparationService.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/service/PaymentPreparationService.java b/src/main/java/com/ordertogether/team14_be/payment/service/PaymentPreparationService.java new file mode 100644 index 00000000..1b2b33cb --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/service/PaymentPreparationService.java @@ -0,0 +1,94 @@ +package com.ordertogether.team14_be.payment.service; + +import com.ordertogether.team14_be.common.util.IdempotentKeyGenerator; +import com.ordertogether.team14_be.payment.domain.PaymentEvent; +import com.ordertogether.team14_be.payment.domain.PaymentOrder; +import com.ordertogether.team14_be.payment.domain.Product; +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 com.ordertogether.team14_be.payment.web.request.PaymentPrepareRequest; +import com.ordertogether.team14_be.payment.web.response.PaymentPrepareResponse; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +/** 결제 시작 전, 결제 정보를 저장하는 서비스 */ +public class PaymentPreparationService { + + private final PaymentEventRepository paymentEventRepository; + private final PaymentOrderRepository paymentOrderRepository; + private final ProductRepository productRepository; + + /** + * 결제 정보를 저장한다.
+ * {@link PaymentEvent} 와 {@link PaymentOrder} 를 저장한다. + * + * @param request 결제 정보 + * @return 저장된 결제 정보 + */ + @Transactional + public PaymentPrepareResponse prepare(PaymentPrepareRequest request) { + validateDuplicatePayment(request); + + List products = productRepository.findByIdIn(request.getProductIds()); + List paymentOrders = + paymentOrderRepository.saveAll(createPaymentOrders(products, request.getIdempotencySeed())); + PaymentEvent paymentEvent = paymentEventRepository.save(createPaymentEvent(request, products)); + + return PaymentPrepareResponse.of(paymentEvent, paymentOrders); + } + + /** + * 중복 결제 요청인지 확인한다. + * + * @param request 결제 정보 + * @throws IllegalArgumentException 중복 결제 요청일 경우 + */ + private void validateDuplicatePayment(PaymentPrepareRequest request) { + String idempotentKey = IdempotentKeyGenerator.generate(request.getIdempotencySeed()); + paymentEventRepository + .findByOrderId(idempotentKey) + .ifPresent( + paymentEvent -> { + throw new IllegalArgumentException( + "Seed: %s 를 통해 생성된 결제는 이미 %s 상태인 주문입니다." + .formatted( + request.getIdempotencySeed(), + paymentEvent.getPaymentStatus().getDescription())); + }); + } + + private List createPaymentOrders(List products, String idempotencySeed) { + return products.stream().map(product -> createPaymentOrder(product, idempotencySeed)).toList(); + } + + private PaymentOrder createPaymentOrder(Product product, String idempotencySeed) { + return PaymentOrder.builder() + .productId(product.getId()) + .orderId(IdempotentKeyGenerator.generate(idempotencySeed)) + .orderName(product.getName()) + .amount(product.getPrice()) + .build(); + } + + private PaymentEvent createPaymentEvent(PaymentPrepareRequest request, List products) { + String idempotencySeed = request.getIdempotencySeed(); + + return PaymentEvent.builder() + .buyerId(request.getBuyerId()) + .paymentOrders( + products.stream().map(product -> createPaymentOrder(product, idempotencySeed)).toList()) + .orderId(IdempotentKeyGenerator.generate(idempotencySeed)) + .orderName(createOrderName(products)) + .paymentKey(IdempotentKeyGenerator.generate(idempotencySeed)) + .build(); + } + + private String createOrderName(List products) { + return String.join(",", products.stream().map(Product::getName).toList()); + } +} From 4e899936564db8fe28e49d9cdb5310f14d010b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:13:13 +0900 Subject: [PATCH 65/85] =?UTF-8?q?test:=20PaymentDatabaseHelper=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/helper/PaymentDatabaseHelper.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/test/java/com/ordertogether/team14_be/helper/PaymentDatabaseHelper.java diff --git a/src/test/java/com/ordertogether/team14_be/helper/PaymentDatabaseHelper.java b/src/test/java/com/ordertogether/team14_be/helper/PaymentDatabaseHelper.java new file mode 100644 index 00000000..73e969bd --- /dev/null +++ b/src/test/java/com/ordertogether/team14_be/helper/PaymentDatabaseHelper.java @@ -0,0 +1,6 @@ +package com.ordertogether.team14_be.helper; + +public interface PaymentDatabaseHelper { + + void clean(); +} From f853a90df78bd49795d5e754a36c4315ae0a5986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:13:52 +0900 Subject: [PATCH 66/85] =?UTF-8?q?test:=20JpaDatabaseCleanup=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helper/jpa/JpaDatabaseCleanup.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/test/java/com/ordertogether/team14_be/helper/jpa/JpaDatabaseCleanup.java diff --git a/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaDatabaseCleanup.java b/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaDatabaseCleanup.java new file mode 100644 index 00000000..68e609ad --- /dev/null +++ b/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaDatabaseCleanup.java @@ -0,0 +1,51 @@ +package com.ordertogether.team14_be.helper.jpa; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; +import jakarta.persistence.Entity; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import java.util.List; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +@Component +@Profile("test") +public class JpaDatabaseCleanup implements InitializingBean { + + @PersistenceContext private EntityManager entityManager; + + private List tableNames; + + @Override + public void afterPropertiesSet() { + tableNames = + entityManager.getMetamodel().getEntities().stream() + .filter(e -> e.getJavaType().getAnnotation(Entity.class) != null) + .map(e -> removePostfix(e.getName(), "Entity")) + .map(SnakeCaseStrategy.INSTANCE::translate) + .toList(); + } + + private String removePostfix(String entityName, String postfix) { + if (entityName.endsWith(postfix)) { + return entityName.substring(0, entityName.length() - postfix.length()); + } + return entityName; + } + + @Transactional + public void execute() { + entityManager.flush(); + entityManager.createNativeQuery("SET FOREIGN_KEY_CHECKS = 0").executeUpdate(); + + for (String tableName : tableNames) { + entityManager.createNativeQuery("TRUNCATE TABLE " + tableName).executeUpdate(); + entityManager + .createNativeQuery("ALTER TABLE " + tableName + " AUTO_INCREMENT = 1") + .executeUpdate(); + } + entityManager.createNativeQuery("SET FOREIGN_KEY_CHECKS = 1").executeUpdate(); + } +} From 950b16cf76eca96aeea61df8d1e6054b95d570f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:14:08 +0900 Subject: [PATCH 67/85] =?UTF-8?q?test:=20JpaPaymentDatabaseHelper=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helper/jpa/JpaPaymentDatabaseHelper.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/java/com/ordertogether/team14_be/helper/jpa/JpaPaymentDatabaseHelper.java diff --git a/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaPaymentDatabaseHelper.java b/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaPaymentDatabaseHelper.java new file mode 100644 index 00000000..7f292b01 --- /dev/null +++ b/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaPaymentDatabaseHelper.java @@ -0,0 +1,17 @@ +package com.ordertogether.team14_be.helper.jpa; + +import com.ordertogether.team14_be.helper.PaymentDatabaseHelper; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class JpaPaymentDatabaseHelper implements PaymentDatabaseHelper { + + private final JpaDatabaseCleanup jpaDatabaseCleanup; + + @Override + public void clean() { + jpaDatabaseCleanup.execute(); + } +} From 9f5bb093b758260a705d12e1f181476209689da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:14:56 +0900 Subject: [PATCH 68/85] =?UTF-8?q?test:=20test=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/application-test.yml | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/test/resources/application-test.yml diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml new file mode 100644 index 00000000..64108094 --- /dev/null +++ b/src/test/resources/application-test.yml @@ -0,0 +1,27 @@ +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: + url: jdbc:mysql://localhost:3306/delivery_sharing + + jpa: + hibernate: + ddl-auto: create + properties: + hibernate: + format_sql: true + defer-datasource-initialization: true + + sql: + init: + mode: always + +logging: + level: + org: + hibernate: + SQL: debug + orm: + jdbc: + bind: trace \ No newline at end of file From ba92eece534caa63e8025959cc569b2a10b11d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:15:57 +0900 Subject: [PATCH 69/85] =?UTF-8?q?test:=20=EA=B2=B0=EC=A0=9C=20=EC=A4=80?= =?UTF-8?q?=EB=B9=84=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 결제 준비에 대한 정상 케이스 - 중복 결제 준비 요청에 대한 예외 발생 케이스 --- .../PaymentPreparationServiceTest.java | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/test/java/com/ordertogether/team14_be/payment/service/PaymentPreparationServiceTest.java diff --git a/src/test/java/com/ordertogether/team14_be/payment/service/PaymentPreparationServiceTest.java b/src/test/java/com/ordertogether/team14_be/payment/service/PaymentPreparationServiceTest.java new file mode 100644 index 00000000..c71eef59 --- /dev/null +++ b/src/test/java/com/ordertogether/team14_be/payment/service/PaymentPreparationServiceTest.java @@ -0,0 +1,81 @@ +package com.ordertogether.team14_be.payment.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; + +import com.ordertogether.team14_be.helper.PaymentDatabaseHelper; +import com.ordertogether.team14_be.payment.domain.Product; +import com.ordertogether.team14_be.payment.persistence.repository.ProductRepository; +import com.ordertogether.team14_be.payment.web.request.PaymentPrepareRequest; +import com.ordertogether.team14_be.payment.web.response.PaymentPrepareResponse; +import java.math.BigDecimal; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("test") +@SpringBootTest +class PaymentPreparationServiceTest { + + @Autowired private PaymentPreparationService paymentPreparationService; + @Autowired private ProductRepository productRepository; + + @Autowired private PaymentDatabaseHelper paymentDatabaseHelper; + + @BeforeEach + void setup() { + paymentDatabaseHelper.clean(); + + productRepository.saveAll( + List.of( + Product.builder().id(1L).name("Product 1").price(BigDecimal.valueOf(10000)).build(), + Product.builder().id(2L).name("Product 2").price(BigDecimal.valueOf(20000)).build(), + Product.builder().id(3L).name("Product 3").price(BigDecimal.valueOf(30000)).build())); + } + + @Test + @DisplayName("결제 정보를 성공적으로 저장할 수 있다.") + void shouldSuccessWhenNormalRequest() { + // given + PaymentPrepareRequest request = + new PaymentPrepareRequest("idempotency-seed", List.of(1L, 2L, 3L)).addBuyerId(1L); + + // then + PaymentPrepareResponse response = paymentPreparationService.prepare(request); + + // when + assertThat(response.getPaymentEventId()).isNotNull(); + assertThat(response.getBuyerId()).isEqualTo(1L); + assertThat(response.getPaymentOrders()).hasSize(3); + assertThat(response.getOrderId()).isNotNull(); + assertThat(response.getOrderName()).isEqualTo("Product 1,Product 2,Product 3"); + assertThat(response.getPaymentKey()).isNotNull(); + response.getPaymentOrders().stream() + .forEach( + paymentOrder -> { + assertAll( + () -> assertThat(paymentOrder.getPaymentOrderId()).isNotNull(), + () -> assertThat(paymentOrder.getProductId()).isIn(1L, 2L, 3L), + () -> assertThat(paymentOrder.getOrderId()).isEqualTo(response.getOrderId())); + }); + } + + @Test + @DisplayName("이미 저장된 결제 정보는 저장 요청 시, 예외가 발생한다.") + void shouldThrowExceptionWhenAlreadyCompleteRequest() { + // given + PaymentPrepareRequest request = + new PaymentPrepareRequest("idempotency-seed", List.of(1L, 2L, 3L)).addBuyerId(1L); + paymentPreparationService.prepare(request); + + // then + // when + assertThatThrownBy(() -> paymentPreparationService.prepare(request)) + .isInstanceOf(IllegalArgumentException.class); + } +} From 8901a383ace0a83f7c326e6f37adf70bc2f3bace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:17:01 +0900 Subject: [PATCH 70/85] =?UTF-8?q?feat:=20application.yml=20data.sql=20?= =?UTF-8?q?=EC=88=98=ED=96=89=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index a2d13976..e78878b3 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -14,6 +14,11 @@ spring: properties: hibernate: format_sql: true + defer-datasource-initialization: true + + sql: + init: + mode: always logging: level: From 744905b308945135617d4107eee9b69dc9e83df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:17:16 +0900 Subject: [PATCH 71/85] =?UTF-8?q?feat:=20data.sql=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/data.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/main/resources/data.sql diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql new file mode 100644 index 00000000..59b6346f --- /dev/null +++ b/src/main/resources/data.sql @@ -0,0 +1,3 @@ +INSERT INTO product (id, name, price, created_at, modified_at, created_by, modified_by) VALUES (1, 'Product 1', 10000, now(), now(), 1, 1); +INSERT INTO product (id, name, price, created_at, modified_at, created_by, modified_by) VALUES (2, 'Product 2', 20000, now(), now(), 1, 1); +INSERT INTO product (id, name, price, created_at, modified_at, created_by, modified_by) VALUES (3, 'Product 3', 30000, now(), now(), 1, 1); From b996d58a4800bc67b7a31e41722f164eb7043edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:18:34 +0900 Subject: [PATCH 72/85] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20Repository?= =?UTF-8?q?=20=EB=B9=88=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/config/PersistenceConfig.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main/java/com/ordertogether/team14_be/config/PersistenceConfig.java b/src/main/java/com/ordertogether/team14_be/config/PersistenceConfig.java index d9de0f5e..8d24b129 100644 --- a/src/main/java/com/ordertogether/team14_be/config/PersistenceConfig.java +++ b/src/main/java/com/ordertogether/team14_be/config/PersistenceConfig.java @@ -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; @@ -15,4 +24,24 @@ public class PersistenceConfig { public AuditorAware 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); + } } From e76e5a545352b61dc4409ecb1edf164b0b108c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:19:05 +0900 Subject: [PATCH 73/85] =?UTF-8?q?feat:=20PaymentController=20=EA=B2=B0?= =?UTF-8?q?=EC=A0=9C=20=EC=A4=80=EB=B9=84=20=EC=97=94=EB=93=9C=ED=8F=AC?= =?UTF-8?q?=EC=9D=B8=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/PaymentController.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/web/controller/PaymentController.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/controller/PaymentController.java b/src/main/java/com/ordertogether/team14_be/payment/web/controller/PaymentController.java new file mode 100644 index 00000000..5b17246e --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/web/controller/PaymentController.java @@ -0,0 +1,31 @@ +package com.ordertogether.team14_be.payment.web.controller; + +import com.ordertogether.team14_be.common.web.response.ApiResponse; +import com.ordertogether.team14_be.payment.service.PaymentPreparationService; +import com.ordertogether.team14_be.payment.web.request.PaymentPrepareRequest; +import com.ordertogether.team14_be.payment.web.response.PaymentPrepareResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/v1/payments") +@RequiredArgsConstructor +public class PaymentController { + + private final PaymentPreparationService paymentPreparationService; + + @PostMapping + public ResponseEntity> preparePayment( + @RequestBody PaymentPrepareRequest request) { + // todo: 1L -> UserDetail.getUserId() + request.addBuyerId(1L); + PaymentPrepareResponse data = paymentPreparationService.prepare(request); + + return ResponseEntity.ok(ApiResponse.with(HttpStatus.OK, "결제 정보를 저장하였습니다.", data)); + } +} From e7a0993e7c687df52de57e4fdf72ac7a58bb7cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 02:19:30 +0900 Subject: [PATCH 74/85] =?UTF-8?q?feat:=20Api=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EB=B3=B8=EB=AC=B8=20=EA=B5=AC=EC=A1=B0=20=EC=84=A0=EC=96=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/web/response/ApiResponse.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/common/web/response/ApiResponse.java diff --git a/src/main/java/com/ordertogether/team14_be/common/web/response/ApiResponse.java b/src/main/java/com/ordertogether/team14_be/common/web/response/ApiResponse.java new file mode 100644 index 00000000..23ccb295 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/common/web/response/ApiResponse.java @@ -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 { + + private Integer status; + private String message; + private T data; + + public static ApiResponse with(HttpStatus httpStatus, String message, @Nullable T data) { + return new ApiResponse<>(httpStatus.value(), message, data); + } +} From 0faa40f95c33d24208055042af211686765b15d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 16:59:58 +0900 Subject: [PATCH 75/85] =?UTF-8?q?style:=20=ED=8C=8C=EC=9D=BC=20=EB=81=9D?= =?UTF-8?q?=20=EB=B9=88=20=EC=A4=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/application-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index 64108094..daf41535 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -24,4 +24,4 @@ logging: SQL: debug orm: jdbc: - bind: trace \ No newline at end of file + bind: trace From cdab4b18743218b6cb2d0849ed84a77819271bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 20:07:06 +0900 Subject: [PATCH 76/85] =?UTF-8?q?feat:=20DTO=20record=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/response/PaymentOrderResponse.java | 33 ++++------------- .../web/response/PaymentPrepareResponse.java | 37 +++++++------------ 2 files changed, 22 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentOrderResponse.java b/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentOrderResponse.java index 352e8974..2e1faf5a 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentOrderResponse.java +++ b/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentOrderResponse.java @@ -1,32 +1,15 @@ package com.ordertogether.team14_be.payment.web.response; import com.ordertogether.team14_be.payment.domain.PaymentOrder; -import lombok.Builder; -import lombok.Getter; -import lombok.ToString; - -@Getter -@Builder -@ToString -public class PaymentOrderResponse { - - private final Long paymentOrderId; - - private final Long productId; - - private final String orderId; - - private final String orderName; - - private final Long amount; +public record PaymentOrderResponse( + Long paymentOrderId, Long productId, String orderId, String orderName, Long amount) { public static PaymentOrderResponse from(PaymentOrder paymentOrder) { - return PaymentOrderResponse.builder() - .paymentOrderId(paymentOrder.getId()) - .productId(paymentOrder.getProductId()) - .orderId(paymentOrder.getOrderId()) - .orderName(paymentOrder.getOrderName()) - .amount(paymentOrder.getAmount().longValue()) - .build(); + return new PaymentOrderResponse( + paymentOrder.getId(), + paymentOrder.getProductId(), + paymentOrder.getOrderId(), + paymentOrder.getOrderName(), + paymentOrder.getAmount().longValue()); } } diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentPrepareResponse.java b/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentPrepareResponse.java index 566809a1..6f96b2be 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentPrepareResponse.java +++ b/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentPrepareResponse.java @@ -3,31 +3,22 @@ import com.ordertogether.team14_be.payment.domain.PaymentEvent; import com.ordertogether.team14_be.payment.domain.PaymentOrder; import java.util.List; -import lombok.Builder; -import lombok.Getter; -import lombok.ToString; - -@Getter -@Builder -@ToString -public class PaymentPrepareResponse { - - private Long paymentEventId; - private Long buyerId; - private List paymentOrders; - private String orderId; - private String orderName; - private String paymentKey; +public record PaymentPrepareResponse( + Long paymentEventId, + Long buyerId, + List paymentOrders, + String orderId, + String orderName, + String paymentKey) { public static PaymentPrepareResponse of( PaymentEvent paymentEvent, List paymentOrders) { - return PaymentPrepareResponse.builder() - .paymentEventId(paymentEvent.getId()) - .buyerId(paymentEvent.getBuyerId()) - .paymentOrders(paymentOrders.stream().map(PaymentOrderResponse::from).toList()) - .orderId(paymentEvent.getOrderId()) - .orderName(paymentEvent.getOrderName()) - .paymentKey(paymentEvent.getPaymentKey()) - .build(); + return new PaymentPrepareResponse( + paymentEvent.getId(), + paymentEvent.getBuyerId(), + paymentOrders.stream().map(PaymentOrderResponse::from).toList(), + paymentEvent.getOrderId(), + paymentEvent.getOrderName(), + paymentEvent.getPaymentKey()); } } From 3719428bdc824d917ed4096db319e7edf45092d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 20:07:33 +0900 Subject: [PATCH 77/85] =?UTF-8?q?rename:=20package=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit memebr -> member --- .../application/service/MemberService.java | 6 +++--- .../{memebr => member}/persistence/MemberRepository.java | 4 ++-- .../{memebr => member}/persistence/entity/Member.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename src/main/java/com/ordertogether/team14_be/{memebr => member}/application/service/MemberService.java (71%) rename src/main/java/com/ordertogether/team14_be/{memebr => member}/persistence/MemberRepository.java (69%) rename src/main/java/com/ordertogether/team14_be/{memebr => member}/persistence/entity/Member.java (95%) diff --git a/src/main/java/com/ordertogether/team14_be/memebr/application/service/MemberService.java b/src/main/java/com/ordertogether/team14_be/member/application/service/MemberService.java similarity index 71% rename from src/main/java/com/ordertogether/team14_be/memebr/application/service/MemberService.java rename to src/main/java/com/ordertogether/team14_be/member/application/service/MemberService.java index ee6346b8..6d9c51d3 100644 --- a/src/main/java/com/ordertogether/team14_be/memebr/application/service/MemberService.java +++ b/src/main/java/com/ordertogether/team14_be/member/application/service/MemberService.java @@ -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; diff --git a/src/main/java/com/ordertogether/team14_be/memebr/persistence/MemberRepository.java b/src/main/java/com/ordertogether/team14_be/member/persistence/MemberRepository.java similarity index 69% rename from src/main/java/com/ordertogether/team14_be/memebr/persistence/MemberRepository.java rename to src/main/java/com/ordertogether/team14_be/member/persistence/MemberRepository.java index cea83bb6..8cc1815a 100644 --- a/src/main/java/com/ordertogether/team14_be/memebr/persistence/MemberRepository.java +++ b/src/main/java/com/ordertogether/team14_be/member/persistence/MemberRepository.java @@ -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; diff --git a/src/main/java/com/ordertogether/team14_be/memebr/persistence/entity/Member.java b/src/main/java/com/ordertogether/team14_be/member/persistence/entity/Member.java similarity index 95% rename from src/main/java/com/ordertogether/team14_be/memebr/persistence/entity/Member.java rename to src/main/java/com/ordertogether/team14_be/member/persistence/entity/Member.java index d5338f95..cb06b470 100644 --- a/src/main/java/com/ordertogether/team14_be/memebr/persistence/entity/Member.java +++ b/src/main/java/com/ordertogether/team14_be/member/persistence/entity/Member.java @@ -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; From a2abac859338480f495987267f12d8cffd512ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 20:08:48 +0900 Subject: [PATCH 78/85] =?UTF-8?q?style:=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e78878b3..6b783ffd 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,7 +3,7 @@ spring: name: Team14_BE datasource: - driver-class-name: ${DRIVER_CALSS_NAME} + driver-class-name: ${DRIVER_CLASS_NAME} username: ${USERNAME} password: url: ${URL} @@ -43,4 +43,4 @@ kakao: key: jwt: - secreat-key: ${JWT_SCREAT_KEY} + secret-key: ${JWT_SECRET_KEY} From 09f1e90895ffcc3a6af9dbedbc31d6a1deb49c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 20:09:13 +0900 Subject: [PATCH 79/85] =?UTF-8?q?rename:=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/auth/application/service/AuthService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ordertogether/team14_be/auth/application/service/AuthService.java b/src/main/java/com/ordertogether/team14_be/auth/application/service/AuthService.java index b94808cd..7ec5e4d1 100644 --- a/src/main/java/com/ordertogether/team14_be/auth/application/service/AuthService.java +++ b/src/main/java/com/ordertogether/team14_be/auth/application/service/AuthService.java @@ -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; From ab1c23f6965b1eb3b34fe83a48bcacb658196b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 20:09:48 +0900 Subject: [PATCH 80/85] =?UTF-8?q?chore:=20spring=20security=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 사용하지 않음 --- build.gradle | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 77a5b8f7..c9e5761f 100644 --- a/build.gradle +++ b/build.gradle @@ -34,16 +34,15 @@ 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}" + runtimeOnly "io.jsonwebtoken:jjwt-impl:${jjwt_version}" + runtimeOnly "io.jsonwebtoken:jjwt-jackson:${jjwt_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' @@ -55,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' } From 9edc26d180f743875bda7b210544d28910131f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 20:10:16 +0900 Subject: [PATCH 81/85] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=EB=A6=B0?= =?UTF-8?q?=ED=8A=B8=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/converter/AbstractCodedEnumConverter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java b/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java index f4dc9b85..6bad1307 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java +++ b/src/main/java/com/ordertogether/team14_be/spot/converter/AbstractCodedEnumConverter.java @@ -2,7 +2,6 @@ import jakarta.persistence.AttributeConverter; import jakarta.persistence.Converter; - import java.util.Arrays; import java.util.Objects; From 883d9eb3800f1fc3f206a977c267cf416552d625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 20:10:31 +0900 Subject: [PATCH 82/85] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=EB=A6=B0?= =?UTF-8?q?=ED=8A=B8=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ordertogether/team14_be/spot/service/SpotService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java b/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java index 09982254..a16a6dc4 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java +++ b/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java @@ -53,8 +53,7 @@ public SpotDto updateSpot(SpotDto spotDto) { @Transactional public void deleteSpot(Long id) { Optional spotToDelete = spotRepository.findByIdAndIsDeletedFalse(id); - spotToDelete.ifPresent( - Spot::delete); + spotToDelete.ifPresent(Spot::delete); } // Service Layer에서 toDto만들어서 매핑시키기 From b7d424e640706d4ab9f8cc2fee2d3c65ab0da4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 20:10:50 +0900 Subject: [PATCH 83/85] =?UTF-8?q?feat:=20application-test.yml=20=EB=88=84?= =?UTF-8?q?=EB=9D=BD=EB=90=9C=20=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/application-test.yml | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index daf41535..6b783ffd 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -1,9 +1,12 @@ spring: + application: + name: Team14_BE + datasource: - driver-class-name: com.mysql.cj.jdbc.Driver - username: root + driver-class-name: ${DRIVER_CLASS_NAME} + username: ${USERNAME} password: - url: jdbc:mysql://localhost:3306/delivery_sharing + url: ${URL} jpa: hibernate: @@ -25,3 +28,19 @@ logging: orm: jdbc: bind: trace + +kakao: + client-id: ${KAKAO_CLIENT_ID} + redirect-url: ${KAKAO_REDIRECT_URL} + + auth: + token: + url: ${KAKAO_AUTH_TOKEN_URL} + + user: + api: + url: ${KAKAO_USER_API_URL} + +key: + jwt: + secret-key: ${JWT_SECRET_KEY} From 8b60659194d75c0121609a8837598636ad7c2d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 20:11:55 +0900 Subject: [PATCH 84/85] =?UTF-8?q?feat:=20=EC=95=A0=ED=94=8C=EB=A6=AC?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=85=98=20=EC=BB=A8=ED=85=8D=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=A1=9C=EB=93=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?test=20=ED=94=84=EB=A1=9C=ED=8C=8C=EC=9D=BC=20=ED=99=9C?= =?UTF-8?q?=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ordertogether/team14_be/Team14BeApplicationTests.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/com/ordertogether/team14_be/Team14BeApplicationTests.java b/src/test/java/com/ordertogether/team14_be/Team14BeApplicationTests.java index ff77c428..fd45e8ba 100644 --- a/src/test/java/com/ordertogether/team14_be/Team14BeApplicationTests.java +++ b/src/test/java/com/ordertogether/team14_be/Team14BeApplicationTests.java @@ -2,8 +2,10 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; @SpringBootTest +@ActiveProfiles("test") class Team14BeApplicationTests { @Test From 1261c7b81a23b128f5c6e438bc3665fc3c106bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Fri, 27 Sep 2024 20:12:25 +0900 Subject: [PATCH 85/85] =?UTF-8?q?test:=20=EA=B2=B0=EC=A0=9C=20=EC=A4=80?= =?UTF-8?q?=EB=B9=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9C=A0=EC=A7=80?= =?UTF-8?q?=EB=B3=B4=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DTO 가 record 타입으로 변경됨에 따른 수정 --- .../PaymentPreparationServiceTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/ordertogether/team14_be/payment/service/PaymentPreparationServiceTest.java b/src/test/java/com/ordertogether/team14_be/payment/service/PaymentPreparationServiceTest.java index c71eef59..30ac7813 100644 --- a/src/test/java/com/ordertogether/team14_be/payment/service/PaymentPreparationServiceTest.java +++ b/src/test/java/com/ordertogether/team14_be/payment/service/PaymentPreparationServiceTest.java @@ -49,19 +49,19 @@ void shouldSuccessWhenNormalRequest() { PaymentPrepareResponse response = paymentPreparationService.prepare(request); // when - assertThat(response.getPaymentEventId()).isNotNull(); - assertThat(response.getBuyerId()).isEqualTo(1L); - assertThat(response.getPaymentOrders()).hasSize(3); - assertThat(response.getOrderId()).isNotNull(); - assertThat(response.getOrderName()).isEqualTo("Product 1,Product 2,Product 3"); - assertThat(response.getPaymentKey()).isNotNull(); - response.getPaymentOrders().stream() + assertThat(response.paymentEventId()).isNotNull(); + assertThat(response.buyerId()).isEqualTo(1L); + assertThat(response.paymentOrders()).hasSize(3); + assertThat(response.orderId()).isNotNull(); + assertThat(response.orderName()).isEqualTo("Product 1,Product 2,Product 3"); + assertThat(response.paymentKey()).isNotNull(); + response.paymentOrders().stream() .forEach( paymentOrder -> { assertAll( - () -> assertThat(paymentOrder.getPaymentOrderId()).isNotNull(), - () -> assertThat(paymentOrder.getProductId()).isIn(1L, 2L, 3L), - () -> assertThat(paymentOrder.getOrderId()).isEqualTo(response.getOrderId())); + () -> assertThat(paymentOrder.paymentOrderId()).isNotNull(), + () -> assertThat(paymentOrder.productId()).isIn(1L, 2L, 3L), + () -> assertThat(paymentOrder.orderId()).isEqualTo(response.orderId())); }); }