From 5b6410a2a9962c32edb94cca5ce84c01128b7a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=EC=9D=B8=ED=9D=AC?= Date: Thu, 27 Jul 2023 15:41:00 +0900 Subject: [PATCH] fix: add username from token in voucher-read-method --- .../controller/VoucherController.java | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 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 16a40acf..3a9d9749 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 @@ -1,19 +1,33 @@ package org.swmaestro.repl.gifthub.vouchers.controller; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.servlet.http.HttpServletRequest; -import lombok.RequiredArgsConstructor; +import java.io.IOException; +import java.util.List; + import org.springframework.beans.factory.annotation.Value; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import org.swmaestro.repl.gifthub.util.JwtProvider; -import org.swmaestro.repl.gifthub.vouchers.dto.*; +import org.swmaestro.repl.gifthub.vouchers.dto.S3FileDto; +import org.swmaestro.repl.gifthub.vouchers.dto.VoucherReadResponseDto; +import org.swmaestro.repl.gifthub.vouchers.dto.VoucherSaveRequestDto; +import org.swmaestro.repl.gifthub.vouchers.dto.VoucherSaveResponseDto; +import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUpdateRequestDto; +import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseRequestDto; +import org.swmaestro.repl.gifthub.vouchers.dto.VoucherUseResponseDto; import org.swmaestro.repl.gifthub.vouchers.service.StorageService; import org.swmaestro.repl.gifthub.vouchers.service.VoucherService; -import java.io.IOException; -import java.util.List; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; @RestController @RequestMapping("/vouchers") @@ -35,7 +49,7 @@ public S3FileDto saveVoucherImage(@RequestPart("image_file") MultipartFile image @PostMapping @Operation(summary = "Voucher 등록 메서드", description = "클라이언트에서 요청한 기프티콘 정보를 저장하기 위한 메서드입니다.") public VoucherSaveResponseDto saveVoucher(HttpServletRequest request, - @RequestBody VoucherSaveRequestDto voucherSaveRequestDto) throws + @RequestBody VoucherSaveRequestDto voucherSaveRequestDto) throws IOException { String username = jwtProvider.getUsername(jwtProvider.resolveToken(request).substring(7)); return voucherService.save(username, voucherSaveRequestDto); @@ -43,8 +57,10 @@ public VoucherSaveResponseDto saveVoucher(HttpServletRequest request, @GetMapping("/{voucherId}") @Operation(summary = "Voucher 상세 조회 메서드", description = "클라이언트에서 요청한 기프티콘 상세 정보를 조회하기 위한 메서드입니다.") - public VoucherReadResponseDto readVoucher(@PathVariable Long voucherId) throws IOException { - return voucherService.read(voucherId); + public VoucherReadResponseDto readVoucher(HttpServletRequest request, @PathVariable Long voucherId) throws + IOException { + String username = jwtProvider.getUsername(jwtProvider.resolveToken(request).substring(7)); + return voucherService.read(voucherId, username); } @GetMapping @@ -57,14 +73,14 @@ public List listVoucher(HttpServletRequest request) { @PatchMapping("/{voucherId}") @Operation(summary = "Voucher 수정 메서드", description = "클라이언트에서 요청한 기프티콘 정보를 수정하기 위한 메서드입니다.") public VoucherSaveResponseDto updateVoucher(@PathVariable Long voucherId, - @RequestBody VoucherUpdateRequestDto voucherUpdateRequestDto) throws IOException { + @RequestBody VoucherUpdateRequestDto voucherUpdateRequestDto) throws IOException { return voucherService.update(voucherId, voucherUpdateRequestDto); } @PostMapping("/{voucherId}/usage") @Operation(summary = "Voucher 사용 메서드", description = "클라이언트에서 요청한 기프티콘 사용 정보를 저장하기 위한 메서드입니다.") public VoucherUseResponseDto useVoucher(HttpServletRequest request, @PathVariable Long voucherId, - @RequestBody VoucherUseRequestDto voucherUseRequestDto) throws IOException { + @RequestBody VoucherUseRequestDto voucherUseRequestDto) throws IOException { String username = jwtProvider.getUsername(jwtProvider.resolveToken(request).substring(7)); return voucherService.use(username, voucherId, voucherUseRequestDto); }