From 7bee9ee5bd77725580002d2b65ed8b9ff8913551 Mon Sep 17 00:00:00 2001 From: jainefer Date: Sun, 8 Dec 2024 23:06:51 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20s3=20swagger=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20id=20=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../billbill/apiserver/api/s3/Service/S3Service.java | 7 +++---- .../apiserver/api/s3/Service/S3ServiceImpl.java | 10 +++------- .../apiserver/api/s3/controller/S3Controller.java | 12 +++++++++--- .../apiserver/api/s3/converter/S3Converter.java | 6 ++---- .../apiserver/api/s3/dto/response/S3Response.java | 4 +++- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/main/java/site/billbill/apiserver/api/s3/Service/S3Service.java b/src/main/java/site/billbill/apiserver/api/s3/Service/S3Service.java index 42e1eea..d4e2bfe 100644 --- a/src/main/java/site/billbill/apiserver/api/s3/Service/S3Service.java +++ b/src/main/java/site/billbill/apiserver/api/s3/Service/S3Service.java @@ -1,14 +1,13 @@ package site.billbill.apiserver.api.s3.Service; import org.springframework.web.multipart.MultipartFile; -import site.billbill.apiserver.api.s3.dto.request.S3Request; import site.billbill.apiserver.api.s3.dto.response.S3Response; import java.util.List; public interface S3Service { - S3Response.uploadResponse uploadPostsFiles(List files, String userId); - S3Response.uploadResponse uploadChatFiles(List files,String userId,long id); - S3Response.uploadResponse uploadUserFiles(List files); + S3Response.uploadS3Response uploadPostsFiles(List files, String userId); + S3Response.uploadS3Response uploadChatFiles(List files, String userId, String id); + S3Response.uploadS3Response uploadUserFiles(List files); } diff --git a/src/main/java/site/billbill/apiserver/api/s3/Service/S3ServiceImpl.java b/src/main/java/site/billbill/apiserver/api/s3/Service/S3ServiceImpl.java index 547bad7..e3959ed 100644 --- a/src/main/java/site/billbill/apiserver/api/s3/Service/S3ServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/s3/Service/S3ServiceImpl.java @@ -1,18 +1,14 @@ package site.billbill.apiserver.api.s3.Service; import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.AmazonS3Client; -import com.amazonaws.services.s3.S3Resource; import com.amazonaws.services.s3.model.CannedAccessControlList; import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.PutObjectRequest; -import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.multipart.MultipartFile; import site.billbill.apiserver.api.s3.converter.S3Converter; -import site.billbill.apiserver.api.s3.dto.request.S3Request; import site.billbill.apiserver.api.s3.dto.response.S3Response; import java.io.File; @@ -34,7 +30,7 @@ public class S3ServiceImpl implements S3Service { private String CHATS_IMG_DIR="chats/"; private String USERS_IMG_DIR="users/"; @Override - public S3Response.uploadResponse uploadPostsFiles(List files, String userId){ + public S3Response.uploadS3Response uploadPostsFiles(List files, String userId){ StringBuilder imgDir= new StringBuilder(); imgDir.append(Posts_IMG_DIR) @@ -55,7 +51,7 @@ public S3Response.uploadResponse uploadPostsFiles(List files, Str } @Override - public S3Response.uploadResponse uploadChatFiles(List files,String userId,long id){ + public S3Response.uploadS3Response uploadChatFiles(List files, String userId, String id){ StringBuilder imgDir= new StringBuilder(); imgDir.append(CHATS_IMG_DIR) .append(File.separator) // 운영 체제에 맞는 구분자를 추가 @@ -73,7 +69,7 @@ public S3Response.uploadResponse uploadChatFiles(List files,Strin return S3Converter.toS3UploadResponse(list); } @Override - public S3Response.uploadResponse uploadUserFiles(List files){ + public S3Response.uploadS3Response uploadUserFiles(List files){ Listlist=files.stream() .map(file->{ diff --git a/src/main/java/site/billbill/apiserver/api/s3/controller/S3Controller.java b/src/main/java/site/billbill/apiserver/api/s3/controller/S3Controller.java index 4088273..c5b51c5 100644 --- a/src/main/java/site/billbill/apiserver/api/s3/controller/S3Controller.java +++ b/src/main/java/site/billbill/apiserver/api/s3/controller/S3Controller.java @@ -1,6 +1,9 @@ package site.billbill.apiserver.api.s3.controller; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -11,7 +14,6 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import site.billbill.apiserver.api.s3.Service.S3Service; -import site.billbill.apiserver.api.s3.dto.request.S3Request; import site.billbill.apiserver.api.s3.dto.response.S3Response; import site.billbill.apiserver.common.response.BaseResponse; import site.billbill.apiserver.common.utils.jwt.JWTUtil; @@ -25,10 +27,14 @@ @RequiredArgsConstructor public class S3Controller { private final S3Service s3Service; + @Operation(summary = "s3 이미지 업로드", description = "s3 이미지 업로드입니다. 쿼리의 id는 채팅방 id만 해당됩니다.") @ResponseStatus(HttpStatus.OK) @PostMapping(value="/{option}",consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public BaseResponse upload(@Valid List images, - @PathVariable("option") String option, @RequestParam(value ="id",required = false) Long id) { + public BaseResponse upload(@Valid List images, + @Parameter(name = "option", description = "S3 옵션 (user, chat, post)", example = "user", in = ParameterIn.PATH, required = true) + @PathVariable("option") String option, + @Parameter(name = "id", description = "채팅방 id", example = "CHAT-XXXXX", in = ParameterIn.QUERY, required = false) + @RequestParam(value ="id",required = false) String id) { String userId = ""; if(MDC.get(JWTUtil.MDC_USER_ID) != null) { userId= MDC.get(JWTUtil.MDC_USER_ID).toString(); diff --git a/src/main/java/site/billbill/apiserver/api/s3/converter/S3Converter.java b/src/main/java/site/billbill/apiserver/api/s3/converter/S3Converter.java index e531049..219b585 100644 --- a/src/main/java/site/billbill/apiserver/api/s3/converter/S3Converter.java +++ b/src/main/java/site/billbill/apiserver/api/s3/converter/S3Converter.java @@ -1,14 +1,12 @@ package site.billbill.apiserver.api.s3.converter; -import org.springframework.web.multipart.MultipartFile; -import site.billbill.apiserver.api.s3.dto.request.S3Request; import site.billbill.apiserver.api.s3.dto.response.S3Response; import java.util.List; public class S3Converter { - public static S3Response.uploadResponse toS3UploadResponse(List urls){ - return S3Response.uploadResponse.builder() + public static S3Response.uploadS3Response toS3UploadResponse(List urls){ + return S3Response.uploadS3Response.builder() .urls(urls) .build(); } diff --git a/src/main/java/site/billbill/apiserver/api/s3/dto/response/S3Response.java b/src/main/java/site/billbill/apiserver/api/s3/dto/response/S3Response.java index 2b525f0..af06dc1 100644 --- a/src/main/java/site/billbill/apiserver/api/s3/dto/response/S3Response.java +++ b/src/main/java/site/billbill/apiserver/api/s3/dto/response/S3Response.java @@ -1,5 +1,6 @@ package site.billbill.apiserver.api.s3.dto.response; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; import java.util.List; @@ -10,7 +11,8 @@ public class S3Response { @Builder @Getter - public static class uploadResponse{ + @Schema(description = "S3 업로드 응답") + public static class uploadS3Response { private List urls; }