Skip to content

Commit

Permalink
[fix] s3 swagger 수정 및 id 타입 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jainefer committed Dec 8, 2024
1 parent 0805434 commit 7bee9ee
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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<MultipartFile> files, String userId);
S3Response.uploadResponse uploadChatFiles(List<MultipartFile> files,String userId,long id);
S3Response.uploadResponse uploadUserFiles(List<MultipartFile> files);
S3Response.uploadS3Response uploadPostsFiles(List<MultipartFile> files, String userId);
S3Response.uploadS3Response uploadChatFiles(List<MultipartFile> files, String userId, String id);
S3Response.uploadS3Response uploadUserFiles(List<MultipartFile> files);

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<MultipartFile> files, String userId){
public S3Response.uploadS3Response uploadPostsFiles(List<MultipartFile> files, String userId){

StringBuilder imgDir= new StringBuilder();
imgDir.append(Posts_IMG_DIR)
Expand All @@ -55,7 +51,7 @@ public S3Response.uploadResponse uploadPostsFiles(List<MultipartFile> files, Str
}

@Override
public S3Response.uploadResponse uploadChatFiles(List<MultipartFile> files,String userId,long id){
public S3Response.uploadS3Response uploadChatFiles(List<MultipartFile> files, String userId, String id){
StringBuilder imgDir= new StringBuilder();
imgDir.append(CHATS_IMG_DIR)
.append(File.separator) // 운영 체제에 맞는 구분자를 추가
Expand All @@ -73,7 +69,7 @@ public S3Response.uploadResponse uploadChatFiles(List<MultipartFile> files,Strin
return S3Converter.toS3UploadResponse(list);
}
@Override
public S3Response.uploadResponse uploadUserFiles(List<MultipartFile> files){
public S3Response.uploadS3Response uploadUserFiles(List<MultipartFile> files){

List<String>list=files.stream()
.map(file->{
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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<S3Response.uploadResponse> upload(@Valid List<MultipartFile> images,
@PathVariable("option") String option, @RequestParam(value ="id",required = false) Long id) {
public BaseResponse<S3Response.uploadS3Response> upload(@Valid List<MultipartFile> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> urls){
return S3Response.uploadResponse.builder()
public static S3Response.uploadS3Response toS3UploadResponse(List<String> urls){
return S3Response.uploadS3Response.builder()
.urls(urls)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,7 +11,8 @@
public class S3Response {
@Builder
@Getter
public static class uploadResponse{
@Schema(description = "S3 업로드 응답")
public static class uploadS3Response {
private List<String> urls;
}

Expand Down

0 comments on commit 7bee9ee

Please sign in to comment.