-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π :: (#495) Presigned URL μμ± api
π :: (#495) Presigned URL μμ± api
- Loading branch information
Showing
12 changed files
with
195 additions
and
29 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
jobis-application/src/main/java/team/retum/jobis/common/util/FileUtil.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,27 @@ | ||
package team.retum.jobis.common.util; | ||
|
||
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; | ||
|
||
public class FileUtil { | ||
|
||
public static String generateFullFileName(FileType fileType, String fileName) { | ||
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; | ||
} | ||
|
||
return fileType.name() + "/" + UUID.randomUUID() + "-" + fileName; | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...pplication/src/main/java/team/retum/jobis/domain/file/dto/CreateFileUploadUrlRequest.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,21 @@ | ||
package team.retum.jobis.domain.file.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import team.retum.jobis.domain.file.model.FileType; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class CreateFileUploadUrlRequest { | ||
|
||
private final List<FileRequest> files; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public static class FileRequest { | ||
private final FileType type; | ||
private final String fileName; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../src/main/java/team/retum/jobis/domain/file/dto/response/CreateFileUploadUrlResponse.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,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<UrlResponse> urls; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public static class UrlResponse { | ||
private final String filePath; | ||
private final String preSignedUrl; | ||
} | ||
} |
5 changes: 2 additions & 3 deletions
5
jobis-application/src/main/java/team/retum/jobis/domain/file/spi/FilePort.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,9 +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, FileType fileType); | ||
void uploadFile(File file, String fileName); | ||
String generateFileUploadUrl(String fullFileName); | ||
} |
32 changes: 32 additions & 0 deletions
32
...cation/src/main/java/team/retum/jobis/domain/file/usecase/CreateFileUploadUrlUseCase.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,32 @@ | ||
package team.retum.jobis.domain.file.usecase; | ||
|
||
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; | ||
import team.retum.jobis.domain.file.spi.FilePort; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class CreateFileUploadUrlUseCase { | ||
|
||
private final FilePort filePort; | ||
|
||
public CreateFileUploadUrlResponse execute(CreateFileUploadUrlRequest request) { | ||
return new CreateFileUploadUrlResponse( | ||
request.getFiles().stream() | ||
.map( | ||
file -> { | ||
String fullFileName = FileUtil.generateFullFileName(file.getType(), file.getFileName()); | ||
String url = filePort.generateFileUploadUrl(fullFileName); | ||
return new UrlResponse( | ||
fullFileName, | ||
url | ||
); | ||
} | ||
).toList() | ||
); | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
...main/java/team/retum/jobis/domain/file/presentation/dto/CreatePreSignedUrlWebRequest.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,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.CreateFileUploadUrlRequest; | ||
import team.retum.jobis.domain.file.dto.CreateFileUploadUrlRequest.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 CreateFileUploadUrlRequest toDomainRequest() { | ||
return new CreateFileUploadUrlRequest( | ||
files.stream() | ||
.map(file -> | ||
new FileRequest( | ||
file.type, | ||
file.fileName | ||
) | ||
).toList() | ||
); | ||
} | ||
} |
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