Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/store #35

Merged
merged 8 commits into from
Nov 19, 2024
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
@@ -0,0 +1,25 @@
package com.jangburich.domain.store.domain;

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

import lombok.Builder;

@Builder
public record StoreTeamResponseDTO(
Long id,
Integer point,
Long teamId,
String teamName,
Long storeId

) {
@QueryProjection
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,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;
Expand All @@ -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;
Expand All @@ -41,57 +44,53 @@ 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 = "μ‹ κ·œ νŒŒνŠΈλ„ˆ κ°€κ²Œλ₯Ό λ“±λ‘ν•©λ‹ˆλ‹€.")
@PostMapping("/create")
public ResponseCustom<Message> 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<Message> createAdditionalInfo(Authentication authentication, @RequestBody
StoreAdditionalInfoCreateRequestDTO storeAdditionalInfoCreateRequestDTO) {
public ResponseCustom<Message> 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<Message> updateStore(Authentication authentication, @PathVariable Long storeId, @RequestBody
StoreUpdateRequestDTO storeUpdateRequestDTO) {
public ResponseCustom<Message> 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());
return ResponseCustom.OK(Message.builder().message("success").build());
}

@Operation(summary = "κ°€κ²Œ 정보 쑰회", description = "κ°€κ²Œ 상세 정보λ₯Ό μ‘°νšŒν•©λ‹ˆλ‹€.")
Expand All @@ -100,4 +99,21 @@ public ResponseCustom<StoreGetResponseDTO> getStoreInfo(Authentication authentic
CustomOAuthUser customOAuth2User = (CustomOAuthUser)authentication.getPrincipal();
return ResponseCustom.OK(storeService.getStoreInfo(customOAuth2User));
}

@Operation(summary = "결제 κ·Έλ£Ή 쑰회", description = "μž₯λΆ€ 결제 그룹을 μ‘°νšŒν•©λ‹ˆλ‹€.")
@GetMapping("/payment_group")
public ResponseCustom<Page<StoreTeamResponseDTO>> getPaymentGroup(Authentication authentication,
Pageable pageable) {
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
Expand Up @@ -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<StoreTeam, Long> {
Optional<StoreTeam> findByStoreIdAndTeamId(Long store_id, Long team_id);

Page<StoreTeamResponseDTO> findAllByStore(Store store, Pageable pageable);
}
Loading