Skip to content

Commit

Permalink
톡픽 임시 저장 시 이미지가 중첩되는 문제 해결 (#722)
Browse files Browse the repository at this point in the history
* fix: 톡픽 임시 저장 API 요청 DTO에 isLoaded 추가 및 그에 따른 로직 구현

* feat: 누락된 검증 어노테이션 추가
  • Loading branch information
Hanjaemo authored Nov 24, 2024
1 parent 3cad886 commit b704e24
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<File, Long>, FileRepositoryCustom {

void deleteByResourceIdAndFileType(Long tempTalkPickId, FileType fileType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -49,6 +52,7 @@ private void relocateFilesIfContainsFileIds(SaveTempTalkPickRequest request, Lon

List<Long> deletedFileIds = deleteRequestedFiles(request);


if (request.containsNewFileIds()) {
List<Long> newFileIds = request.getNewFileIds();
newFileIds.removeIf((deletedFileIds::contains));
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/balancetalk/talkpick/dto/TalkPickDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,7 @@ public static class CreateTalkPickRequest {
private BaseTalkPickFields baseFields;

@Schema(description = "첨부한 이미지 파일 ID 목록", example = "[12, 41]")
@Size(max = 10, message = "톡픽 생성 시 업로드할 수 있는 파일 개수는 최대 10개입니다.")
private List<Long> fileIds;

public TalkPick toEntity(Member member) {
Expand Down Expand Up @@ -61,6 +63,7 @@ public static class UpdateTalkPickRequest {
private BaseTalkPickFields baseFields;

@Schema(description = "새로 첨부한 이미지 파일 ID 목록", example = "[12, 41]")
@Size(max = 10, message = "톡픽 생성 시 업로드할 수 있는 파일 개수는 최대 10개입니다.")
private List<Long> newFileIds;

@Schema(description = "제거할 이미지 파일 ID 목록", example = "[3, 7]")
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/balancetalk/talkpick/dto/TempTalkPickDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,11 +20,16 @@ public static class SaveTempTalkPickRequest {
private BaseTempTalkPickFields baseFields;

@Schema(description = "새로 첨부한 이미지 파일 ID 목록", example = "[12, 41]")
@Size(max = 10, message = "톡픽 생성 시 업로드할 수 있는 파일 개수는 최대 10개입니다.")
private List<Long> newFileIds;

@Schema(description = "제거할 이미지 파일 ID 목록", example = "[3, 7]")
private List<Long> deleteFileIds;

@Schema(description = "최근 임시저장된 톡픽 불러오기 여부", example = "true")
@NotNull(message = "isLoaded 필드는 NULL을 허용하지 않습니다.")
private Boolean isLoaded;

public TempTalkPick toEntity(Member member) {
return TempTalkPick.builder()
.title(baseFields.getTitle())
Expand All @@ -34,6 +41,10 @@ public TempTalkPick toEntity(Member member) {
.build();
}

public boolean isNewRequest() {
return !isLoaded;
}

public boolean containsNewFileIds() {
return newFileIds != null && !newFileIds.isEmpty();
}
Expand Down

0 comments on commit b704e24

Please sign in to comment.