From b8bef146634347d9e66fa4fe25d76e2aac7f81e4 Mon Sep 17 00:00:00 2001 From: daeng Date: Thu, 15 Feb 2024 23:11:38 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=20=ED=86=A0=ED=81=B0=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config | 2 +- .../ReviewZIP/domain/image/ImageConverter.java | 6 +++--- .../ReviewZIP/domain/image/ImagesController.java | 16 +++++++++++----- .../image/dto/request/ImageRequestDto.java | 11 ----------- ...ageResponseDto.java => ImageResponseDto.java} | 2 +- 5 files changed, 16 insertions(+), 21 deletions(-) delete mode 100644 src/main/java/com/example/ReviewZIP/domain/image/dto/request/ImageRequestDto.java rename src/main/java/com/example/ReviewZIP/domain/image/dto/response/{UploadImageResponseDto.java => ImageResponseDto.java} (87%) diff --git a/config b/config index 6e041abb..8a2e061d 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit 6e041abbb7d0b160aea337d0d7210c0471ced18f +Subproject commit 8a2e061da905aeefd12ea84997fa058d668483b4 diff --git a/src/main/java/com/example/ReviewZIP/domain/image/ImageConverter.java b/src/main/java/com/example/ReviewZIP/domain/image/ImageConverter.java index 1b8a2ffc..dbbb2dac 100644 --- a/src/main/java/com/example/ReviewZIP/domain/image/ImageConverter.java +++ b/src/main/java/com/example/ReviewZIP/domain/image/ImageConverter.java @@ -1,6 +1,6 @@ package com.example.ReviewZIP.domain.image; -import com.example.ReviewZIP.domain.image.dto.response.UploadImageResponseDto; +import com.example.ReviewZIP.domain.image.dto.response.ImageResponseDto; import org.springframework.stereotype.Component; import java.util.List; @@ -9,8 +9,8 @@ @Component public class ImageConverter { - public static UploadImageResponseDto toUploadImageDto(List imagesList) { + public static ImageResponseDto toUploadImageDto(List imagesList) { List imageIds = imagesList.stream().map(Images::getId).collect(Collectors.toList()); - return new UploadImageResponseDto(imageIds); + return new ImageResponseDto(imageIds); } } diff --git a/src/main/java/com/example/ReviewZIP/domain/image/ImagesController.java b/src/main/java/com/example/ReviewZIP/domain/image/ImagesController.java index 69f53fb9..1b0a1f8d 100644 --- a/src/main/java/com/example/ReviewZIP/domain/image/ImagesController.java +++ b/src/main/java/com/example/ReviewZIP/domain/image/ImagesController.java @@ -1,12 +1,16 @@ package com.example.ReviewZIP.domain.image; -import com.example.ReviewZIP.domain.image.dto.response.UploadImageResponseDto; +import com.example.ReviewZIP.domain.image.dto.response.ImageResponseDto; +import com.example.ReviewZIP.domain.user.UsersService; import com.example.ReviewZIP.global.response.ApiResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponses; import lombok.RequiredArgsConstructor; +import org.springframework.http.MediaType; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.core.userdetails.UserDetails; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -17,16 +21,18 @@ @RequestMapping("/v1/images") public class ImagesController { private final ImagesService imageService; + private final UsersService usersService; - @PostMapping("/users/{userId}") - @Operation(summary = "이미지 업로드 API", description = "UploadImageResponseDto 사용") + @PostMapping(path = "/upload",consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @Operation(summary = "파일 업로드 API", description = "UploadImageResponseDto 사용") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "SEARCH203",description = "OK, 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "IMAGE402", description = "이미지 업로드 실패",content = @Content(schema = @Schema(implementation = ApiResponse.class))), }) - public ApiResponse uploadImage(@PathVariable(name="userId") Long userId, @RequestParam("fileList") List fileList){ + public ApiResponse uploadImage(@AuthenticationPrincipal UserDetails user, @RequestParam("fileList") List fileList){ + Long userId = usersService.getUserId(user); List imageList = imageService.uploadImage(fileList, userId); - UploadImageResponseDto imageResponseDto = ImageConverter.toUploadImageDto(imageList); + ImageResponseDto imageResponseDto = ImageConverter.toUploadImageDto(imageList); return ApiResponse.onSuccess(imageResponseDto); } } diff --git a/src/main/java/com/example/ReviewZIP/domain/image/dto/request/ImageRequestDto.java b/src/main/java/com/example/ReviewZIP/domain/image/dto/request/ImageRequestDto.java deleted file mode 100644 index 6582c6aa..00000000 --- a/src/main/java/com/example/ReviewZIP/domain/image/dto/request/ImageRequestDto.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.example.ReviewZIP.domain.image.dto.request; - -import lombok.Getter; - -import java.util.List; - -@Getter -public class ImageRequestDto { - private Long userId; - private List urlList; -} diff --git a/src/main/java/com/example/ReviewZIP/domain/image/dto/response/UploadImageResponseDto.java b/src/main/java/com/example/ReviewZIP/domain/image/dto/response/ImageResponseDto.java similarity index 87% rename from src/main/java/com/example/ReviewZIP/domain/image/dto/response/UploadImageResponseDto.java rename to src/main/java/com/example/ReviewZIP/domain/image/dto/response/ImageResponseDto.java index 5349d010..42310800 100644 --- a/src/main/java/com/example/ReviewZIP/domain/image/dto/response/UploadImageResponseDto.java +++ b/src/main/java/com/example/ReviewZIP/domain/image/dto/response/ImageResponseDto.java @@ -10,6 +10,6 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class UploadImageResponseDto { +public class ImageResponseDto { public List imageIds; } From cb4e23625f603f8c0d339ca784af78816506b014 Mon Sep 17 00:00:00 2001 From: daeng Date: Thu, 15 Feb 2024 23:14:37 +0900 Subject: [PATCH 2/2] =?UTF-8?q?docs:=20swagger=20responseCode=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/ReviewZIP/domain/image/ImagesController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/ReviewZIP/domain/image/ImagesController.java b/src/main/java/com/example/ReviewZIP/domain/image/ImagesController.java index 1b0a1f8d..8336e6b5 100644 --- a/src/main/java/com/example/ReviewZIP/domain/image/ImagesController.java +++ b/src/main/java/com/example/ReviewZIP/domain/image/ImagesController.java @@ -26,7 +26,7 @@ public class ImagesController { @PostMapping(path = "/upload",consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @Operation(summary = "파일 업로드 API", description = "UploadImageResponseDto 사용") @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "SEARCH203",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "IMAGE402", description = "이미지 업로드 실패",content = @Content(schema = @Schema(implementation = ApiResponse.class))), }) public ApiResponse uploadImage(@AuthenticationPrincipal UserDetails user, @RequestParam("fileList") List fileList){