Skip to content

Commit

Permalink
feat : 가게 결제 그룹 상세 정보 조회 api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunWoo9930 committed Nov 19, 2024
1 parent a4b31a3 commit 40bf044
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,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()));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
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;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface TeamChargeHistoryRepository extends JpaRepository<TeamChargeHistory, Long> {
Optional<TeamChargeHistory> findByTransactionId(String tid);

Page<TeamChargeHistoryResponse> findAllByTeam(Team team, Pageable pageable);
}
14 changes: 13 additions & 1 deletion src/main/java/com/jangburich/domain/store/domain/StoreTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jangburich.domain.store.domain;

import com.jangburich.domain.team.domain.Team;
import com.querydsl.core.annotations.QueryProjection;

import lombok.Builder;
Expand All @@ -9,15 +10,16 @@ public record StoreTeamResponseDTO(
Long id,
Integer point,
Long teamId,
String teamName,
Long storeId

) {

@QueryProjection
public StoreTeamResponseDTO(Long id, Integer point, Long teamId, Long storeId) {
public StoreTeamResponseDTO(Long id, Integer point, Long teamId, String teamName, Long storeId) {
this.id = id;
this.point = point;
this.teamId = teamId;
this.teamName = teamName;
this.storeId = storeId;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package com.jangburich.domain.store.domain.controller;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
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;
Expand All @@ -20,11 +14,16 @@
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;
Expand All @@ -45,24 +44,26 @@ public class StoreController {
@Operation(summary = "카테고리 별 가게 목록 조회", description = "카테고리 별로 가게 목록을 조회합니다.")
@GetMapping
public ResponseCustom<Page<SearchStoresResponse>> 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<Page<SearchStoresResponse>> 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 = "신규 파트너 가게를 등록합니다.")
Expand Down Expand Up @@ -106,4 +107,13 @@ public ResponseCustom<Page<StoreTeamResponseDTO>> getPaymentGroup(Authentication
return ResponseCustom.OK(
storeService.getPaymentGroup(AuthenticationParser.parseUserId(authentication), pageable));
}

@Operation(summary = "결제 그룹 상세 조회", description = "장부 결제 그룹을 상세 조회합니다.")
@GetMapping("/payment_group/{teamId}")
public ResponseCustom<PaymentGroupDetailResponse> getPaymentGroupDetail(Authentication authentication,
@PathVariable Long teamId,
Pageable pageable) {
return ResponseCustom.OK(
storeService.getPaymentGroupDetail(AuthenticationParser.parseUserId(authentication), teamId, pageable));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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;
private Page<TeamChargeHistoryResponse> historyResponses;

public static PaymentGroupDetailResponse create(String teamName, Integer point, Integer remainPoint,
User teamLeader, Page<TeamChargeHistoryResponse> 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;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.jangburich.domain.store.domain.service;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
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;
Expand All @@ -16,18 +9,29 @@
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.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;

Expand All @@ -39,6 +43,8 @@ public class StoreService {
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) {
Expand Down Expand Up @@ -158,26 +164,51 @@ public Page<StoreTeamResponseDTO> getPaymentGroup(String userId, Pageable pageab
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION));

return storeTeamRepository.findAllByStore(store, pageable);

}

public Page<SearchStoresResponse> searchByCategory(final Authentication authentication,
final Integer searchRadius,
final Category category,
final StoreSearchCondition storeSearchCondition,
final Pageable pageable) {
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<SearchStoresResponse> 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<TeamChargeHistoryResponse> chargeHistoryRepositoryAllByTeam = teamChargeHistoryRepository.findAllByTeam(
team, pageable);

return PaymentGroupDetailResponse.create(team.getName(), storeTeam.getPoint(), storeTeam.getRemainPoint(), teamLeader, chargeHistoryRepositoryAllByTeam);
}
}

0 comments on commit 40bf044

Please sign in to comment.