diff --git a/src/main/java/ussum/homepage/application/post/controller/PostManageController.java b/src/main/java/ussum/homepage/application/post/controller/PostManageController.java index 8616a13..90792c4 100644 --- a/src/main/java/ussum/homepage/application/post/controller/PostManageController.java +++ b/src/main/java/ussum/homepage/application/post/controller/PostManageController.java @@ -96,12 +96,11 @@ public ResponseEntity> createBoardPost(@Parameter(hidden = true) 기본적으로 액세스 토큰을 필요로 합니다. 요청 path에 fileCategory(카테고리 ex.총학생회칙) 값을 문자열 형태로 넣으면 됩니다. """) - @PostMapping("/data/{fileCategory}/{fileType}/post") + @PostMapping("/data/{fileCategory}/post") public ResponseEntity> createDataPost(@Parameter(hidden = true) @UserId Long userId, @PathVariable(name = "fileCategory") String fileCategory, - @PathVariable(name = "fileType") String fileType, @RequestBody PostCreateRequest postCreateRequest) { - return ApiResponse.success(postManageService.createDataPost(userId, fileCategory, fileType, postCreateRequest)); + return ApiResponse.success(postManageService.createDataPost(userId, fileCategory, postCreateRequest)); } @Operation(summary = "게시물 생성 시 파일 및 이미지 저장 api", description = """ @@ -110,19 +109,17 @@ public ResponseEntity> createDataPost(@Parameter(hidden = true) @ 이 반환값을 가지고 게시물 생성 api에 있는 dto의 List에 url를 보내주어야 합니다. 기본적으로 액세스 토큰을 필요로 합니다. PathVariable로 노션에 있는 boardCode중 하나를 적습니다. - s3에 저장할 MultipartFile 형식의 파라미터를 2개 두었습니다. - 첫번째 파라미터는 files라는 key값으로 보내주면 됩니다. - 두번째 파라미터는 images라는 key값으로 보내주면 됩니다. + s3에 저장할 MultipartFile 형식을 fileType에 담아주시면 됩니다. 이미지와 파일을 경로를 구분하여 저장하기 위해 이러한 방식을 선택했습니다. 기본적인 api로직은 받은 파라미터를 통해 파일들을 먼저 s3에 저장하고 db에 순차적으로 생성된 id와 url을 하나의 dto로 이를 List로 반환합니다. """) - @PostMapping(value = "/{boardCode}/files", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, + @PostMapping(value = "/{boardCode}/files/{fileType}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> createBoardPostFile(@Parameter(hidden = true) @UserId Long userId, @PathVariable(name = "boardCode") String boardCode, @RequestPart(value = "files", required = false) MultipartFile[] files, - @RequestPart(value = "images", required = false) MultipartFile[] images) { - return ApiResponse.success(postManageService.createBoardPostFile(userId, boardCode, files, images)); + @PathVariable(name = "fileType") String fileType) { + return ApiResponse.success(postManageService.createBoardPostFile(userId, boardCode, files, fileType)); } @Operation(summary = "게시물 단건 조회 후 파일 혹은 이미지 삭제 api", description = """ diff --git a/src/main/java/ussum/homepage/application/post/service/PostManageService.java b/src/main/java/ussum/homepage/application/post/service/PostManageService.java index a7c56a2..606a240 100644 --- a/src/main/java/ussum/homepage/application/post/service/PostManageService.java +++ b/src/main/java/ussum/homepage/application/post/service/PostManageService.java @@ -177,16 +177,16 @@ public PostCreateResponse createBoardPost(Long userId, String boardCode, PostCre } @Transactional - public PostCreateResponse createDataPost(Long userId, String fileCategory, String fileType, PostCreateRequest postCreateRequest){ + public PostCreateResponse createDataPost(Long userId, String fileCategory, PostCreateRequest postCreateRequest){ Board board = boardReader.getBoardWithBoardCode(BoardCode.DATA.getStringBoardCode()); - Post post = postAppender.createPost(postCreateRequest.toDomain(board.getId(), userId, Category.getEnumCategoryCodeFromStringCategoryCode(fileType))); + Post post = postAppender.createPost(postCreateRequest.toDomain(board.getId(), userId, Category.getEnumCategoryCodeFromStringCategoryCode(postCreateRequest.categoryCode()))); postFileAppender.updatePostIdAndFileCategoryForIds(postCreateRequest.postFileList(), post.getId(), fileCategory); return PostCreateResponse.of(post.getId(), BoardCode.DATA.getStringBoardCode()); } @Transactional - public PostFileListResponse createBoardPostFile(Long userId, String boardCode, MultipartFile[] files, MultipartFile[] images){ - PostFileMediatorResponse response = s3utils.uploadFileWithPath(userId, boardCode, files, images); + public PostFileListResponse createBoardPostFile(Long userId, String boardCode, MultipartFile[] files, String fileType){ + PostFileMediatorResponse response = s3utils.uploadFileWithPath(userId, boardCode, files, fileType); List postFiles = convertUrlsToPostFiles(response); List afterSaveList = postFileAppender.saveAllPostFile(postFiles); diff --git a/src/main/java/ussum/homepage/infra/jpa/post/entity/Category.java b/src/main/java/ussum/homepage/infra/jpa/post/entity/Category.java index 91781cb..8b011d3 100644 --- a/src/main/java/ussum/homepage/infra/jpa/post/entity/Category.java +++ b/src/main/java/ussum/homepage/infra/jpa/post/entity/Category.java @@ -42,7 +42,7 @@ public enum Category { AUDIT_RESULT("감사결과"), ETC("기타"), - //자료집카테고리 + //자료집카테고리(이거 나중에 없앨 예정) RESULT_REPORT("결과보고서"), MINUTES("회의록"), STUDENT_COUNCIL_RULES("총학생회칙"), diff --git a/src/main/java/ussum/homepage/infra/utils/S3utils.java b/src/main/java/ussum/homepage/infra/utils/S3utils.java index 962b776..676565a 100644 --- a/src/main/java/ussum/homepage/infra/utils/S3utils.java +++ b/src/main/java/ussum/homepage/infra/utils/S3utils.java @@ -52,21 +52,21 @@ public String uploadFile(MultipartFile file) { return amazonS3.getUrl(bucket, originalFilename).toString(); } - public PostFileMediatorResponse uploadFileWithPath(Long userId, String boardCode, MultipartFile[] files, MultipartFile[] images) { + public PostFileMediatorResponse uploadFileWithPath(Long userId, String boardCode, MultipartFile[] files, String fileType) { List> uploadedFileUrls = new ArrayList<>(); List originalFileNames = new ArrayList<>(); - if (images != null && images.length > 0) { - PostFileMediatorResponse imageResponse = uploadFiles(userId, boardCode, images, "images"); + if (files != null && files.length > 0) { + PostFileMediatorResponse imageResponse = uploadFiles(userId, boardCode, files, fileType); uploadedFileUrls.addAll(imageResponse.urlList()); originalFileNames.addAll(formatOriginalFileNames(imageResponse.originalFileNames())); } - - if (files != null && files.length > 0) { - PostFileMediatorResponse fileResponse = uploadFiles(userId, boardCode, files, "files"); - uploadedFileUrls.addAll(fileResponse.urlList()); - originalFileNames.addAll(formatOriginalFileNames(fileResponse.originalFileNames())); - } +// +// if (files != null && files.length > 0) { +// PostFileMediatorResponse fileResponse = uploadFiles(userId, boardCode, files, "files"); +// uploadedFileUrls.addAll(fileResponse.urlList()); +// originalFileNames.addAll(formatOriginalFileNames(fileResponse.originalFileNames())); +// } return PostFileMediatorResponse.of(originalFileNames, uploadedFileUrls); }