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

#30 [feat] 소원권 사용하기 Api 구현 #31

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public UpdateWishCouponResponseDto updateWishCoupon(@RequestBody UpdateWishCoupo
return wishCouponService.uploadWishCoupon(requestDto);
}

@PatchMapping("/{wishCouponId}")
@ResponseStatus(HttpStatus.OK)
public void useWishCoupon(@PathVariable Long wishCouponId) {
wishCouponService.useWishCoupon(wishCouponId);
}

@GetMapping("/{wishCouponId}")
@ResponseStatus(HttpStatus.OK)
public WishCouponResponseDto wishCouponResponseDto(@PathVariable Long wishCouponId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ public void updateContent(String content) {
public void makeVisible() {
this.isVisible = true;
}

public void useWishCoupon() {
this.isUsed = true;
this.usedAt = LocalDateTime.now();
}
}
13 changes: 9 additions & 4 deletions src/main/java/com/universe/uni/service/WishCouponService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ public class WishCouponService {

private final WishCouponRepository wishCouponRepository;

@Transactional
public UpdateWishCouponResponseDto uploadWishCoupon(UpdateWishCouponRequestDto requestDto) {
GameType gameType = GameType.valueOf(requestDto.gameType());
List<WishCoupon> wishCouponList = wishCouponRepository.findByGameTypeAndIsVisibleFalseAndIsUsedFalseAndUsedAtIsNull(
gameType);
List<WishCoupon> wishCouponList = wishCouponRepository
.findByGameTypeAndIsVisibleFalseAndIsUsedFalseAndUsedAtIsNull(gameType);

if (wishCouponList.isEmpty()) {
throw new BadRequestException(ErrorType.INVALID_REQUEST_METHOD);
Expand All @@ -42,7 +41,13 @@ public UpdateWishCouponResponseDto uploadWishCoupon(UpdateWishCouponRequestDto r
return fromWishCouponToUpdateWishCouponResponseDto(wishCoupon);
}

@Transactional
public void useWishCoupon(Long wishCouponId) {
WishCoupon wishCoupon = wishCouponRepository.findById(wishCouponId)
.orElseThrow(() -> new NotFoundException(ErrorType.INVALID_ENDPOINT_EXCEPTION));

wishCoupon.useWishCoupon();
}

public WishCouponResponseDto getWishCoupon(Long wishCouponId) {
WishCoupon wishCoupon = wishCouponRepository.findById(wishCouponId)
.orElseThrow(() -> new NotFoundException(ErrorType.INVALID_ENDPOINT_EXCEPTION));
Expand Down
Loading