diff --git a/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java b/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java index 24e3cc8..4f47145 100644 --- a/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java +++ b/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java @@ -22,6 +22,7 @@ import com.jangburich.domain.store.domain.StoreTeam; import com.jangburich.domain.store.domain.repository.StoreRepository; import com.jangburich.domain.store.domain.repository.StoreTeamRepository; +import com.jangburich.domain.store.exception.StoreNotFoundException; import com.jangburich.domain.team.domain.Team; import com.jangburich.domain.team.domain.repository.TeamRepository; import com.jangburich.global.error.DefaultNullPointerException; @@ -88,12 +89,13 @@ public ReadyResponse payReady(String userId, PayRequest payRequest) { readyResponseResponseEntity = template.postForEntity(url, requestEntity, ReadyResponse.class); Team team = teamRepository.findById(payRequest.teamId()).orElseThrow(() -> new TeamNotFoundException()); - + Store store = storeRepository.findById(payRequest.storeId()).orElseThrow(() -> new StoreNotFoundException()); TeamChargeHistory teamChargeHistory = TeamChargeHistory.builder() .transactionId(readyResponseResponseEntity.getBody().tid()) .paymentAmount(Integer.valueOf(payRequest.totalAmount())) .paymentChargeStatus(PaymentChargeStatus.PENDING) .team(team) + .store(store) .build(); teamChargeHistoryRepository.save(teamChargeHistory); diff --git a/src/main/java/com/jangburich/domain/payment/domain/TeamChargeHistory.java b/src/main/java/com/jangburich/domain/payment/domain/TeamChargeHistory.java index 0732f6f..49e6ae3 100644 --- a/src/main/java/com/jangburich/domain/payment/domain/TeamChargeHistory.java +++ b/src/main/java/com/jangburich/domain/payment/domain/TeamChargeHistory.java @@ -1,8 +1,9 @@ package com.jangburich.domain.payment.domain; import com.jangburich.domain.common.BaseEntity; +import com.jangburich.domain.store.domain.Store; import com.jangburich.domain.team.domain.Team; -import com.jangburich.domain.user.domain.User; + import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -23,35 +24,40 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class TeamChargeHistory extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", updatable = false) - private Long id; - - @Column(name = "transaction_id") - private String transactionId; - - @Column(name = "payment_amount") - private Integer paymentAmount; - - @Enumerated(EnumType.STRING) - @Column(name = "payment_charge_status", length = 20) - private PaymentChargeStatus paymentChargeStatus; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "team_id") - private Team team; - - @Builder - public TeamChargeHistory(String transactionId, Integer paymentAmount, PaymentChargeStatus paymentChargeStatus, - Team team) { - this.transactionId = transactionId; - this.paymentAmount = paymentAmount; - this.paymentChargeStatus = paymentChargeStatus; - this.team = team; - } - - public void completePaymentChargeStatus() { - this.paymentChargeStatus = PaymentChargeStatus.COMPLETED; - } + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", updatable = false) + private Long id; + + @Column(name = "transaction_id") + private String transactionId; + + @Column(name = "payment_amount") + private Integer paymentAmount; + + @Enumerated(EnumType.STRING) + @Column(name = "payment_charge_status", length = 20) + private PaymentChargeStatus paymentChargeStatus; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "team_id") + private Team team; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "store_id") + private Store store; + + @Builder + public TeamChargeHistory(String transactionId, Integer paymentAmount, PaymentChargeStatus paymentChargeStatus, + Team team, Store store) { + this.transactionId = transactionId; + this.paymentAmount = paymentAmount; + this.paymentChargeStatus = paymentChargeStatus; + this.team = team; + this.store = store; + } + + public void completePaymentChargeStatus() { + this.paymentChargeStatus = PaymentChargeStatus.COMPLETED; + } } diff --git a/src/main/java/com/jangburich/domain/payment/domain/repository/TeamChargeHistoryRepository.java b/src/main/java/com/jangburich/domain/payment/domain/repository/TeamChargeHistoryRepository.java index 1ce99ae..883a176 100644 --- a/src/main/java/com/jangburich/domain/payment/domain/repository/TeamChargeHistoryRepository.java +++ b/src/main/java/com/jangburich/domain/payment/domain/repository/TeamChargeHistoryRepository.java @@ -1,9 +1,5 @@ package com.jangburich.domain.payment.domain.repository; -import com.jangburich.domain.payment.domain.TeamChargeHistory; -import com.jangburich.domain.payment.domain.TeamChargeHistoryResponse; -import com.jangburich.domain.team.domain.Team; - import java.util.Optional; import org.springframework.data.domain.Page; @@ -11,9 +7,17 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import com.jangburich.domain.payment.domain.TeamChargeHistory; +import com.jangburich.domain.payment.domain.TeamChargeHistoryResponse; +import com.jangburich.domain.store.domain.Store; +import com.jangburich.domain.store.domain.StoreChargeHistoryResponse; +import com.jangburich.domain.team.domain.Team; + @Repository public interface TeamChargeHistoryRepository extends JpaRepository { - Optional findByTransactionId(String tid); + Optional findByTransactionId(String tid); + + Page findAllByTeam(Team team, Pageable pageable); - Page findAllByTeam(Team team, Pageable pageable); + Page findAllByStore(Store store, Pageable pageable); } diff --git a/src/main/java/com/jangburich/domain/store/domain/StoreChargeHistoryResponse.java b/src/main/java/com/jangburich/domain/store/domain/StoreChargeHistoryResponse.java new file mode 100644 index 0000000..74235f8 --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/domain/StoreChargeHistoryResponse.java @@ -0,0 +1,21 @@ +package com.jangburich.domain.store.domain; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +import com.querydsl.core.annotations.QueryProjection; + +public record StoreChargeHistoryResponse( + Long id, + LocalDateTime createdAt, + String teamName, + Integer paymentAmount +) { + @QueryProjection + public StoreChargeHistoryResponse(Long id, LocalDateTime createdAt, String teamName, Integer paymentAmount) { + this.id = id; + this.createdAt = createdAt; + this.teamName = teamName; + this.paymentAmount = paymentAmount; + } +} diff --git a/src/main/java/com/jangburich/domain/store/domain/controller/StoreController.java b/src/main/java/com/jangburich/domain/store/domain/controller/StoreController.java index a60bd1e..f55caf1 100644 --- a/src/main/java/com/jangburich/domain/store/domain/controller/StoreController.java +++ b/src/main/java/com/jangburich/domain/store/domain/controller/StoreController.java @@ -42,7 +42,7 @@ public class StoreController { private final StoreService storeService; @Operation(summary = "카테고리 별 가게 목록 조회", description = "카테고리 별로 가게 목록을 조회합니다.") - @GetMapping + @GetMapping("/category") public ResponseCustom> searchByCategory( Authentication authentication, @RequestParam(required = false, defaultValue = "3") Integer searchRadius, @@ -94,7 +94,7 @@ public ResponseCustom updateStore(Authentication authentication, @PathV } @Operation(summary = "가게 정보 조회", description = "가게 상세 정보를 조회합니다.") - @GetMapping("/{storeId}") + @GetMapping("") public ResponseCustom getStoreInfo(Authentication authentication) { CustomOAuthUser customOAuth2User = (CustomOAuthUser)authentication.getPrincipal(); return ResponseCustom.OK(storeService.getStoreInfo(customOAuth2User)); @@ -116,4 +116,10 @@ public ResponseCustom getPaymentGroupDetail(Authenti return ResponseCustom.OK( storeService.getPaymentGroupDetail(AuthenticationParser.parseUserId(authentication), teamId, pageable)); } + + @Operation(summary = "결제 내역 조회", description = "가게에서 일어난 결제 내역을 조회합니다.") + @GetMapping("/payment_history") + public ResponseCustom getPaymentHistory(Authentication authentication, Pageable pageable) { + return ResponseCustom.OK(storeService.getPaymentHistory(AuthenticationParser.parseUserId(authentication), pageable)); + } } \ No newline at end of file diff --git a/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java b/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java index 324e12d..961eaa0 100644 --- a/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java +++ b/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java @@ -14,6 +14,7 @@ import com.jangburich.domain.store.domain.Category; import com.jangburich.domain.store.domain.Store; import com.jangburich.domain.store.domain.StoreAdditionalInfoCreateRequestDTO; +import com.jangburich.domain.store.domain.StoreChargeHistoryResponse; import com.jangburich.domain.store.domain.StoreCreateRequestDTO; import com.jangburich.domain.store.domain.StoreGetResponseDTO; import com.jangburich.domain.store.domain.StoreTeam; @@ -209,6 +210,21 @@ public PaymentGroupDetailResponse getPaymentGroupDetail(String userId, Long team Page chargeHistoryRepositoryAllByTeam = teamChargeHistoryRepository.findAllByTeam( team, pageable); - return PaymentGroupDetailResponse.create(team.getName(), storeTeam.getPoint(), storeTeam.getRemainPoint(), teamLeader, chargeHistoryRepositoryAllByTeam); + return PaymentGroupDetailResponse.create(team.getName(), storeTeam.getPoint(), storeTeam.getRemainPoint(), + teamLeader, chargeHistoryRepositoryAllByTeam); + } + + public Page getPaymentHistory(String userId, Pageable pageable) { + User user = userRepository.findByProviderId(userId) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Owner owner = ownerRepository.findByUser(user) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Store store = storeRepository.findByOwner(owner) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Page historyResponses = teamChargeHistoryRepository.findAllByStore(store, pageable); + return historyResponses; } } diff --git a/src/main/java/com/jangburich/domain/store/exception/StoreNotFoundException.java b/src/main/java/com/jangburich/domain/store/exception/StoreNotFoundException.java new file mode 100644 index 0000000..f9f1380 --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/exception/StoreNotFoundException.java @@ -0,0 +1,7 @@ +package com.jangburich.domain.store.exception; + +public class StoreNotFoundException extends RuntimeException{ + public StoreNotFoundException() { + super("해당 가게를 찾을 수 없습니다."); + } +}