From 1d712a8caa9067a95ac995269018b055d7120403 Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Thu, 14 Dec 2023 09:00:07 +0900 Subject: [PATCH 01/12] =?UTF-8?q?=F0=9F=A7=A9=20::=20(#495)=20getPreSigned?= =?UTF-8?q?Url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../retum/jobis/domain/file/spi/FilePort.java | 8 ++- .../retum/jobis/thirdparty/s3/S3Adapter.java | 58 ++++++++++++++++++- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/spi/FilePort.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/spi/FilePort.java index 851660332..946e79b86 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/spi/FilePort.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/spi/FilePort.java @@ -5,5 +5,11 @@ import java.io.File; public interface FilePort { - void uploadFile(File file, String fileName, FileType fileType); + void uploadFile(File file, String fileName); + + String getPreSignedUrl(String fullFileName); + + void validateExtension(String fileName, FileType fileType); + + String getFullFileName(FileType fileType, String fileName); } diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/s3/S3Adapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/s3/S3Adapter.java index c2f59b06d..449dab2e6 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/s3/S3Adapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/s3/S3Adapter.java @@ -1,20 +1,31 @@ package team.retum.jobis.thirdparty.s3; +import com.amazonaws.HttpMethod; import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.Headers; import com.amazonaws.services.s3.internal.Mimetypes; import com.amazonaws.services.s3.model.CannedAccessControlList; +import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.PutObjectRequest; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import team.retum.jobis.domain.file.exception.FileUploadFailedException; +import team.retum.jobis.domain.file.exception.InvalidExtensionException; import team.retum.jobis.domain.file.model.FileType; import team.retum.jobis.domain.file.spi.FilePort; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.util.Date; +import java.util.UUID; + +import static team.retum.jobis.domain.file.model.FileType.EXTENSION_FILE; +import static team.retum.jobis.domain.file.model.FileType.LOGO_IMAGE; @Component @RequiredArgsConstructor @@ -25,7 +36,7 @@ public class S3Adapter implements FilePort { @Override @Async("asyncTaskExecutor") - public void uploadFile(File file, String fileName, FileType fileType) { + public void uploadFile(File file, String fileName) { try { InputStream inputStream = new FileInputStream(file); ObjectMetadata objectMetadata = new ObjectMetadata(); @@ -45,4 +56,49 @@ public void uploadFile(File file, String fileName, FileType fileType) { throw FileUploadFailedException.EXCEPTION; } } + + @Override + public String getPreSignedUrl(String fullFileName) { + return URLDecoder.decode( + amazonS3.generatePresignedUrl(getPreSignedUrlRequest(fullFileName)).toString(), StandardCharsets.UTF_8 + ); + } + + @Override + public void validateExtension(String fileName, FileType fileType) { + String extension = fileName.substring(fileName.lastIndexOf(".")); + + boolean isValid = switch (fileType) { + case LOGO_IMAGE -> LOGO_IMAGE.validExtensions.contains(extension); + case EXTENSION_FILE -> EXTENSION_FILE.validExtensions.contains(extension); + }; + + if (!isValid) { + throw InvalidExtensionException.EXCEPTION; + } + } + + @Override + public String getFullFileName(FileType fileType, String fileName) { + return fileType.name() + "/" + UUID.randomUUID() + "-" + fileName; + } + + private GeneratePresignedUrlRequest getPreSignedUrlRequest(String filename) { + GeneratePresignedUrlRequest request = + new GeneratePresignedUrlRequest(s3Properties.getBucket(), filename) + .withMethod(HttpMethod.PUT) + .withExpiration(getPreSignedUrlExpiration()); + request.addRequestParameter( + Headers.S3_CANNED_ACL, + CannedAccessControlList.PublicRead.toString() + ); + + return request; + } + + private Date getPreSignedUrlExpiration() { + Date expiration = new Date(); + expiration.setTime(expiration.getTime() + 1000 * 60 * 2); + return expiration; + } } From bbca97f9155151ca51fa663d2f3ce1b869cdbaaf Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Thu, 14 Dec 2023 09:06:16 +0900 Subject: [PATCH 02/12] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20::=20(#495)=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/file/usecase/FileUploadUseCase.java | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java index 0aaa5bf28..c3502a6d0 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java @@ -25,9 +25,9 @@ public FileUploadResponse execute(List files, FileType fileType) { List fileUrls = files.stream().filter(Objects::nonNull) .map( file -> { - String fileName = fileType + "/" + UUID.randomUUID() + "-" + file.getName(); - validateExtension(fileName, fileType); - filePort.uploadFile(file, fileName, fileType); + String fileName = filePort.getFullFileName(fileType, file.getName()); + filePort.validateExtension(fileName, fileType); + filePort.uploadFile(file, fileName); return fileName.replace(" ", "+"); } @@ -36,16 +36,5 @@ public FileUploadResponse execute(List files, FileType fileType) { return new FileUploadResponse(fileUrls); } - private void validateExtension(String fileName, FileType fileType) { - String extension = fileName.substring(fileName.lastIndexOf(".")); - boolean isValid = switch (fileType) { - case LOGO_IMAGE -> LOGO_IMAGE.validExtensions.contains(extension); - case EXTENSION_FILE -> EXTENSION_FILE.validExtensions.contains(extension); - }; - - if (!isValid) { - throw InvalidExtensionException.EXCEPTION; - } - } } From ebcd55fa0a70fc8f96284a42a618f41d2187e157 Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Thu, 14 Dec 2023 09:06:49 +0900 Subject: [PATCH 03/12] =?UTF-8?q?=F0=9F=A7=A9=20::=20(#495)=20presigned=20?= =?UTF-8?q?Url=20=EC=83=9D=EC=84=B1=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/dto/CreatePreSignedUrlRequest.java | 22 ++++++++++ .../response/CreatePreSignedUrlResponse.java | 19 +++++++++ .../usecase/CreatePreSignedUrlUseCase.java | 34 +++++++++++++++ .../file/presentation/FileWebAdapter.java | 14 +++++++ .../dto/CreatePreSignedUrlWebRequest.java | 41 +++++++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 jobis-application/src/main/java/team/retum/jobis/domain/file/dto/CreatePreSignedUrlRequest.java create mode 100644 jobis-application/src/main/java/team/retum/jobis/domain/file/dto/response/CreatePreSignedUrlResponse.java create mode 100644 jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreatePreSignedUrlUseCase.java create mode 100644 jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/dto/CreatePreSignedUrlWebRequest.java diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/CreatePreSignedUrlRequest.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/CreatePreSignedUrlRequest.java new file mode 100644 index 000000000..160a13ed0 --- /dev/null +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/CreatePreSignedUrlRequest.java @@ -0,0 +1,22 @@ +package team.retum.jobis.domain.file.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import team.retum.jobis.domain.file.model.FileType; + +import java.util.List; + +@Getter +@AllArgsConstructor +public class CreatePreSignedUrlRequest { + + private final List files; + + @Getter + @AllArgsConstructor + public static class FileRequest { + private final FileType type; + private final String fileName; + } +} diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/response/CreatePreSignedUrlResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/response/CreatePreSignedUrlResponse.java new file mode 100644 index 000000000..39d8f3224 --- /dev/null +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/response/CreatePreSignedUrlResponse.java @@ -0,0 +1,19 @@ +package team.retum.jobis.domain.file.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.List; + +@Getter +@AllArgsConstructor +public class CreatePreSignedUrlResponse { + private final List urls; + + @Getter + @AllArgsConstructor + public static class PreSignedUrlResponse { + private String filePath; + private String preSignedUrl; + } +} diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreatePreSignedUrlUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreatePreSignedUrlUseCase.java new file mode 100644 index 000000000..3cc494c74 --- /dev/null +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreatePreSignedUrlUseCase.java @@ -0,0 +1,34 @@ +package team.retum.jobis.domain.file.usecase; + +import lombok.RequiredArgsConstructor; +import team.retum.jobis.common.annotation.UseCase; +import team.retum.jobis.domain.file.dto.CreatePreSignedUrlRequest; +import team.retum.jobis.domain.file.dto.response.CreatePreSignedUrlResponse; +import team.retum.jobis.domain.file.dto.response.CreatePreSignedUrlResponse.PreSignedUrlResponse; +import team.retum.jobis.domain.file.model.FileType; +import team.retum.jobis.domain.file.spi.FilePort; + +import java.util.List; + +@RequiredArgsConstructor +@UseCase +public class CreatePreSignedUrlUseCase { + + private final FilePort filePort; + + public CreatePreSignedUrlResponse execute(CreatePreSignedUrlRequest request) { + return new CreatePreSignedUrlResponse( + request.getFiles().stream() + .map( + file -> { + String fileName = filePort.getFullFileName(file.getType(), file.getFileName()); + String url = filePort.getPreSignedUrl(fileName); + return new PreSignedUrlResponse( + fileName, + url + ); + } + ).toList() + ); + } +} diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/FileWebAdapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/FileWebAdapter.java index 56af81730..9053592b2 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/FileWebAdapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/FileWebAdapter.java @@ -1,17 +1,22 @@ package team.retum.jobis.domain.file.presentation; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import team.retum.jobis.domain.file.dto.response.CreatePreSignedUrlResponse; import team.retum.jobis.domain.file.dto.response.FileUploadResponse; import team.retum.jobis.domain.file.exception.FileNotFoundException; import team.retum.jobis.domain.file.exception.FileUploadFailedException; import team.retum.jobis.domain.file.model.FileType; +import team.retum.jobis.domain.file.presentation.dto.CreatePreSignedUrlWebRequest; +import team.retum.jobis.domain.file.usecase.CreatePreSignedUrlUseCase; import team.retum.jobis.domain.file.usecase.FileUploadUseCase; import java.io.File; @@ -26,6 +31,7 @@ public class FileWebAdapter { private final FileUploadUseCase fileUploadUseCase; + private final CreatePreSignedUrlUseCase createPreSignedUrlUseCase; @ResponseStatus(HttpStatus.CREATED) @PostMapping @@ -52,4 +58,12 @@ public FileUploadResponse uploadFile( fileType ); } + + @ResponseStatus(HttpStatus.CREATED) + @PostMapping("/pre_signed") + public CreatePreSignedUrlResponse createPreSignedUrl( + @RequestBody @Valid CreatePreSignedUrlWebRequest request + ) { + return createPreSignedUrlUseCase.execute(request.toDomainRequest()); + } } diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/dto/CreatePreSignedUrlWebRequest.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/dto/CreatePreSignedUrlWebRequest.java new file mode 100644 index 000000000..c02a6fd3c --- /dev/null +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/dto/CreatePreSignedUrlWebRequest.java @@ -0,0 +1,41 @@ +package team.retum.jobis.domain.file.presentation.dto; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.NoArgsConstructor; +import team.retum.jobis.domain.file.dto.CreatePreSignedUrlRequest; +import team.retum.jobis.domain.file.dto.CreatePreSignedUrlRequest.FileRequest; +import team.retum.jobis.domain.file.model.FileType; + +import java.util.List; + +@Getter +@NoArgsConstructor +public class CreatePreSignedUrlWebRequest { + + private List<@NotNull FileWebRequest> files; + + @Getter + @NoArgsConstructor + public static class FileWebRequest { + + @NotNull + private FileType type; + + @NotBlank + private String fileName; + } + + public CreatePreSignedUrlRequest toDomainRequest() { + return new CreatePreSignedUrlRequest( + files.stream() + .map(file -> + new FileRequest( + file.type, + file.fileName + ) + ).toList() + ); + } +} From 81cd4b8dd95a20ef8d90c61fabc6f9907ff2123b Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Thu, 14 Dec 2023 09:07:06 +0900 Subject: [PATCH 04/12] =?UTF-8?q?=F0=9F=97=82=EF=B8=8F=20::=20(#495)=20?= =?UTF-8?q?=EC=A0=91=EA=B7=BC=EA=B6=8C=ED=95=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/team/retum/jobis/global/security/SecurityConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/SecurityConfig.java b/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/SecurityConfig.java index fce403c40..c84b8f5e6 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/SecurityConfig.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/SecurityConfig.java @@ -117,6 +117,7 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception { // files .requestMatchers(HttpMethod.POST, "/files").permitAll() + .requestMatchers(HttpMethod.POST, "/files/pre_signed").permitAll() .requestMatchers(HttpMethod.DELETE, "/files").permitAll() // code From c1b3ef15237b8ec33e1a01134eff00adb78087a0 Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Thu, 14 Dec 2023 09:07:49 +0900 Subject: [PATCH 05/12] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20::=20(#495)=20unu?= =?UTF-8?q?sed=20imports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/usecase/QueryEmploymentCountUseCase.java | 2 -- .../jobis/domain/file/dto/CreatePreSignedUrlRequest.java | 1 - .../jobis/domain/file/usecase/CreatePreSignedUrlUseCase.java | 3 --- .../retum/jobis/domain/file/usecase/FileUploadUseCase.java | 5 ----- .../application/presentation/ApplicationWebAdapter.java | 5 ++--- 5 files changed, 2 insertions(+), 14 deletions(-) diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/QueryEmploymentCountUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/QueryEmploymentCountUseCase.java index afc297bc6..2da00624d 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/QueryEmploymentCountUseCase.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/QueryEmploymentCountUseCase.java @@ -3,8 +3,6 @@ import lombok.RequiredArgsConstructor; import team.retum.jobis.common.annotation.ReadOnlyUseCase; import team.retum.jobis.domain.application.dto.response.QueryEmploymentCountResponse; -import team.retum.jobis.domain.application.model.ApplicationStatus; -import team.retum.jobis.domain.application.spi.QueryApplicationPort; import team.retum.jobis.domain.student.spi.QueryStudentPort; import java.time.Year; diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/CreatePreSignedUrlRequest.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/CreatePreSignedUrlRequest.java index 160a13ed0..940a7f49a 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/CreatePreSignedUrlRequest.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/CreatePreSignedUrlRequest.java @@ -2,7 +2,6 @@ import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.NoArgsConstructor; import team.retum.jobis.domain.file.model.FileType; import java.util.List; diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreatePreSignedUrlUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreatePreSignedUrlUseCase.java index 3cc494c74..5a1b1250d 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreatePreSignedUrlUseCase.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreatePreSignedUrlUseCase.java @@ -5,11 +5,8 @@ import team.retum.jobis.domain.file.dto.CreatePreSignedUrlRequest; import team.retum.jobis.domain.file.dto.response.CreatePreSignedUrlResponse; import team.retum.jobis.domain.file.dto.response.CreatePreSignedUrlResponse.PreSignedUrlResponse; -import team.retum.jobis.domain.file.model.FileType; import team.retum.jobis.domain.file.spi.FilePort; -import java.util.List; - @RequiredArgsConstructor @UseCase public class CreatePreSignedUrlUseCase { diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java index c3502a6d0..943d46c5d 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java @@ -3,17 +3,12 @@ import lombok.RequiredArgsConstructor; import team.retum.jobis.common.annotation.UseCase; import team.retum.jobis.domain.file.dto.response.FileUploadResponse; -import team.retum.jobis.domain.file.exception.InvalidExtensionException; import team.retum.jobis.domain.file.model.FileType; import team.retum.jobis.domain.file.spi.FilePort; import java.io.File; import java.util.List; import java.util.Objects; -import java.util.UUID; - -import static team.retum.jobis.domain.file.model.FileType.EXTENSION_FILE; -import static team.retum.jobis.domain.file.model.FileType.LOGO_IMAGE; @RequiredArgsConstructor @UseCase diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/presentation/ApplicationWebAdapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/presentation/ApplicationWebAdapter.java index c45ca56b2..d937f30d3 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/presentation/ApplicationWebAdapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/presentation/ApplicationWebAdapter.java @@ -1,7 +1,6 @@ package team.retum.jobis.domain.application.presentation; import jakarta.validation.Valid; -import jakarta.validation.constraints.Positive; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.DeleteMapping; @@ -18,9 +17,9 @@ import team.retum.jobis.common.dto.response.TotalPageCountResponse; import team.retum.jobis.domain.application.dto.response.CompanyQueryApplicationsResponse; import team.retum.jobis.domain.application.dto.response.QueryEmploymentCountResponse; +import team.retum.jobis.domain.application.dto.response.QueryMyApplicationsResponse; import team.retum.jobis.domain.application.dto.response.QueryPassedApplicationStudentsResponse; import team.retum.jobis.domain.application.dto.response.QueryRejectionReasonResponse; -import team.retum.jobis.domain.application.dto.response.QueryMyApplicationsResponse; import team.retum.jobis.domain.application.dto.response.TeacherQueryApplicationsResponse; import team.retum.jobis.domain.application.model.ApplicationStatus; import team.retum.jobis.domain.application.presentation.dto.request.ChangeApplicationsStatusWebRequest; @@ -33,9 +32,9 @@ import team.retum.jobis.domain.application.usecase.CreateApplicationUseCase; import team.retum.jobis.domain.application.usecase.DeleteApplicationUseCase; import team.retum.jobis.domain.application.usecase.QueryEmploymentCountUseCase; +import team.retum.jobis.domain.application.usecase.QueryMyApplicationsUseCase; import team.retum.jobis.domain.application.usecase.QueryPassedApplicationStudentsUseCase; import team.retum.jobis.domain.application.usecase.QueryRejectionReasonUseCase; -import team.retum.jobis.domain.application.usecase.QueryMyApplicationsUseCase; import team.retum.jobis.domain.application.usecase.ReapplyUseCase; import team.retum.jobis.domain.application.usecase.RejectApplicationUseCase; import team.retum.jobis.domain.application.usecase.TeacherQueryApplicationsUseCase; From 5b6cced67f36e04c5547da26db9698943292a206 Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Thu, 14 Dec 2023 16:24:36 +0900 Subject: [PATCH 06/12] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20::=20(#495)=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...t.java => CreateFileUploadUrlRequest.java} | 2 +- .../response/CreateFileUploadUrlResponse.java | 19 +++++++++++ .../response/CreatePreSignedUrlResponse.java | 19 ----------- .../retum/jobis/domain/file/spi/FilePort.java | 9 +---- .../usecase/CreateFileUploadUrlUseCase.java | 34 +++++++++++++++++++ .../usecase/CreatePreSignedUrlUseCase.java | 31 ----------------- .../file/presentation/FileWebAdapter.java | 10 +++--- .../dto/CreatePreSignedUrlWebRequest.java | 8 ++--- .../retum/jobis/thirdparty/s3/S3Adapter.java | 27 +-------------- 9 files changed, 65 insertions(+), 94 deletions(-) rename jobis-application/src/main/java/team/retum/jobis/domain/file/dto/{CreatePreSignedUrlRequest.java => CreateFileUploadUrlRequest.java} (90%) create mode 100644 jobis-application/src/main/java/team/retum/jobis/domain/file/dto/response/CreateFileUploadUrlResponse.java delete mode 100644 jobis-application/src/main/java/team/retum/jobis/domain/file/dto/response/CreatePreSignedUrlResponse.java create mode 100644 jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java delete mode 100644 jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreatePreSignedUrlUseCase.java diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/CreatePreSignedUrlRequest.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/CreateFileUploadUrlRequest.java similarity index 90% rename from jobis-application/src/main/java/team/retum/jobis/domain/file/dto/CreatePreSignedUrlRequest.java rename to jobis-application/src/main/java/team/retum/jobis/domain/file/dto/CreateFileUploadUrlRequest.java index 940a7f49a..f4afdc469 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/CreatePreSignedUrlRequest.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/CreateFileUploadUrlRequest.java @@ -8,7 +8,7 @@ @Getter @AllArgsConstructor -public class CreatePreSignedUrlRequest { +public class CreateFileUploadUrlRequest { private final List files; diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/response/CreateFileUploadUrlResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/response/CreateFileUploadUrlResponse.java new file mode 100644 index 000000000..d64191f14 --- /dev/null +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/response/CreateFileUploadUrlResponse.java @@ -0,0 +1,19 @@ +package team.retum.jobis.domain.file.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.List; + +@Getter +@AllArgsConstructor +public class CreateFileUploadUrlResponse { + private final List urls; + + @Getter + @AllArgsConstructor + public static class UrlResponse { + private final String filePath; + private final String preSignedUrl; + } +} diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/response/CreatePreSignedUrlResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/response/CreatePreSignedUrlResponse.java deleted file mode 100644 index 39d8f3224..000000000 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/dto/response/CreatePreSignedUrlResponse.java +++ /dev/null @@ -1,19 +0,0 @@ -package team.retum.jobis.domain.file.dto.response; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.List; - -@Getter -@AllArgsConstructor -public class CreatePreSignedUrlResponse { - private final List urls; - - @Getter - @AllArgsConstructor - public static class PreSignedUrlResponse { - private String filePath; - private String preSignedUrl; - } -} diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/spi/FilePort.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/spi/FilePort.java index 946e79b86..52d6a4173 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/spi/FilePort.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/spi/FilePort.java @@ -1,15 +1,8 @@ package team.retum.jobis.domain.file.spi; -import team.retum.jobis.domain.file.model.FileType; - import java.io.File; public interface FilePort { void uploadFile(File file, String fileName); - - String getPreSignedUrl(String fullFileName); - - void validateExtension(String fileName, FileType fileType); - - String getFullFileName(FileType fileType, String fileName); + String getFileUploadUrl(String fullFileName); } diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java new file mode 100644 index 000000000..9ef7a47b3 --- /dev/null +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java @@ -0,0 +1,34 @@ +package team.retum.jobis.domain.file.usecase; + +import lombok.RequiredArgsConstructor; +import team.retum.jobis.common.annotation.UseCase; +import team.retum.jobis.domain.file.dto.CreateFileUploadUrlRequest; +import team.retum.jobis.domain.file.dto.response.CreateFileUploadUrlResponse; +import team.retum.jobis.domain.file.dto.response.CreateFileUploadUrlResponse.UrlResponse; +import team.retum.jobis.domain.file.service.FileService; +import team.retum.jobis.domain.file.spi.FilePort; + +@RequiredArgsConstructor +@UseCase +public class CreateFileUploadUrlUseCase { + + private final FilePort filePort; + private final FileService fileService; + + public CreateFileUploadUrlResponse execute(CreateFileUploadUrlRequest request) { + return new CreateFileUploadUrlResponse( + request.getFiles().stream() + .map( + file -> { + fileService.validateExtension(file.getFileName(), file.getType()); + String fullFileName = fileService.getFullFileName(file.getType(), file.getFileName()); + String url = filePort.getFileUploadUrl(fullFileName); + return new UrlResponse( + fullFileName, + url + ); + } + ).toList() + ); + } +} diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreatePreSignedUrlUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreatePreSignedUrlUseCase.java deleted file mode 100644 index 5a1b1250d..000000000 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreatePreSignedUrlUseCase.java +++ /dev/null @@ -1,31 +0,0 @@ -package team.retum.jobis.domain.file.usecase; - -import lombok.RequiredArgsConstructor; -import team.retum.jobis.common.annotation.UseCase; -import team.retum.jobis.domain.file.dto.CreatePreSignedUrlRequest; -import team.retum.jobis.domain.file.dto.response.CreatePreSignedUrlResponse; -import team.retum.jobis.domain.file.dto.response.CreatePreSignedUrlResponse.PreSignedUrlResponse; -import team.retum.jobis.domain.file.spi.FilePort; - -@RequiredArgsConstructor -@UseCase -public class CreatePreSignedUrlUseCase { - - private final FilePort filePort; - - public CreatePreSignedUrlResponse execute(CreatePreSignedUrlRequest request) { - return new CreatePreSignedUrlResponse( - request.getFiles().stream() - .map( - file -> { - String fileName = filePort.getFullFileName(file.getType(), file.getFileName()); - String url = filePort.getPreSignedUrl(fileName); - return new PreSignedUrlResponse( - fileName, - url - ); - } - ).toList() - ); - } -} diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/FileWebAdapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/FileWebAdapter.java index 9053592b2..8d4e2fae8 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/FileWebAdapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/FileWebAdapter.java @@ -10,13 +10,13 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import team.retum.jobis.domain.file.dto.response.CreatePreSignedUrlResponse; +import team.retum.jobis.domain.file.dto.response.CreateFileUploadUrlResponse; import team.retum.jobis.domain.file.dto.response.FileUploadResponse; import team.retum.jobis.domain.file.exception.FileNotFoundException; import team.retum.jobis.domain.file.exception.FileUploadFailedException; import team.retum.jobis.domain.file.model.FileType; import team.retum.jobis.domain.file.presentation.dto.CreatePreSignedUrlWebRequest; -import team.retum.jobis.domain.file.usecase.CreatePreSignedUrlUseCase; +import team.retum.jobis.domain.file.usecase.CreateFileUploadUrlUseCase; import team.retum.jobis.domain.file.usecase.FileUploadUseCase; import java.io.File; @@ -31,7 +31,7 @@ public class FileWebAdapter { private final FileUploadUseCase fileUploadUseCase; - private final CreatePreSignedUrlUseCase createPreSignedUrlUseCase; + private final CreateFileUploadUrlUseCase createFileUploadUrlUseCase; @ResponseStatus(HttpStatus.CREATED) @PostMapping @@ -61,9 +61,9 @@ public FileUploadResponse uploadFile( @ResponseStatus(HttpStatus.CREATED) @PostMapping("/pre_signed") - public CreatePreSignedUrlResponse createPreSignedUrl( + public CreateFileUploadUrlResponse createPreSignedUrl( @RequestBody @Valid CreatePreSignedUrlWebRequest request ) { - return createPreSignedUrlUseCase.execute(request.toDomainRequest()); + return createFileUploadUrlUseCase.execute(request.toDomainRequest()); } } diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/dto/CreatePreSignedUrlWebRequest.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/dto/CreatePreSignedUrlWebRequest.java index c02a6fd3c..0976fdd07 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/dto/CreatePreSignedUrlWebRequest.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/dto/CreatePreSignedUrlWebRequest.java @@ -4,8 +4,8 @@ import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.NoArgsConstructor; -import team.retum.jobis.domain.file.dto.CreatePreSignedUrlRequest; -import team.retum.jobis.domain.file.dto.CreatePreSignedUrlRequest.FileRequest; +import team.retum.jobis.domain.file.dto.CreateFileUploadUrlRequest; +import team.retum.jobis.domain.file.dto.CreateFileUploadUrlRequest.FileRequest; import team.retum.jobis.domain.file.model.FileType; import java.util.List; @@ -27,8 +27,8 @@ public static class FileWebRequest { private String fileName; } - public CreatePreSignedUrlRequest toDomainRequest() { - return new CreatePreSignedUrlRequest( + public CreateFileUploadUrlRequest toDomainRequest() { + return new CreateFileUploadUrlRequest( files.stream() .map(file -> new FileRequest( diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/s3/S3Adapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/s3/S3Adapter.java index 449dab2e6..30763e3ee 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/s3/S3Adapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/s3/S3Adapter.java @@ -12,8 +12,6 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import team.retum.jobis.domain.file.exception.FileUploadFailedException; -import team.retum.jobis.domain.file.exception.InvalidExtensionException; -import team.retum.jobis.domain.file.model.FileType; import team.retum.jobis.domain.file.spi.FilePort; import java.io.File; @@ -22,10 +20,6 @@ import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.util.Date; -import java.util.UUID; - -import static team.retum.jobis.domain.file.model.FileType.EXTENSION_FILE; -import static team.retum.jobis.domain.file.model.FileType.LOGO_IMAGE; @Component @RequiredArgsConstructor @@ -58,31 +52,12 @@ public void uploadFile(File file, String fileName) { } @Override - public String getPreSignedUrl(String fullFileName) { + public String getFileUploadUrl(String fullFileName) { return URLDecoder.decode( amazonS3.generatePresignedUrl(getPreSignedUrlRequest(fullFileName)).toString(), StandardCharsets.UTF_8 ); } - @Override - public void validateExtension(String fileName, FileType fileType) { - String extension = fileName.substring(fileName.lastIndexOf(".")); - - boolean isValid = switch (fileType) { - case LOGO_IMAGE -> LOGO_IMAGE.validExtensions.contains(extension); - case EXTENSION_FILE -> EXTENSION_FILE.validExtensions.contains(extension); - }; - - if (!isValid) { - throw InvalidExtensionException.EXCEPTION; - } - } - - @Override - public String getFullFileName(FileType fileType, String fileName) { - return fileType.name() + "/" + UUID.randomUUID() + "-" + fileName; - } - private GeneratePresignedUrlRequest getPreSignedUrlRequest(String filename) { GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(s3Properties.getBucket(), filename) From e8a5fee5f9c0ef91bcf7acfde34d644a1e4f2267 Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Thu, 14 Dec 2023 16:24:52 +0900 Subject: [PATCH 07/12] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20::=20(#495)=20fil?= =?UTF-8?q?eService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/file/service/FileService.java | 31 +++++++++++++++++++ .../file/usecase/FileUploadUseCase.java | 6 ++-- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 jobis-application/src/main/java/team/retum/jobis/domain/file/service/FileService.java diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/service/FileService.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/service/FileService.java new file mode 100644 index 000000000..929b8ad09 --- /dev/null +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/service/FileService.java @@ -0,0 +1,31 @@ +package team.retum.jobis.domain.file.service; + +import team.retum.jobis.common.annotation.Service; +import team.retum.jobis.domain.file.exception.InvalidExtensionException; +import team.retum.jobis.domain.file.model.FileType; + +import java.util.UUID; + +import static team.retum.jobis.domain.file.model.FileType.EXTENSION_FILE; +import static team.retum.jobis.domain.file.model.FileType.LOGO_IMAGE; + +@Service +public class FileService { + + public String getFullFileName(FileType fileType, String fileName) { + return fileType.name() + "/" + UUID.randomUUID() + "-" + fileName; + } + + public void validateExtension(String fileName, FileType fileType) { + String extension = fileName.substring(fileName.lastIndexOf(".")); + + boolean isValid = switch (fileType) { + case LOGO_IMAGE -> LOGO_IMAGE.validExtensions.contains(extension); + case EXTENSION_FILE -> EXTENSION_FILE.validExtensions.contains(extension); + }; + + if (!isValid) { + throw InvalidExtensionException.EXCEPTION; + } + } +} diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java index 943d46c5d..72a414c7f 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java @@ -4,6 +4,7 @@ import team.retum.jobis.common.annotation.UseCase; import team.retum.jobis.domain.file.dto.response.FileUploadResponse; import team.retum.jobis.domain.file.model.FileType; +import team.retum.jobis.domain.file.service.FileService; import team.retum.jobis.domain.file.spi.FilePort; import java.io.File; @@ -15,13 +16,14 @@ public class FileUploadUseCase { private final FilePort filePort; + private final FileService fileService; public FileUploadResponse execute(List files, FileType fileType) { List fileUrls = files.stream().filter(Objects::nonNull) .map( file -> { - String fileName = filePort.getFullFileName(fileType, file.getName()); - filePort.validateExtension(fileName, fileType); + String fileName = fileService.getFullFileName(fileType, file.getName()); + fileService.validateExtension(fileName, fileType); filePort.uploadFile(file, fileName); return fileName.replace(" ", "+"); From 0dcd6d231236e1552d36ec92e34dea6f8d5d1876 Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Thu, 14 Dec 2023 16:43:51 +0900 Subject: [PATCH 08/12] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20::=20(#495)=20gen?= =?UTF-8?q?erateFullFileName?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../retum/jobis/domain/file/service/FileService.java | 8 +++----- .../domain/file/usecase/CreateFileUploadUrlUseCase.java | 9 ++++----- .../jobis/domain/file/usecase/FileUploadUseCase.java | 3 +-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/service/FileService.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/service/FileService.java index 929b8ad09..db025603b 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/service/FileService.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/service/FileService.java @@ -12,11 +12,7 @@ @Service public class FileService { - public String getFullFileName(FileType fileType, String fileName) { - return fileType.name() + "/" + UUID.randomUUID() + "-" + fileName; - } - - public void validateExtension(String fileName, FileType fileType) { + public String generateFullFileName(FileType fileType, String fileName) { String extension = fileName.substring(fileName.lastIndexOf(".")); boolean isValid = switch (fileType) { @@ -27,5 +23,7 @@ public void validateExtension(String fileName, FileType fileType) { if (!isValid) { throw InvalidExtensionException.EXCEPTION; } + + return fileType.name() + "/" + UUID.randomUUID() + "-" + fileName; } } diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java index 9ef7a47b3..3e4722beb 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java @@ -1,7 +1,7 @@ package team.retum.jobis.domain.file.usecase; import lombok.RequiredArgsConstructor; -import team.retum.jobis.common.annotation.UseCase; +import team.retum.jobis.common.annotation.Service; import team.retum.jobis.domain.file.dto.CreateFileUploadUrlRequest; import team.retum.jobis.domain.file.dto.response.CreateFileUploadUrlResponse; import team.retum.jobis.domain.file.dto.response.CreateFileUploadUrlResponse.UrlResponse; @@ -9,7 +9,7 @@ import team.retum.jobis.domain.file.spi.FilePort; @RequiredArgsConstructor -@UseCase +@Service public class CreateFileUploadUrlUseCase { private final FilePort filePort; @@ -20,9 +20,8 @@ public CreateFileUploadUrlResponse execute(CreateFileUploadUrlRequest request) { request.getFiles().stream() .map( file -> { - fileService.validateExtension(file.getFileName(), file.getType()); - String fullFileName = fileService.getFullFileName(file.getType(), file.getFileName()); - String url = filePort.getFileUploadUrl(fullFileName); + String fullFileName = fileService.generateFullFileName(file.getType(), file.getFileName()); + String url = filePort.generateFileUploadUrl(fullFileName); return new UrlResponse( fullFileName, url diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java index 72a414c7f..6d2bf3ac9 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java @@ -22,8 +22,7 @@ public FileUploadResponse execute(List files, FileType fileType) { List fileUrls = files.stream().filter(Objects::nonNull) .map( file -> { - String fileName = fileService.getFullFileName(fileType, file.getName()); - fileService.validateExtension(fileName, fileType); + String fileName = fileService.generateFullFileName(fileType, file.getName()); filePort.uploadFile(file, fileName); return fileName.replace(" ", "+"); From 4a126597b348b1ee46698191df813b3b7f11b420 Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Thu, 14 Dec 2023 16:44:37 +0900 Subject: [PATCH 09/12] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20::=20(#495)=20nam?= =?UTF-8?q?ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/team/retum/jobis/domain/file/spi/FilePort.java | 2 +- .../src/main/java/team/retum/jobis/thirdparty/s3/S3Adapter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/spi/FilePort.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/spi/FilePort.java index 52d6a4173..b70efd0cf 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/spi/FilePort.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/spi/FilePort.java @@ -4,5 +4,5 @@ public interface FilePort { void uploadFile(File file, String fileName); - String getFileUploadUrl(String fullFileName); + String generateFileUploadUrl(String fullFileName); } diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/s3/S3Adapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/s3/S3Adapter.java index 30763e3ee..88f671ff1 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/s3/S3Adapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/thirdparty/s3/S3Adapter.java @@ -52,7 +52,7 @@ public void uploadFile(File file, String fileName) { } @Override - public String getFileUploadUrl(String fullFileName) { + public String generateFileUploadUrl(String fullFileName) { return URLDecoder.decode( amazonS3.generatePresignedUrl(getPreSignedUrlRequest(fullFileName)).toString(), StandardCharsets.UTF_8 ); From ef81debf7bc14a1d951c8617315ed3b5dc64296b Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Thu, 14 Dec 2023 16:45:04 +0900 Subject: [PATCH 10/12] =?UTF-8?q?=F0=9F=A6=B7=20::=20(#495)=20pre-signed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../retum/jobis/domain/file/presentation/FileWebAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/FileWebAdapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/FileWebAdapter.java index 8d4e2fae8..deab72e04 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/FileWebAdapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/file/presentation/FileWebAdapter.java @@ -60,7 +60,7 @@ public FileUploadResponse uploadFile( } @ResponseStatus(HttpStatus.CREATED) - @PostMapping("/pre_signed") + @PostMapping("/pre-signed") public CreateFileUploadUrlResponse createPreSignedUrl( @RequestBody @Valid CreatePreSignedUrlWebRequest request ) { From 9d919c83a5a756b9ae3a0d014a877791061b66a5 Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Thu, 14 Dec 2023 16:54:15 +0900 Subject: [PATCH 11/12] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20::=20(#495)=20Fil?= =?UTF-8?q?eUtil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileService.java => common/util/FileUtil.java} | 8 +++----- .../domain/file/usecase/CreateFileUploadUrlUseCase.java | 1 - .../jobis/domain/file/usecase/FileUploadUseCase.java | 5 ++--- 3 files changed, 5 insertions(+), 9 deletions(-) rename jobis-application/src/main/java/team/retum/jobis/{domain/file/service/FileService.java => common/util/FileUtil.java} (78%) diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/service/FileService.java b/jobis-application/src/main/java/team/retum/jobis/common/util/FileUtil.java similarity index 78% rename from jobis-application/src/main/java/team/retum/jobis/domain/file/service/FileService.java rename to jobis-application/src/main/java/team/retum/jobis/common/util/FileUtil.java index db025603b..12d77439a 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/service/FileService.java +++ b/jobis-application/src/main/java/team/retum/jobis/common/util/FileUtil.java @@ -1,6 +1,5 @@ -package team.retum.jobis.domain.file.service; +package team.retum.jobis.common.util; -import team.retum.jobis.common.annotation.Service; import team.retum.jobis.domain.file.exception.InvalidExtensionException; import team.retum.jobis.domain.file.model.FileType; @@ -9,10 +8,9 @@ import static team.retum.jobis.domain.file.model.FileType.EXTENSION_FILE; import static team.retum.jobis.domain.file.model.FileType.LOGO_IMAGE; -@Service -public class FileService { +public class FileUtil { - public String generateFullFileName(FileType fileType, String fileName) { + public static String generateFullFileName(FileType fileType, String fileName) { String extension = fileName.substring(fileName.lastIndexOf(".")); boolean isValid = switch (fileType) { diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java index 3e4722beb..eb5260741 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java @@ -5,7 +5,6 @@ import team.retum.jobis.domain.file.dto.CreateFileUploadUrlRequest; import team.retum.jobis.domain.file.dto.response.CreateFileUploadUrlResponse; import team.retum.jobis.domain.file.dto.response.CreateFileUploadUrlResponse.UrlResponse; -import team.retum.jobis.domain.file.service.FileService; import team.retum.jobis.domain.file.spi.FilePort; @RequiredArgsConstructor diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java index 6d2bf3ac9..3868a5739 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/FileUploadUseCase.java @@ -2,9 +2,9 @@ import lombok.RequiredArgsConstructor; import team.retum.jobis.common.annotation.UseCase; +import team.retum.jobis.common.util.FileUtil; import team.retum.jobis.domain.file.dto.response.FileUploadResponse; import team.retum.jobis.domain.file.model.FileType; -import team.retum.jobis.domain.file.service.FileService; import team.retum.jobis.domain.file.spi.FilePort; import java.io.File; @@ -16,13 +16,12 @@ public class FileUploadUseCase { private final FilePort filePort; - private final FileService fileService; public FileUploadResponse execute(List files, FileType fileType) { List fileUrls = files.stream().filter(Objects::nonNull) .map( file -> { - String fileName = fileService.generateFullFileName(fileType, file.getName()); + String fileName = FileUtil.generateFullFileName(fileType, file.getName()); filePort.uploadFile(file, fileName); return fileName.replace(" ", "+"); From c91661820becb8762e0a9f45d0e52234ca8b5ba9 Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Thu, 14 Dec 2023 16:58:19 +0900 Subject: [PATCH 12/12] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20::=20(#495)=20?= =?UTF-8?q?=EC=BB=B4=ED=8C=8C=EC=9D=BC=20=EC=97=90=EB=9F=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java index eb5260741..696b050ea 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import team.retum.jobis.common.annotation.Service; +import team.retum.jobis.common.util.FileUtil; import team.retum.jobis.domain.file.dto.CreateFileUploadUrlRequest; import team.retum.jobis.domain.file.dto.response.CreateFileUploadUrlResponse; import team.retum.jobis.domain.file.dto.response.CreateFileUploadUrlResponse.UrlResponse; @@ -12,14 +13,13 @@ public class CreateFileUploadUrlUseCase { private final FilePort filePort; - private final FileService fileService; public CreateFileUploadUrlResponse execute(CreateFileUploadUrlRequest request) { return new CreateFileUploadUrlResponse( request.getFiles().stream() .map( file -> { - String fullFileName = fileService.generateFullFileName(file.getType(), file.getFileName()); + String fullFileName = FileUtil.generateFullFileName(file.getType(), file.getFileName()); String url = filePort.generateFileUploadUrl(fullFileName); return new UrlResponse( fullFileName,