Skip to content

Commit

Permalink
Merge pull request 9oormthon-univ#37 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 85feb74 + 0e77e86 commit 6ab07cd
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
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;

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<TeamChargeHistory, Long> {
Optional<TeamChargeHistory> findByTransactionId(String tid);
Optional<TeamChargeHistory> findByTransactionId(String tid);

Page<TeamChargeHistoryResponse> findAllByTeam(Team team, Pageable pageable);

Page<TeamChargeHistoryResponse> findAllByTeam(Team team, Pageable pageable);
Page<StoreChargeHistoryResponse> findAllByStore(Store store, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class StoreController {
private final StoreService storeService;

@Operation(summary = "์นดํ…Œ๊ณ ๋ฆฌ ๋ณ„ ๊ฐ€๊ฒŒ ๋ชฉ๋ก ์กฐํšŒ", description = "์นดํ…Œ๊ณ ๋ฆฌ ๋ณ„๋กœ ๊ฐ€๊ฒŒ ๋ชฉ๋ก์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping
@GetMapping("/category")
public ResponseCustom<Page<SearchStoresResponse>> searchByCategory(
Authentication authentication,
@RequestParam(required = false, defaultValue = "3") Integer searchRadius,
Expand Down Expand Up @@ -94,7 +94,7 @@ public ResponseCustom<Message> updateStore(Authentication authentication, @PathV
}

@Operation(summary = "๊ฐ€๊ฒŒ ์ •๋ณด ์กฐํšŒ", description = "๊ฐ€๊ฒŒ ์ƒ์„ธ ์ •๋ณด๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/{storeId}")
@GetMapping("")
public ResponseCustom<StoreGetResponseDTO> getStoreInfo(Authentication authentication) {
CustomOAuthUser customOAuth2User = (CustomOAuthUser)authentication.getPrincipal();
return ResponseCustom.OK(storeService.getStoreInfo(customOAuth2User));
Expand All @@ -116,4 +116,10 @@ public ResponseCustom<PaymentGroupDetailResponse> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -209,6 +210,21 @@ public PaymentGroupDetailResponse getPaymentGroupDetail(String userId, Long team
Page<TeamChargeHistoryResponse> 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<StoreChargeHistoryResponse> 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<StoreChargeHistoryResponse> historyResponses = teamChargeHistoryRepository.findAllByStore(store, pageable);
return historyResponses;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.jangburich.domain.store.exception;

public class StoreNotFoundException extends RuntimeException{
public StoreNotFoundException() {
super("ํ•ด๋‹น ๊ฐ€๊ฒŒ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
}

0 comments on commit 6ab07cd

Please sign in to comment.