diff --git a/src/main/java/balancetalk/file/domain/repository/FileRepository.java b/src/main/java/balancetalk/file/domain/repository/FileRepository.java index 612bf7665..0b77e7fe1 100644 --- a/src/main/java/balancetalk/file/domain/repository/FileRepository.java +++ b/src/main/java/balancetalk/file/domain/repository/FileRepository.java @@ -1,8 +1,10 @@ package balancetalk.file.domain.repository; import balancetalk.file.domain.File; +import balancetalk.file.domain.FileType; import org.springframework.data.jpa.repository.JpaRepository; public interface FileRepository extends JpaRepository, FileRepositoryCustom { + void deleteByResourceIdAndFileType(Long tempTalkPickId, FileType fileType); } diff --git a/src/main/java/balancetalk/talkpick/application/TempTalkPickService.java b/src/main/java/balancetalk/talkpick/application/TempTalkPickService.java index 3979aba26..fcdbd2826 100644 --- a/src/main/java/balancetalk/talkpick/application/TempTalkPickService.java +++ b/src/main/java/balancetalk/talkpick/application/TempTalkPickService.java @@ -34,6 +34,9 @@ public void createTempTalkPick(SaveTempTalkPickRequest request, ApiMember apiMem if (member.hasTempTalkPick()) { Long tempTalkPickId = member.updateTempTalkPick(request.toEntity(member)); + if (request.isNewRequest()) { + fileRepository.deleteByResourceIdAndFileType(tempTalkPickId, TEMP_TALK_PICK); + } relocateFilesIfContainsFileIds(request, tempTalkPickId); return; } @@ -49,6 +52,7 @@ private void relocateFilesIfContainsFileIds(SaveTempTalkPickRequest request, Lon List deletedFileIds = deleteRequestedFiles(request); + if (request.containsNewFileIds()) { List newFileIds = request.getNewFileIds(); newFileIds.removeIf((deletedFileIds::contains)); diff --git a/src/main/java/balancetalk/talkpick/dto/TalkPickDto.java b/src/main/java/balancetalk/talkpick/dto/TalkPickDto.java index a7187cfc5..e00c1b7d7 100644 --- a/src/main/java/balancetalk/talkpick/dto/TalkPickDto.java +++ b/src/main/java/balancetalk/talkpick/dto/TalkPickDto.java @@ -14,6 +14,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.querydsl.core.annotations.QueryProjection; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.Size; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; @@ -31,6 +32,7 @@ public static class CreateTalkPickRequest { private BaseTalkPickFields baseFields; @Schema(description = "첨부한 이미지 파일 ID 목록", example = "[12, 41]") + @Size(max = 10, message = "톡픽 생성 시 업로드할 수 있는 파일 개수는 최대 10개입니다.") private List fileIds; public TalkPick toEntity(Member member) { @@ -61,6 +63,7 @@ public static class UpdateTalkPickRequest { private BaseTalkPickFields baseFields; @Schema(description = "새로 첨부한 이미지 파일 ID 목록", example = "[12, 41]") + @Size(max = 10, message = "톡픽 생성 시 업로드할 수 있는 파일 개수는 최대 10개입니다.") private List newFileIds; @Schema(description = "제거할 이미지 파일 ID 목록", example = "[3, 7]") diff --git a/src/main/java/balancetalk/talkpick/dto/TempTalkPickDto.java b/src/main/java/balancetalk/talkpick/dto/TempTalkPickDto.java index 3f51f7810..0383d05a4 100644 --- a/src/main/java/balancetalk/talkpick/dto/TempTalkPickDto.java +++ b/src/main/java/balancetalk/talkpick/dto/TempTalkPickDto.java @@ -3,6 +3,8 @@ import balancetalk.member.domain.Member; import balancetalk.talkpick.domain.TempTalkPick; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import java.util.List; import lombok.AllArgsConstructor; import lombok.Builder; @@ -18,11 +20,16 @@ public static class SaveTempTalkPickRequest { private BaseTempTalkPickFields baseFields; @Schema(description = "새로 첨부한 이미지 파일 ID 목록", example = "[12, 41]") + @Size(max = 10, message = "톡픽 생성 시 업로드할 수 있는 파일 개수는 최대 10개입니다.") private List newFileIds; @Schema(description = "제거할 이미지 파일 ID 목록", example = "[3, 7]") private List deleteFileIds; + @Schema(description = "최근 임시저장된 톡픽 불러오기 여부", example = "true") + @NotNull(message = "isLoaded 필드는 NULL을 허용하지 않습니다.") + private Boolean isLoaded; + public TempTalkPick toEntity(Member member) { return TempTalkPick.builder() .title(baseFields.getTitle()) @@ -34,6 +41,10 @@ public TempTalkPick toEntity(Member member) { .build(); } + public boolean isNewRequest() { + return !isLoaded; + } + public boolean containsNewFileIds() { return newFileIds != null && !newFileIds.isEmpty(); }