Skip to content

Commit

Permalink
Merge pull request #35 from 9oormthon-univ/feat/store
Browse files Browse the repository at this point in the history
Feat/store
  • Loading branch information
HyunWoo9930 authored Nov 19, 2024
2 parents e42b307 + 40bf044 commit 85feb74
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 48 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
@@ -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

0 comments on commit 85feb74

Please sign in to comment.