From 5567eac378c4cdc35296cd711016f6f4161a4354 Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Tue, 14 Nov 2023 23:00:56 +0900 Subject: [PATCH 1/3] feat: implement voucher-update-response-dto --- .../dto/VoucherUpdateResponseDto.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/org/swmaestro/repl/gifthub/vouchers/dto/VoucherUpdateResponseDto.java 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; + } +} From 161b7239cc2e7e71518426e0fb3133ec82de0b92 Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Tue, 14 Nov 2023 23:01:47 +0900 Subject: [PATCH 2/3] fix: modify voucher-update-api return value to voucher-update-response-dto --- .../vouchers/controller/VoucherController.java | 3 ++- .../gifthub/vouchers/service/VoucherService.java | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) 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/service/VoucherService.java b/src/main/java/org/swmaestro/repl/gifthub/vouchers/service/VoucherService.java index f8659a4b..246498ed 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; @@ -163,7 +164,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 수정 @@ -206,8 +207,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(); } From 32beef57914d7bfc5d08fccf78d8b36e7ad0034f Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Tue, 14 Nov 2023 23:02:00 +0900 Subject: [PATCH 3/3] test: modify to match dto --- .../gifthub/vouchers/controller/VoucherControllerTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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()); }