diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherController.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherController.java index deac3bea..148e680b 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherController.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherController.java @@ -27,6 +27,7 @@ import org.swmaestro.repl.gifthub.vouchers.dto.VoucherShareRequestDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherShareResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateRequestDto; +import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseRequestDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseResponseDto; import org.swmaestro.repl.gifthub.vouchers.service.PendingVoucherService; @@ -132,7 +133,7 @@ public ResponseEntity listVoucher(HttpServletRequest request, @RequestP }) public ResponseEntity updateVoucher(HttpServletRequest request, @PathVariable Long voucherId, @RequestBody VoucherUpdateRequestDto voucherUpdateRequestDto) throws IOException { - VoucherSaveResponseDto updatedVoucher = voucherService.update(voucherId, voucherUpdateRequestDto); + VoucherUpdateResponseDto updatedVoucher = voucherService.update(voucherId, voucherUpdateRequestDto); return ResponseEntity.ok( SuccessMessage.builder() .path(request.getRequestURI()) diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUpdateResponseDto.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUpdateResponseDto.java new file mode 100644 index 00000000..59d7b500 --- /dev/null +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUpdateResponseDto.java @@ -0,0 +1,43 @@ +package org.swmaestro.repl.gifthub.vouchers.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) +public class VoucherUpdateResponseDto { + private Long id; + private Long productId; + private String barcode; + private String expiresAt; + private Integer price; + private Integer balance; + private String imageUrl; + @JsonProperty("is_accessible") + private boolean accessible; + @JsonProperty("is_shared") + private boolean shared; + + @Builder + public VoucherUpdateResponseDto(Long id, Long productId, String barcode, String expiresAt, Integer price, + Integer balance, String imageUrl, boolean accessible, boolean shared) { + this.id = id; + this.productId = productId; + this.barcode = barcode; + this.expiresAt = expiresAt; + this.price = price; + this.balance = balance; + this.imageUrl = imageUrl; + this.accessible = accessible; + this.shared = shared; + } +} diff --git a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java index 0902770e..6a9d2d2b 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java @@ -22,6 +22,7 @@ import org.swmaestro.repl.gifthub.vouchers.dto.VoucherShareRequestDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherShareResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateRequestDto; +import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseRequestDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseResponseDto; import org.swmaestro.repl.gifthub.vouchers.entity.Brand; @@ -164,7 +165,7 @@ public List list(String username) { /* 기프티콘 정보 수정 메서드 */ - public VoucherSaveResponseDto update(Long voucherId, VoucherUpdateRequestDto voucherUpdateRequestDto) { + public VoucherUpdateResponseDto update(Long voucherId, VoucherUpdateRequestDto voucherUpdateRequestDto) { Voucher voucher = voucherRepository.findById(voucherId) .orElseThrow(() -> new BusinessException("존재하지 않는 상품권 입니다.", StatusEnum.NOT_FOUND)); // Balance 수정 @@ -211,8 +212,18 @@ public VoucherSaveResponseDto update(Long voucherId, VoucherUpdateRequestDto vou voucherRepository.save(voucher); - return VoucherSaveResponseDto.builder() + return VoucherUpdateResponseDto.builder() .id(voucherId) + .accessible(voucher.getDeletedAt() == null) + .id(voucher.getId()) + .productId(voucher.getProduct().getId()) + .barcode(voucher.getBarcode()) + .price(voucher.getProduct().getPrice()) + .balance(voucher.getBalance()) + .expiresAt(voucher.getExpiresAt().toString()) + .imageUrl(voucher.getImageUrl()) + .accessible(voucher.getDeletedAt() == null) + .shared(giftCardService.isExist(voucher.getId())) .build(); } diff --git a/src/test/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherControllerTest.java b/src/test/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherControllerTest.java index 4d2dfa17..1d3cb1d0 100644 --- a/src/test/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherControllerTest.java +++ b/src/test/java/org/swmaestro/repl/gifthub/vouchers/controller/VoucherControllerTest.java @@ -30,6 +30,7 @@ import org.swmaestro.repl.gifthub.vouchers.dto.VoucherShareRequestDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherShareResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateRequestDto; +import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateResponseDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseRequestDto; import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseResponseDto; import org.swmaestro.repl.gifthub.vouchers.service.GptService; @@ -176,20 +177,20 @@ void voucherUpdateTest() throws Exception { .expiresAt("2023-06-15") .build(); - VoucherSaveResponseDto voucherSaveResponseDto = VoucherSaveResponseDto.builder() + VoucherUpdateResponseDto voucherUpdateResponseDto = VoucherUpdateResponseDto.builder() .id(1L) .build(); // when when(jwtProvider.resolveToken(any())).thenReturn("my_awesome_access_token"); when(jwtProvider.getUsername(anyString())).thenReturn("이진우"); - when(voucherService.update(any(), any(VoucherUpdateRequestDto.class))).thenReturn(voucherSaveResponseDto); + when(voucherService.update(any(), any(VoucherUpdateRequestDto.class))).thenReturn(voucherUpdateResponseDto); // then mockMvc.perform(patch("/vouchers/1") .header("Authorization", "Bearer my_awesome_access_token") .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(voucherSaveResponseDto))) + .content(objectMapper.writeValueAsString(voucherUpdateResponseDto))) .andExpect(status().isOk()); }