Skip to content

Commit

Permalink
#39 [feat] 소원권 관련 Api Response 수정 (#40)
Browse files Browse the repository at this point in the history
* feat: Fix Use update wish coupon response

* feat: Fix wish coupon response dto
  • Loading branch information
2zerozu authored Jul 12, 2023
1 parent b4dd91a commit 6693521
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.web.bind.annotation.RestController;

import com.universe.uni.dto.request.UpdateWishCouponRequestDto;
import com.universe.uni.dto.response.UpdateWishCouponResponseDto;
import com.universe.uni.dto.response.WishCouponResponseDto;
import com.universe.uni.service.WishCouponService;

Expand All @@ -25,8 +24,8 @@ public class WishCouponController {

@PatchMapping
@ResponseStatus(HttpStatus.OK)
public UpdateWishCouponResponseDto updateWishCoupon(@RequestBody UpdateWishCouponRequestDto requestDto) {
return wishCouponService.uploadWishCoupon(requestDto);
public void updateWishCoupon(@RequestBody UpdateWishCouponRequestDto requestDto) {
wishCouponService.uploadWishCoupon(requestDto);
}

@PatchMapping("/{wishCouponId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@JsonPropertyOrder({"id", "image", "content", "isVisible", "isUsed", "usedAt", "gameType"})
@Builder
public record UpdateWishCouponResponseDto(
public record WishCouponDto(
Long id,
String image,
String content,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package com.universe.uni.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import lombok.Builder;

@JsonPropertyOrder({"id", "isMine", "image", "content", "isVisible", "isUsed", "usedAt", "gameType"})
@JsonPropertyOrder({"isMine", "wishCoupon"})
@Builder
public record WishCouponResponseDto(
Long id,
boolean isMine,
String image,
String content,
@JsonProperty("isVisible") boolean visible,
@JsonProperty("isUsed") boolean used,
String usedAt,
String gameType
WishCouponDto wishCoupon
) {
}
27 changes: 15 additions & 12 deletions src/main/java/com/universe/uni/service/WishCouponService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.universe.uni.domain.entity.Game;
import com.universe.uni.domain.entity.WishCoupon;
import com.universe.uni.dto.request.UpdateWishCouponRequestDto;
import com.universe.uni.dto.response.UpdateWishCouponResponseDto;
import com.universe.uni.dto.response.WishCouponDto;
import com.universe.uni.dto.response.WishCouponResponseDto;
import com.universe.uni.exception.BadRequestException;
import com.universe.uni.exception.NotFoundException;
Expand All @@ -25,8 +25,7 @@ public class WishCouponService {

private final WishCouponRepository wishCouponRepository;

@Transactional
public UpdateWishCouponResponseDto uploadWishCoupon(UpdateWishCouponRequestDto requestDto) {
public WishCouponDto uploadWishCoupon(UpdateWishCouponRequestDto requestDto) {
GameType gameType = GameType.valueOf(requestDto.gameType());
List<WishCoupon> wishCouponList = wishCouponRepository
.findByGameTypeAndIsVisibleFalseAndIsUsedFalseAndUsedAtIsNull(gameType);
Expand All @@ -53,13 +52,20 @@ public void useWishCoupon(Long wishCouponId) {
public WishCouponResponseDto getWishCoupon(Long wishCouponId) {
WishCoupon wishCoupon = wishCouponRepository.findById(wishCouponId)
.orElseThrow(() -> new NotFoundException(ErrorType.INVALID_ENDPOINT_EXCEPTION));
return fromWishCouponToWishCouponResponseDto(wishCoupon);

/** TODO 영주 : 추후 1L 내 userId로 바꾸기*/
boolean isMine = wishCoupon.getUser().getId() == 1L;

return WishCouponResponseDto.builder()
.isMine(isMine)
.wishCoupon(fromWishCouponToWishCouponDto(wishCoupon))
.build();
}

private UpdateWishCouponResponseDto fromWishCouponToUpdateWishCouponResponseDto(WishCoupon wishCoupon) {
private WishCouponDto fromWishCouponToUpdateWishCouponResponseDto(WishCoupon wishCoupon) {
String usedAt = wishCoupon.getUsedAt() != null ? wishCoupon.getUsedAt().toString() : null;

return UpdateWishCouponResponseDto.builder()
return WishCouponDto.builder()
.id(wishCoupon.getId())
.image(wishCoupon.getImage())
.content(wishCoupon.getContent())
Expand All @@ -71,7 +77,7 @@ private UpdateWishCouponResponseDto fromWishCouponToUpdateWishCouponResponseDto(
}

public WishCoupon issueWishCoupon(String content, Game game) {
if(content == null || content.isEmpty()) {
if (content == null || content.isEmpty()) {
return createWishCoupon(content, game, false);
} else {
return createWishCoupon(content, game, true);
Expand All @@ -92,14 +98,11 @@ public void saveWishCoupon(WishCoupon wishCoupon) {
wishCouponRepository.save(wishCoupon);
}

private WishCouponResponseDto fromWishCouponToWishCouponResponseDto(WishCoupon wishCoupon) {
/** TODO 영주 : 추후 1L 내 userId로 바꾸기*/
boolean isMine = wishCoupon.getUser().getId() == 1L;
private WishCouponDto fromWishCouponToWishCouponDto(WishCoupon wishCoupon) {
String usedAt = wishCoupon.getUsedAt() != null ? wishCoupon.getUsedAt().toString() : null;

return WishCouponResponseDto.builder()
return WishCouponDto.builder()
.id(wishCoupon.getId())
.isMine(isMine)
.image(wishCoupon.getImage())
.content(wishCoupon.getContent())
.visible(wishCoupon.isVisible())
Expand Down

0 comments on commit 6693521

Please sign in to comment.