-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: UploadFile 엔티티, 도메인 추가 * feat: StorageClient R2 구현체 추가 * feat: ImageFileUploadService 추가 * fix: UploadFile의 상태 변경 로직 수정 - ASSIGNED, ATTACHED 상태 변경 시 예외 던지지 않도록 변경 - 리뉴얼 상태로 변경 시 주인 검사 로직 추가 * feat: UploadFileStatusChangeService 추가 * feat: 관리자 이미지 업로드 API 추가 * feat: AsyncSchoolUploadImagesStatusChangeEventListener 추가 * feat: AsyncArtistUploadImagesStatusChangeEventListener 추가 * feat: AsyncFestivalUploadImagesStatusChangeEventListener 추가 * feat: 서브모듈 업데이트 * chore: R2Config 메서드 인자로 설정 모두 받도록 변경 * feat: 서브모듈 업데이트 * refactor: R2Config 제거 및 R2StorageClient에서 설정들 의존 받도록 변경 * chore: 서브모듈 업데이트
- Loading branch information
1 parent
ead933c
commit 929dac6
Showing
49 changed files
with
1,833 additions
and
14 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
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/com/festago/admin/dto/upload/AdminImageUploadV1Response.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,9 @@ | ||
package com.festago.admin.dto.upload; | ||
|
||
import java.net.URI; | ||
|
||
public record AdminImageUploadV1Response( | ||
URI uploadUri | ||
) { | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
backend/src/main/java/com/festago/admin/presentation/v1/AdminUploadV1Controller.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,35 @@ | ||
package com.festago.admin.presentation.v1; | ||
|
||
import com.festago.admin.dto.upload.AdminImageUploadV1Response; | ||
import com.festago.upload.application.ImageFileUploadService; | ||
import com.festago.upload.domain.FileOwnerType; | ||
import com.festago.upload.dto.FileUploadResult; | ||
import io.swagger.v3.oas.annotations.Hidden; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@RestController | ||
@RequestMapping("/admin/api/v1/upload/images") | ||
@RequiredArgsConstructor | ||
@Hidden | ||
public class AdminUploadV1Controller { | ||
|
||
private final ImageFileUploadService imageFileUploadService; | ||
|
||
@PostMapping | ||
public ResponseEntity<AdminImageUploadV1Response> uploadImage( | ||
@RequestPart MultipartFile image, | ||
@RequestParam(required = false) Long ownerId, | ||
@RequestParam(required = false) FileOwnerType ownerType | ||
) { | ||
FileUploadResult result = imageFileUploadService.upload(image, ownerId, ownerType); | ||
return ResponseEntity.ok() | ||
.body(new AdminImageUploadV1Response(result.uploadUri())); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/com/festago/artist/dto/event/ArtistCreatedEvent.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,9 @@ | ||
package com.festago.artist.dto.event; | ||
|
||
import com.festago.artist.domain.Artist; | ||
|
||
public record ArtistCreatedEvent( | ||
Artist artist | ||
) { | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...o/artist/dto/event/ArtistDeleteEvent.java → .../artist/dto/event/ArtistDeletedEvent.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
7 changes: 0 additions & 7 deletions
7
backend/src/main/java/com/festago/artist/dto/event/ArtistUpdateEvent.java
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/com/festago/artist/dto/event/ArtistUpdatedEvent.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,9 @@ | ||
package com.festago.artist.dto.event; | ||
|
||
import com.festago.artist.domain.Artist; | ||
|
||
public record ArtistUpdatedEvent( | ||
Artist artist | ||
) { | ||
|
||
} |
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
4 changes: 3 additions & 1 deletion
4
backend/src/main/java/com/festago/festival/dto/event/FestivalCreatedEvent.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,7 +1,9 @@ | ||
package com.festago.festival.dto.event; | ||
|
||
import com.festago.festival.domain.Festival; | ||
|
||
public record FestivalCreatedEvent( | ||
Long festivalId | ||
Festival festival | ||
) { | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/com/festago/festival/dto/event/FestivalUpdatedEvent.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,9 @@ | ||
package com.festago.festival.dto.event; | ||
|
||
import com.festago.festival.domain.Festival; | ||
|
||
public record FestivalUpdatedEvent( | ||
Festival festival | ||
) { | ||
|
||
} |
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
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/com/festago/school/dto/evnet/SchoolCreatedEvent.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,9 @@ | ||
package com.festago.school.dto.evnet; | ||
|
||
import com.festago.school.domain.School; | ||
|
||
public record SchoolCreatedEvent( | ||
School school | ||
) { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
backend/src/main/java/com/festago/school/dto/evnet/SchoolDeletedEvent.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,7 @@ | ||
package com.festago.school.dto.evnet; | ||
|
||
public record SchoolDeletedEvent( | ||
Long schoolId | ||
) { | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/com/festago/school/dto/evnet/SchoolUpdatedEvent.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,9 @@ | ||
package com.festago.school.dto.evnet; | ||
|
||
import com.festago.school.domain.School; | ||
|
||
public record SchoolUpdatedEvent( | ||
School school | ||
) { | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
backend/src/main/java/com/festago/upload/application/ImageFileUploadService.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,65 @@ | ||
package com.festago.upload.application; | ||
|
||
import com.festago.common.exception.BadRequestException; | ||
import com.festago.common.exception.ErrorCode; | ||
import com.festago.common.util.Validator; | ||
import com.festago.upload.domain.FileExtension; | ||
import com.festago.upload.domain.FileOwnerType; | ||
import com.festago.upload.domain.StorageClient; | ||
import com.festago.upload.domain.UploadFile; | ||
import com.festago.upload.dto.FileUploadResult; | ||
import com.festago.upload.repository.UploadFileRepository; | ||
import com.festago.upload.util.FileNameExtensionParser; | ||
import jakarta.annotation.Nullable; | ||
import java.util.EnumSet; | ||
import java.util.Set; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
// 명시적으로 @Transactional 사용하지 않음 | ||
public class ImageFileUploadService { | ||
|
||
private static final int MAX_FILE_SIZE = 2_000_000; // 2MB | ||
private static final Set<FileExtension> ALLOW_IMAGE_EXTENSION = EnumSet.of(FileExtension.JPG, FileExtension.PNG); | ||
|
||
private final StorageClient storageClient; | ||
private final UploadFileRepository uploadFileRepository; | ||
|
||
public FileUploadResult upload(MultipartFile image, @Nullable Long ownerId, @Nullable FileOwnerType ownerType) { | ||
validate(image); | ||
UploadFile uploadImage = storageClient.storage(image); | ||
if (ownerId != null && ownerType != null) { | ||
uploadImage.changeAssigned(ownerId, ownerType); | ||
} | ||
|
||
uploadFileRepository.save(uploadImage); | ||
|
||
return new FileUploadResult(uploadImage.getId(), uploadImage.getUploadUri()); | ||
} | ||
|
||
private void validate(MultipartFile image) { | ||
validateSize(image.getSize()); | ||
validateExtension(image.getOriginalFilename()); | ||
} | ||
|
||
private void validateSize(long imageSize) { | ||
Validator.maxValue(imageSize, MAX_FILE_SIZE, "imageSize"); | ||
} | ||
|
||
private void validateExtension(String imageName) { | ||
Validator.notBlank(imageName, "imageName"); | ||
String extension = FileNameExtensionParser.parse(imageName); | ||
for (FileExtension allowExtension : ALLOW_IMAGE_EXTENSION) { | ||
if (allowExtension.match(extension)) { | ||
return; | ||
} | ||
} | ||
log.info("허용되지 않은 확장자에 대한 이미지 업로드 요청이 있습니다. fileName={}, extension={}", imageName, extension); | ||
throw new BadRequestException(ErrorCode.NOT_SUPPORT_FILE_EXTENSION); | ||
} | ||
} |
Oops, something went wrong.