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

[#15] 마이페이지 쿠폰 조회 & 사용 가능한 쿠폰 조회 & 쿠폰 사용 #16

Merged
merged 29 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f1fe151
docs : README.md 수정
codesejin Jan 24, 2024
02691a4
docs : Update README.md
codesejin Jan 24, 2024
8d2ad96
자동 PR 리뷰를 위한 workflow 파일 추가 by f-lab
f-lab-bot Jan 24, 2024
c9d9a2f
chore : "JPA"에서 "Mybatis"로 변경
codesejin Jan 27, 2024
08d2332
Merge pull request from master
codesejin Jan 27, 2024
7121a2a
docs : Read Me ERD 등 추가
codesejin Jan 27, 2024
6c419e5
feat : 마이페이지 갖고 있는 쿠폰 조회 & 주문 시 사용 가능한 쿠폰 조회
codesejin Apr 7, 2024
33459ed
refactor : 쿠폰 사용 가능 검증 여부 리팩토링
codesejin Apr 8, 2024
d85e5a9
feat : 쿠폰 사용 비즈니스 로직 구현
codesejin Apr 8, 2024
c844d64
refactor : list empty체크
codesejin Apr 8, 2024
53c23e2
refactor : 쿠폰 사용 검증 관련 익셉션 처리
codesejin Apr 8, 2024
c36b34d
refactor : 사용 가능한 쿠폰 목록 조회 리팩토링
codesejin Apr 8, 2024
767f1bb
refactor : java doc 추가
codesejin Apr 8, 2024
d8c047f
refactor : 불필요한 코드 제거
codesejin Apr 8, 2024
fca2d3c
refactor : QueryTest @Value사용 방법 적용 못함
codesejin Apr 8, 2024
3c82ef2
refactor : 스키마 수정
codesejin Apr 9, 2024
c1b8be5
refactor : 스키마 수정
codesejin Apr 9, 2024
dc01f8b
refactor : 스키마 수정
codesejin Apr 9, 2024
2b0c15e
chore : properties Value주입 안되서 테스트하느라 직접 명시한거 수정
codesejin Apr 9, 2024
235238a
refactor : 테스트하느라 @Scheduled 주석 처리한거 원복
codesejin Apr 9, 2024
cfbf82b
refactor : 메소드명, 변수명 명확하게 변경
codesejin Apr 9, 2024
450f9d6
refactor : Controller에서 @ResponseStatus삭제
codesejin Apr 15, 2024
894f7c2
refactor : Product Exception 추가 및 가격 타입 decimal변경
codesejin Apr 15, 2024
4e3d989
refactor : 메소드 네이밍 변경 - 쿠폰을 사용했다는 명시적인 네이밍
codesejin Apr 15, 2024
784033c
refactor : 주문 시 사용 가능한 쿠폰 조회 기능 리팩토링
codesejin Apr 15, 2024
d255cd0
refactor : 쿼리에서 로직 지우기
codesejin Apr 15, 2024
51475f9
refactor : 람다 표현식에서 외부 변수 접근 문제 해결
codesejin Apr 15, 2024
f1d6941
refactor : 소나클라우드 이슈 해결
codesejin Apr 15, 2024
c0a419d
refactor : early return & stream API 적용
codesejin Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor : 쿠폰 사용 검증 관련 익셉션 처리
  • Loading branch information
codesejin committed Apr 8, 2024
commit 53c23e227f770974721a10827c7a4633b2c8a958
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public ResponseEntity<ResponseDTO<List<AvailableCouponsByMemberIdResponse>>> get
public ResponseEntity<ResponseDTO<String>> orderProduct(@PathVariable final long productId,
@RequestBody final OrderProductRequest orderProductRequest) {
LocalDateTime now = LocalDateTime.now();
orderService.orderProduct(productId,orderProductRequest, now);
return ResponseEntity.status(HttpStatus.OK).body(ResponseDTO.getSuccessResult("주문이 완료되었습니다."));
return ResponseEntity.status(HttpStatus.OK).body(ResponseDTO.getSuccessResult(orderService.orderProduct(productId,orderProductRequest, now)));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public class CouponErrorMessage {
public static final String DUPLICATED_COUPON = "이미 발급된 쿠폰입니다. memberId : %s, couponId : %s";
public static final String ASYNC_DUPLICATED_COUPON = "이미 발급 요청이 처리됐습니다. memberId : %s, couponId : %s";
public static final String FAIL_COUPON_ISSUE_REQUEST = "쿠폰 발급에 실패했습니다. input: %s";

public static final String COUPON_USAGE_INVALID_PERIOD = "쿠폰의 유효기간 범위에 있지 않습니다. couponId: %s, validateStartDate: %s, validateEndDate : %s \"";
public static final String COUPON_IS_NOT_ACTIVE = "쿠폰이 활성화 되어있지 않습니다. couponId : %s";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.flab.offcoupon.exception.coupon;

import com.flab.offcoupon.exception.CustomException;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CouponStatusException extends CustomException {
public CouponStatusException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.flab.offcoupon.exception.coupon;

import com.flab.offcoupon.exception.CustomException;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CouponUsageInvalidPeriodException extends CustomException {
public CouponUsageInvalidPeriodException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.flab.offcoupon.domain.vo.persistence.order.ValidateNowIsBetweenPeriodVo;
import com.flab.offcoupon.dto.request.OrderProductRequest;
import com.flab.offcoupon.dto.response.AvailableCouponsByMemberIdResponse;
import com.flab.offcoupon.exception.coupon.CouponStatusException;
import com.flab.offcoupon.exception.coupon.CouponUsageInvalidPeriodException;
import com.flab.offcoupon.repository.mysql.*;
import com.flab.offcoupon.util.ResponseDTO;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,6 +24,8 @@
import static com.flab.offcoupon.domain.entity.OrderCoupon.createOrderCoupon;
import static com.flab.offcoupon.domain.entity.OrderDetail.createOrderDetail;
import static com.flab.offcoupon.domain.entity.params.OrderInfo.createOrderInfo;
import static com.flab.offcoupon.exception.coupon.CouponErrorMessage.COUPON_IS_NOT_ACTIVE;
import static com.flab.offcoupon.exception.coupon.CouponErrorMessage.COUPON_USAGE_INVALID_PERIOD;

@RequiredArgsConstructor
@Service
Expand Down Expand Up @@ -54,8 +58,15 @@ public ResponseDTO<List<AvailableCouponsByMemberIdResponse>> getAvailableCoupons
return ResponseDTO.getSuccessResult(responseList);
}

/**
* 상품 주문 및 쿠폰 사용 처리
*
* @param productId 상품 ID
* @param request 주문 요청 정보
* @param now 현재 시간
*/
@Transactional
public void orderProduct(final long productId, final OrderProductRequest request, LocalDateTime now) {
public ResponseDTO<String> orderProduct(final long productId, final OrderProductRequest request, LocalDateTime now) {
validateCouponIsAvailable(request, now);
// 3. 주문 정보 저장, 주문에 사용된 쿠폰 저장
OrderInfo orderInfo = createOrderInfo(
Expand All @@ -73,6 +84,7 @@ public void orderProduct(final long productId, final OrderProductRequest request

// 5. 쿠폰 사용 처리
couponIssueRepository.updateCouponStatus(request.getCouponIssueId());
return ResponseDTO.getSuccessResult("쿠폰 처리 및 주문이 완료되었습니다.");
}

/**
Expand All @@ -84,18 +96,17 @@ public void orderProduct(final long productId, final OrderProductRequest request
private void validateCouponIsAvailable(OrderProductRequest request, LocalDateTime now) {
// 1. 쿠폰들의 상태가 ACTIVE인지 확인
List<CouponIssuesAreActiveVo> couponIssueStatus = couponIssueRepository.validateStatusIsActive(request.getCouponIssueId());
System.out.println("couponIssueStatus : " + couponIssueStatus);
for (CouponIssuesAreActiveVo couponIssue : couponIssueStatus) {
if (!couponIssue.isActive()) {
throw new IllegalArgumentException("쿠폰의 상태가 ACTIVE가 아닙니다. couponIssueId: " + couponIssue.couponIssueId());
throw new CouponStatusException(COUPON_IS_NOT_ACTIVE.formatted(couponIssue.couponIssueId()));
}
}

// 2. 현재 시간이 쿠폰의 유효기간 범위내에 있는지 확인
List<ValidateNowIsBetweenPeriodVo> isBetweenValidatePeriodVo = couponRepository.validateNowIsBetweenPeriod(request.getCouponId(), now);
for (ValidateNowIsBetweenPeriodVo isBetweenValidatePeriod : isBetweenValidatePeriodVo) {
if (!isBetweenValidatePeriod.isBetweenValidatePeriod()) {
throw new IllegalArgumentException("쿠폰의 유효기간이 아닙니다. couponId: %s, validateStartDate: %s, validateEndDate : %s "
throw new CouponUsageInvalidPeriodException(COUPON_USAGE_INVALID_PERIOD
.formatted(isBetweenValidatePeriod.couponId(), isBetweenValidatePeriod.validateStartDate(), isBetweenValidatePeriod.validateEndDate()));
}
}
Expand Down