diff --git a/src/main/java/com/jangburich/domain/menu/domain/controller/MenuController.java b/src/main/java/com/jangburich/domain/menu/domain/controller/MenuController.java index 79a4327..8250686 100644 --- a/src/main/java/com/jangburich/domain/menu/domain/controller/MenuController.java +++ b/src/main/java/com/jangburich/domain/menu/domain/controller/MenuController.java @@ -17,6 +17,7 @@ import com.jangburich.domain.menu.domain.MenuUpdateRequestDTO; import com.jangburich.domain.menu.domain.service.MenuService; import com.jangburich.domain.oauth.domain.CustomOAuthUser; +import com.jangburich.global.payload.Message; import com.jangburich.global.payload.ResponseCustom; import io.swagger.v3.oas.annotations.tags.Tag; @@ -31,31 +32,31 @@ public class MenuController { private final MenuService menuService; @PostMapping("/register") - public ResponseCustom registerMenu(Authentication authentication, + public ResponseCustom registerMenu(Authentication authentication, @RequestBody MenuCreateRequestDTO menuCreateRequestDTO) { CustomOAuthUser customOAuthUser = (CustomOAuthUser)authentication.getPrincipal(); menuService.registerMenu(customOAuthUser, menuCreateRequestDTO); - return ResponseCustom.OK("success"); + return ResponseCustom.OK(Message.builder().message("success").build()); } @PatchMapping("/update/{id}") - public ResponseCustom updateMenu(Authentication authentication, @PathVariable Long id, + public ResponseCustom updateMenu(Authentication authentication, @PathVariable Long id, @RequestBody MenuUpdateRequestDTO menuUpdateRequestDTO) { CustomOAuthUser customOAuthUser = (CustomOAuthUser)authentication.getPrincipal(); menuService.updateMenu(customOAuthUser, id, menuUpdateRequestDTO); - return ResponseCustom.OK("success"); + return ResponseCustom.OK(Message.builder().message("success").build()); } @DeleteMapping("/{id}") - public ResponseCustom deleteMenu(Authentication authentication, @PathVariable Long id) { + public ResponseCustom deleteMenu(Authentication authentication, @PathVariable Long id) { CustomOAuthUser customOAuthUser = (CustomOAuthUser)authentication.getPrincipal(); menuService.deleteMenu(customOAuthUser, id); - return ResponseCustom.OK("success"); + return ResponseCustom.OK(Message.builder().message("success").build()); } @GetMapping("") public ResponseCustom> getMenu(Authentication authentication) { - CustomOAuthUser customOAuthUser = (CustomOAuthUser) authentication.getPrincipal(); + CustomOAuthUser customOAuthUser = (CustomOAuthUser)authentication.getPrincipal(); List menu = menuService.getMenu(customOAuthUser); return ResponseCustom.OK(menu); } 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 a4d2ee1..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); @@ -130,7 +132,8 @@ public ApproveResponse payApprove(String pgToken) { .orElse(null); if (storeTeam != null) { - storeTeam.updatePoint(teamChargeHistory.getPaymentAmount()); + storeTeam.addPoint(teamChargeHistory.getPaymentAmount()); + storeTeam.addRemainPoint(teamChargeHistory.getPaymentAmount()); } else { storeTeamRepository.save( StoreTeam.create(teamChargeHistory.getTeam(), store, teamChargeHistory.getPaymentAmount())); 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/TeamChargeHistoryResponse.java b/src/main/java/com/jangburich/domain/payment/domain/TeamChargeHistoryResponse.java new file mode 100644 index 0000000..3f9f663 --- /dev/null +++ b/src/main/java/com/jangburich/domain/payment/domain/TeamChargeHistoryResponse.java @@ -0,0 +1,22 @@ +package com.jangburich.domain.payment.domain; + +import com.querydsl.core.annotations.QueryProjection; + +import lombok.Builder; + +@Builder +public record TeamChargeHistoryResponse( + Long id, + String transactionId, + Integer paymentAmount, + PaymentChargeStatus paymentChargeStatus +) { + @QueryProjection + public TeamChargeHistoryResponse(Long id, String transactionId, Integer paymentAmount, + PaymentChargeStatus paymentChargeStatus) { + this.id = id; + this.transactionId = transactionId; + this.paymentAmount = paymentAmount; + this.paymentChargeStatus = paymentChargeStatus; + } +} 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 1a43279..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,11 +1,23 @@ package com.jangburich.domain.payment.domain.repository; -import com.jangburich.domain.payment.domain.TeamChargeHistory; import java.util.Optional; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; 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 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/StoreTeam.java b/src/main/java/com/jangburich/domain/store/domain/StoreTeam.java index 73db450..313380c 100644 --- a/src/main/java/com/jangburich/domain/store/domain/StoreTeam.java +++ b/src/main/java/com/jangburich/domain/store/domain/StoreTeam.java @@ -37,15 +37,27 @@ public class StoreTeam extends BaseEntity { @Column(name = "point") private Integer point; - public void updatePoint(Integer point) { + @Column(name = "remain_point") + private Integer remainPoint; + + public void addPoint(Integer point) { this.point += point; } + public void addRemainPoint(Integer point) { + this.remainPoint += point; + } + + public void subRemainPoint(Integer point) { + this.remainPoint -= point; + } + public static StoreTeam create(Team team, Store store, Integer point) { StoreTeam storeTeam = new StoreTeam(); storeTeam.setTeam(team); storeTeam.setStore(store); storeTeam.setPoint(point); + storeTeam.setRemainPoint(point); return storeTeam; } } \ No newline at end of file diff --git a/src/main/java/com/jangburich/domain/store/domain/StoreTeamResponseDTO.java b/src/main/java/com/jangburich/domain/store/domain/StoreTeamResponseDTO.java new file mode 100644 index 0000000..34ecc75 --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/domain/StoreTeamResponseDTO.java @@ -0,0 +1,27 @@ +package com.jangburich.domain.store.domain; + +import com.querydsl.core.annotations.QueryProjection; + +import lombok.Builder; + +@Builder +public record StoreTeamResponseDTO( + Long id, + Integer remainPoint, + Long teamId, + String teamName, + String teamDescription, + Long storeId + +) { + @QueryProjection + public StoreTeamResponseDTO(Long id, Integer remainPoint, Long teamId, String teamName, String teamDescription, + Long storeId) { + this.id = id; + this.remainPoint = remainPoint; + this.teamId = teamId; + this.teamName = teamName; + this.teamDescription = teamDescription; + this.storeId = storeId; + } +} 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 cb60fb4..67c21d3 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 @@ -1,9 +1,5 @@ package com.jangburich.domain.store.domain.controller; -import com.jangburich.domain.store.domain.Category; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchCondition; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchConditionWithType; -import com.jangburich.domain.store.domain.dto.response.SearchStoresResponse; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.security.core.Authentication; @@ -18,13 +14,20 @@ import org.springframework.web.bind.annotation.RestController; import com.jangburich.domain.oauth.domain.CustomOAuthUser; +import com.jangburich.domain.store.domain.Category; import com.jangburich.domain.store.domain.StoreAdditionalInfoCreateRequestDTO; import com.jangburich.domain.store.domain.StoreCreateRequestDTO; import com.jangburich.domain.store.domain.StoreGetResponseDTO; +import com.jangburich.domain.store.domain.StoreTeamResponseDTO; import com.jangburich.domain.store.domain.StoreUpdateRequestDTO; +import com.jangburich.domain.store.domain.dto.condition.StoreSearchCondition; +import com.jangburich.domain.store.domain.dto.condition.StoreSearchConditionWithType; +import com.jangburich.domain.store.domain.dto.response.PaymentGroupDetailResponse; +import com.jangburich.domain.store.domain.dto.response.SearchStoresResponse; import com.jangburich.domain.store.domain.service.StoreService; import com.jangburich.global.payload.Message; import com.jangburich.global.payload.ResponseCustom; +import com.jangburich.utils.parser.AuthenticationParser; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -39,26 +42,28 @@ 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, - @RequestParam(required = false, defaultValue = "ALL") Category category, - @ModelAttribute StoreSearchCondition storeSearchCondition, - Pageable pageable + Authentication authentication, + @RequestParam(required = false, defaultValue = "3") Integer searchRadius, + @RequestParam(required = false, defaultValue = "ALL") Category category, + @ModelAttribute StoreSearchCondition storeSearchCondition, + Pageable pageable ) { - return ResponseCustom.OK(storeService.searchByCategory(authentication, searchRadius, category, storeSearchCondition, pageable)); + return ResponseCustom.OK( + storeService.searchByCategory(authentication, searchRadius, category, storeSearchCondition, pageable)); } @Operation(summary = "매장 찾기(검색)", description = "검색어와 매장 유형에 맞는 매장을 검색합니다.") @GetMapping("/search") public ResponseCustom> searchStores( - Authentication authentication, - @RequestParam(required = false, defaultValue = "") String keyword, - @ModelAttribute StoreSearchConditionWithType storeSearchConditionWithType, - Pageable pageable + Authentication authentication, + @RequestParam(required = false, defaultValue = "") String keyword, + @ModelAttribute StoreSearchConditionWithType storeSearchConditionWithType, + Pageable pageable ) { - return ResponseCustom.OK(storeService.searchStores(authentication, keyword, storeSearchConditionWithType, pageable)); + return ResponseCustom.OK( + storeService.searchStores(authentication, keyword, storeSearchConditionWithType, pageable)); } @Operation(summary = "가게 등록", description = "신규 파트너 가게를 등록합니다.") @@ -66,38 +71,55 @@ public ResponseCustom> searchStores( public ResponseCustom createStore(Authentication authentication, @RequestBody StoreCreateRequestDTO storeCreateRequestDTO) { CustomOAuthUser customOAuth2User = (CustomOAuthUser)authentication.getPrincipal(); - storeService.CreateStore(customOAuth2User, storeCreateRequestDTO); - return ResponseCustom.OK(Message.builder() - .message("success") - .build()); + storeService.createStore(customOAuth2User, storeCreateRequestDTO); + return ResponseCustom.OK(Message.builder().message("success").build()); } @Operation(summary = "가게 추가정보 저장", description = "예약 가능 여부, 최소 선결제 금액, 선결제 사용 기간을 저장합니다.") @PostMapping("/create/additionalInfo") - public ResponseCustom createAdditionalInfo(Authentication authentication, @RequestBody - StoreAdditionalInfoCreateRequestDTO storeAdditionalInfoCreateRequestDTO) { + public ResponseCustom createAdditionalInfo(Authentication authentication, + @RequestBody StoreAdditionalInfoCreateRequestDTO storeAdditionalInfoCreateRequestDTO) { CustomOAuthUser customOAuthUser = (CustomOAuthUser)authentication.getPrincipal(); - storeService.CreateAdditionalInfo(customOAuthUser, storeAdditionalInfoCreateRequestDTO); - return ResponseCustom.OK(Message.builder() - .message("success") - .build()); + storeService.createAdditionalInfo(customOAuthUser, storeAdditionalInfoCreateRequestDTO); + return ResponseCustom.OK(Message.builder().message("success").build()); } @Operation(summary = "가게 정보 수정", description = "가게 정보를 수정합니다.") - @PatchMapping("/{storeId}/update") - public ResponseCustom updateStore(Authentication authentication, @PathVariable Long storeId, @RequestBody - StoreUpdateRequestDTO storeUpdateRequestDTO) { - CustomOAuthUser principal = (CustomOAuthUser)authentication.getPrincipal(); - storeService.updateStore(principal, storeId, storeUpdateRequestDTO); - return ResponseCustom.OK(Message.builder() - .message("success") - .build()); + @PatchMapping("/update") + public ResponseCustom updateStore(Authentication authentication, + @RequestBody StoreUpdateRequestDTO storeUpdateRequestDTO) { + storeService.updateStore(AuthenticationParser.parseUserId(authentication), storeUpdateRequestDTO); + return ResponseCustom.OK(Message.builder().message("success").build()); } @Operation(summary = "가게 정보 조회", description = "가게 상세 정보를 조회합니다.") - @GetMapping("/{storeId}") + @GetMapping("") public ResponseCustom getStoreInfo(Authentication authentication) { CustomOAuthUser customOAuth2User = (CustomOAuthUser)authentication.getPrincipal(); return ResponseCustom.OK(storeService.getStoreInfo(customOAuth2User)); } + + @Operation(summary = "결제 그룹 조회", description = "장부 결제 그룹을 조회합니다.") + @GetMapping("/payment_group") + public ResponseCustom> getPaymentGroup(Authentication authentication, + Pageable pageable) { + return ResponseCustom.OK( + storeService.getPaymentGroup(AuthenticationParser.parseUserId(authentication), pageable)); + } + + @Operation(summary = "결제 그룹 상세 조회", description = "장부 결제 그룹을 상세 조회합니다.") + @GetMapping("/payment_group/{teamId}") + public ResponseCustom getPaymentGroupDetail(Authentication authentication, + @PathVariable Long teamId, + Pageable pageable) { + 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/dto/response/PaymentGroupDetailResponse.java b/src/main/java/com/jangburich/domain/store/domain/dto/response/PaymentGroupDetailResponse.java new file mode 100644 index 0000000..20bdd5d --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/domain/dto/response/PaymentGroupDetailResponse.java @@ -0,0 +1,35 @@ +package com.jangburich.domain.store.domain.dto.response; + +import org.springframework.data.domain.Page; + +import com.jangburich.domain.payment.domain.TeamChargeHistoryResponse; +import com.jangburich.domain.user.domain.User; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@RequiredArgsConstructor +public class PaymentGroupDetailResponse { + private String teamName; + private Integer point; + private Integer remainPoint; + private String teamLeaderName; + private String teamLeaderPhoneNum; + // TODO 이거 아니고, order 결제 내역으로 변경해야함. + private Page historyResponses; + + public static PaymentGroupDetailResponse create(String teamName, Integer point, Integer remainPoint, + User teamLeader, Page historyResponses) { + PaymentGroupDetailResponse paymentGroupDetailResponse = new PaymentGroupDetailResponse(); + paymentGroupDetailResponse.setTeamName(teamName); + paymentGroupDetailResponse.setPoint(point); + paymentGroupDetailResponse.setRemainPoint(remainPoint); + paymentGroupDetailResponse.setTeamLeaderName(teamLeader.getNickname()); + paymentGroupDetailResponse.setTeamLeaderPhoneNum(teamLeader.getPhoneNumber()); + paymentGroupDetailResponse.setHistoryResponses(historyResponses); + return paymentGroupDetailResponse; + } +} diff --git a/src/main/java/com/jangburich/domain/store/domain/repository/StoreTeamRepository.java b/src/main/java/com/jangburich/domain/store/domain/repository/StoreTeamRepository.java index 680fa95..e05e178 100644 --- a/src/main/java/com/jangburich/domain/store/domain/repository/StoreTeamRepository.java +++ b/src/main/java/com/jangburich/domain/store/domain/repository/StoreTeamRepository.java @@ -2,10 +2,16 @@ import java.util.Optional; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import com.jangburich.domain.store.domain.Store; import com.jangburich.domain.store.domain.StoreTeam; +import com.jangburich.domain.store.domain.StoreTeamResponseDTO; public interface StoreTeamRepository extends JpaRepository { Optional findByStoreIdAndTeamId(Long store_id, Long team_id); + + Page findAllByStore(Store store, Pageable 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 3e8e1a3..58b9b41 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 @@ -1,10 +1,5 @@ package com.jangburich.domain.store.domain.service; -import com.jangburich.domain.store.domain.Category; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchCondition; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchConditionWithType; -import com.jangburich.domain.store.domain.dto.response.SearchStoresResponse; -import com.jangburich.utils.parser.AuthenticationParser; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.security.core.Authentication; @@ -14,16 +9,30 @@ import com.jangburich.domain.oauth.domain.CustomOAuthUser; import com.jangburich.domain.owner.domain.Owner; import com.jangburich.domain.owner.domain.repository.OwnerRepository; +import com.jangburich.domain.payment.domain.TeamChargeHistoryResponse; +import com.jangburich.domain.payment.domain.repository.TeamChargeHistoryRepository; +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; +import com.jangburich.domain.store.domain.StoreTeamResponseDTO; import com.jangburich.domain.store.domain.StoreUpdateRequestDTO; +import com.jangburich.domain.store.domain.dto.condition.StoreSearchCondition; +import com.jangburich.domain.store.domain.dto.condition.StoreSearchConditionWithType; +import com.jangburich.domain.store.domain.dto.response.PaymentGroupDetailResponse; +import com.jangburich.domain.store.domain.dto.response.SearchStoresResponse; import com.jangburich.domain.store.domain.repository.StoreRepository; +import com.jangburich.domain.store.domain.repository.StoreTeamRepository; +import com.jangburich.domain.team.domain.Team; +import com.jangburich.domain.team.domain.repository.TeamRepository; import com.jangburich.domain.user.domain.User; import com.jangburich.domain.user.domain.repository.UserRepository; import com.jangburich.global.error.DefaultNullPointerException; import com.jangburich.global.payload.ErrorCode; +import com.jangburich.utils.parser.AuthenticationParser; import lombok.RequiredArgsConstructor; @@ -34,9 +43,12 @@ public class StoreService { private final StoreRepository storeRepository; private final OwnerRepository ownerRepository; private final UserRepository userRepository; + private final StoreTeamRepository storeTeamRepository; + private final TeamRepository teamRepository; + private final TeamChargeHistoryRepository teamChargeHistoryRepository; @Transactional - public void CreateStore(CustomOAuthUser customOAuth2User, StoreCreateRequestDTO storeCreateRequestDTO) { + public void createStore(CustomOAuthUser customOAuth2User, StoreCreateRequestDTO storeCreateRequestDTO) { User user = userRepository.findByProviderId(customOAuth2User.getUserId()) .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); @@ -47,7 +59,7 @@ public void CreateStore(CustomOAuthUser customOAuth2User, StoreCreateRequestDTO } @Transactional - public void CreateAdditionalInfo(CustomOAuthUser customOAuthUser, + public void createAdditionalInfo(CustomOAuthUser customOAuthUser, StoreAdditionalInfoCreateRequestDTO storeAdditionalInfoCreateRequestDTO) { User user = userRepository.findByProviderId(customOAuthUser.getUserId()) .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); @@ -67,11 +79,17 @@ public void CreateAdditionalInfo(CustomOAuthUser customOAuthUser, } @Transactional - public void updateStore(CustomOAuthUser customOAuth2User, Long storeId, - StoreUpdateRequestDTO storeUpdateRequestDTO) { - Store store = storeRepository.findById(storeId) - .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_STORE_ID)); - if (!store.getOwner().getUser().getProviderId().equals(customOAuth2User.getUserId())) { + public void updateStore(String userId, StoreUpdateRequestDTO storeUpdateRequestDTO) { + 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)); + + if (!store.getOwner().getUser().getProviderId().equals(userId)) { throw new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION); } @@ -142,23 +160,73 @@ public StoreGetResponseDTO getStoreInfo(CustomOAuthUser customOAuth2User) { return new StoreGetResponseDTO().of(store); } - public Page searchByCategory(final Authentication authentication, - final Integer searchRadius, - final Category category, - final StoreSearchCondition storeSearchCondition, - final Pageable pageable) { + public Page getPaymentGroup(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)); + + return storeTeamRepository.findAllByStore(store, pageable); + } + + public Page searchByCategory(final Authentication authentication, final Integer searchRadius, + final Category category, final StoreSearchCondition storeSearchCondition, final Pageable pageable) { String parsed = AuthenticationParser.parseUserId(authentication); User user = userRepository.findByProviderId(parsed) - .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); - return storeRepository.findStoresByCategory(user.getUserId(), searchRadius, category, storeSearchCondition, pageable); + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + return storeRepository.findStoresByCategory(user.getUserId(), searchRadius, category, storeSearchCondition, + pageable); } public Page searchStores(final Authentication authentication, final String keyword, - final StoreSearchConditionWithType storeSearchConditionWithType, - final Pageable pageable) { + final StoreSearchConditionWithType storeSearchConditionWithType, final Pageable pageable) { String parsed = AuthenticationParser.parseUserId(authentication); User user = userRepository.findByProviderId(parsed) - .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); return storeRepository.findStores(user.getUserId(), keyword, storeSearchConditionWithType, pageable); } + + public PaymentGroupDetailResponse getPaymentGroupDetail(String userId, Long teamId, 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)); + + Team team = teamRepository.findById(teamId) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_PARAMETER)); + + User teamLeader = userRepository.findById(team.getTeamLeader().getUser_id()) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_PARAMETER)); + + StoreTeam storeTeam = storeTeamRepository.findByStoreIdAndTeamId(store.getId(), team.getId()) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_PARAMETER)); + + Page chargeHistoryRepositoryAllByTeam = teamChargeHistoryRepository.findAllByTeam( + team, pageable); + + 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("해당 가게를 찾을 수 없습니다."); + } +}