generated from Bamdoliro/repository-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(#111): 공지사항 파일 업로드 presigned url 적용
- 공지사항 파일 업로드 기능에 presigned url을 적용했습니다. - presigned url을 이용하면 공지사항을 조회할 때 마다 새로운 presigned url을 요청해야하므로 Notice에서 fileUrl 컬럼을 fileUuid 로 대체했습니다.
- Loading branch information
Showing
9 changed files
with
60 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 9 additions & 17 deletions
26
src/main/java/com/bamdoliro/maru/application/notice/UploadFileUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,23 @@ | ||
package com.bamdoliro.maru.application.notice; | ||
|
||
import com.bamdoliro.maru.domain.notice.domain.Notice; | ||
import com.bamdoliro.maru.domain.user.domain.User; | ||
import com.bamdoliro.maru.infrastructure.s3.UploadFileService; | ||
import com.bamdoliro.maru.infrastructure.s3.FileService; | ||
import com.bamdoliro.maru.infrastructure.s3.constants.FolderConstant; | ||
import com.bamdoliro.maru.infrastructure.s3.dto.response.UploadResponse; | ||
import com.bamdoliro.maru.infrastructure.s3.exception.FileSizeLimitExceededException; | ||
import com.bamdoliro.maru.infrastructure.s3.exception.MediaTypeMismatchException; | ||
import com.bamdoliro.maru.infrastructure.s3.dto.response.UrlResponse; | ||
import com.bamdoliro.maru.presentation.notice.dto.response.UploadFileResponse; | ||
import com.bamdoliro.maru.shared.annotation.UseCase; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.util.UUID; | ||
|
||
import static com.bamdoliro.maru.shared.constants.FileConstant.MB; | ||
|
||
@RequiredArgsConstructor | ||
@UseCase | ||
public class UploadFileUseCase { | ||
|
||
private final UploadFileService uploadFileService; | ||
private final FileService fileService; | ||
|
||
public UploadFileResponse execute() { | ||
String uuid = UUID.randomUUID().toString(); | ||
|
||
public UploadResponse execute(MultipartFile noticeFile) { | ||
return uploadFileService.execute(noticeFile, FolderConstant.NOTICE_FILE, UUID.randomUUID().toString(), file -> { | ||
if (file.getSize() > 20 * MB) { | ||
throw new FileSizeLimitExceededException(); | ||
} | ||
}); | ||
return new UploadFileResponse(fileService.getPresignedUrl(FolderConstant.NOTICE_FILE, uuid), uuid); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/com/bamdoliro/maru/presentation/notice/dto/response/UploadFileResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.bamdoliro.maru.presentation.notice.dto.response; | ||
|
||
import com.bamdoliro.maru.infrastructure.s3.dto.response.UrlResponse; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class UploadFileResponse { | ||
|
||
private final UrlResponse url; | ||
|
||
private final String fileUuid; | ||
|
||
public UploadFileResponse(UrlResponse url, String fileUuid) { | ||
this.url = url; | ||
this.fileUuid = fileUuid; | ||
} | ||
} |