Skip to content

Commit

Permalink
Merge pull request #212 from 9oormthon-univ/feat/user
Browse files Browse the repository at this point in the history
feat : 요구사항 반영
  • Loading branch information
HyunWoo9930 authored Dec 7, 2024
2 parents f14ee19 + 7e37155 commit f8ef18e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import com.jangburich.domain.payment.domain.repository.TeamChargeHistoryRepository;
import com.jangburich.domain.payment.dto.request.PayRequest;
import com.jangburich.domain.payment.dto.response.ApproveResponse;
import com.jangburich.domain.payment.dto.response.ReadyResponse;
Expand Down Expand Up @@ -82,14 +81,6 @@ public ReadyResponse payReady(String userId, PayRequest payRequest) {

readyResponseResponseEntity = template.postForEntity(url, requestEntity, ReadyResponse.class);

PointTransaction pointTransaction = PointTransaction.builder()
.user(user)
.transactionedPoint(Integer.valueOf(payRequest.totalAmount()))
.transactionType(TransactionType.POINT_PURCHASE)
.build();

pointTransactionRepository.save(pointTransaction);

return readyResponseResponseEntity.getBody();
}

Expand All @@ -112,7 +103,15 @@ public ApproveResponse payApprove(String pgToken) {

User user = userRepository.findByProviderId(userId)
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION));
user.setPoint(user.getPoint() + Integer.valueOf(payRequest.totalAmount()));
user.setPoint(user.getPoint() + Integer.parseInt(payRequest.totalAmount()));

PointTransaction pointTransaction = PointTransaction.builder()
.user(user)
.transactionedPoint(Integer.valueOf(payRequest.totalAmount()))
.transactionType(TransactionType.POINT_PURCHASE)
.build();

pointTransactionRepository.save(pointTransaction);

return approveResponse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public class PrepaymentInfoResponse {
private Long minPrepayAmount;
private Integer wallet;
private Integer remainPrepay;
private String category;
private String storeName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public PrepaymentInfoResponse getPrepayInfo(String userId, Long storeId, Long te
}
prepaymentInfoResponse.setMinPrepayAmount(store.getMinPrepayment());
prepaymentInfoResponse.setWallet(user.getPoint());
prepaymentInfoResponse.setCategory(store.getCategory().getDisplayName());
prepaymentInfoResponse.setStoreName(store.getName());
return prepaymentInfoResponse;
}
}
25 changes: 15 additions & 10 deletions src/main/java/com/jangburich/domain/store/service/StoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,17 @@ public PaymentGroupDetailResponse getPaymentGroupDetail(String userId, Long team

List<Orders> orders = ordersRepository.findAllByTeam(team);

List<OrderResponse> orderResponse = orders.stream().map(order -> {
int price = 0;
for (Cart cart : cartRepository.findAllByOrders(order)) {
price += cart.getMenu().getPrice();
}
return new OrderResponse(order.getId(), order.getUser().getName(), order.getUpdatedAt(),
String.valueOf(price));
}).toList();
List<OrderResponse> orderResponse = orders.stream()
.map(order -> {
int price = 0;
for (Cart cart : cartRepository.findAllByOrders(order)) {
price += cart.getMenu().getPrice();
}
return new OrderResponse(order.getId(), order.getUser().getName(), order.getUpdatedAt(),
String.valueOf(price));
})
.sorted(Comparator.comparing(OrderResponse::getDate).reversed())
.toList();

return PaymentGroupDetailResponse.create(team, storeTeam.getPoint(), storeTeam.getRemainPoint(),
teamLeader, orderResponse);
Expand All @@ -316,7 +319,9 @@ public List<StoreChargeHistoryResponse> getPaymentHistory(String userId) {
Store store = storeRepository.findByOwner(owner)
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION));

return pointTransactionRepository.findAllByStore(store);
return pointTransactionRepository.findAllByStore(store).stream()
.sorted(Comparator.comparing(StoreChargeHistoryResponse::createdAt).reversed()) // 최신순 정렬
.toList();
}

public List<OrdersGetResponse> getOrdersLast(String userId) {
Expand Down Expand Up @@ -461,7 +466,7 @@ public byte[] createExcel(String userId, Integer period) {
Row headerRow = sheet.createRow(0);

// 헤더 스타일 생성
XSSFCellStyle headerStyle = (XSSFCellStyle) sheet.getWorkbook().createCellStyle();
XSSFCellStyle headerStyle = (XSSFCellStyle)sheet.getWorkbook().createCellStyle();

// 헥사 색상 설정
XSSFColor customColor = new XSSFColor(Color.decode("#FF7048"), null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jangburich.domain.user.service;

import java.time.format.DateTimeFormatter;
import java.util.Comparator;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -178,12 +179,14 @@ public WalletResponse getMyWallet(String userId) {
List<PointTransaction> transactions = pointTransactionRepository.findByUser(user);

List<PurchaseHistory> purchaseHistories = transactions.stream()
.sorted(Comparator.comparing(PointTransaction::getCreatedAt).reversed())
.map(transaction -> new PurchaseHistory(
transaction.getCreatedAt().format(DateTimeFormatter.ofPattern("MM.dd")),
transaction.getTransactionedPoint(),
transaction.getStore() != null ? transaction.getStore().getName() : "알 수 없음",
transaction.getStore() != null ? transaction.getStore().getName() : "장부리치 지갑",
transaction.getTransactionType().getDisplayName()))
.toList();

return new WalletResponse(user.getPoint(), purchaseHistories);
}

Expand Down

0 comments on commit f8ef18e

Please sign in to comment.