Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ONG_TEAM_5_BE into develop
  • Loading branch information
LEEJaeHyeok97 committed Nov 19, 2024
2 parents b5de2ba + 9c2f259 commit ca6b405
Show file tree
Hide file tree
Showing 13 changed files with 343 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,31 +32,31 @@ public class MenuController {
private final MenuService menuService;

@PostMapping("/register")
public ResponseCustom<String> registerMenu(Authentication authentication,
public ResponseCustom<Message> 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<String> updateMenu(Authentication authentication, @PathVariable Long id,
public ResponseCustom<Message> 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<String> deleteMenu(Authentication authentication, @PathVariable Long id) {
public ResponseCustom<Message> 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<List<MenuGetResponseDTO>> getMenu(Authentication authentication) {
CustomOAuthUser customOAuthUser = (CustomOAuthUser) authentication.getPrincipal();
CustomOAuthUser customOAuthUser = (CustomOAuthUser)authentication.getPrincipal();
List<MenuGetResponseDTO> menu = menuService.getMenu(customOAuthUser);
return ResponseCustom.OK(menu);
}
Expand Down
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 Expand Up @@ -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()));
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
@@ -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,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<TeamChargeHistory, Long> {
Optional<TeamChargeHistory> findByTransactionId(String tid);
Optional<TeamChargeHistory> findByTransactionId(String tid);

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;
}
}
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,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;
}
}
Loading

0 comments on commit ca6b405

Please sign in to comment.