Skip to content

Commit

Permalink
톡픽 생성 시 파일 ID 목록을 전달하지 않을 때 발생하는 오류 해결 (#696)
Browse files Browse the repository at this point in the history
* feat: TempTalkPick의 모든 필드를 공백 허용하도록 수정

* refactor: DTO 필드 검증 로직 분리

* feat: 톡픽 생성 또는 임시저장 시 이미지 업로드하지 않았을 경우 조건 처리
  • Loading branch information
Hanjaemo authored Nov 6, 2024
1 parent de37785 commit 965b660
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ public class TalkPickService {
public Long createTalkPick(CreateOrUpdateTalkPickRequest request, ApiMember apiMember) {
Member member = apiMember.toMember(memberRepository);
TalkPick savedTalkPick = talkPickRepository.save(request.toEntity(member));
List<File> files = fileRepository.findAllById(request.getFileIds());
fileHandler.relocateFiles(files, savedTalkPick.getId(), TALK_PICK);
return savedTalkPick.getId();
Long savedTalkPickId = savedTalkPick.getId();
relocateFilesIfContainsFileIds(request, savedTalkPickId);
return savedTalkPickId;
}

private void relocateFilesIfContainsFileIds(CreateOrUpdateTalkPickRequest request, Long talkPickId) {
if (request.containsFileIds()) {
List<File> files = fileRepository.findAllById(request.getFileIds());
fileHandler.relocateFiles(files, talkPickId, TALK_PICK);
}
}

@Transactional
Expand Down Expand Up @@ -80,8 +87,7 @@ public void updateTalkPick(Long talkPickId, CreateOrUpdateTalkPickRequest reques
Member member = apiMember.toMember(memberRepository);
TalkPick talkPick = member.getTalkPickById(talkPickId);
talkPick.update(request.toEntity(member));
List<File> files = fileRepository.findAllById(request.getFileIds());
fileHandler.relocateFiles(files, talkPick.getId(), TALK_PICK);
relocateFilesIfContainsFileIds(request, talkPick.getId());
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,22 @@ public class TempTalkPickService {
@Transactional
public void createTempTalkPick(SaveTempTalkPickRequest request, ApiMember apiMember) {
Member member = apiMember.toMember(memberRepository);
List<File> files = fileRepository.findAllById(request.getFileIds());

if (member.hasTempTalkPick()) {
Long tempTalkPickId = member.updateTempTalkPick(request.toEntity(member));
fileHandler.relocateFiles(files, tempTalkPickId, TEMP_TALK_PICK);
relocateFilesIfContainsFileIds(request, tempTalkPickId);
return;
}

TempTalkPick savedTempTalkPick = tempTalkPickRepository.save(request.toEntity(member));
fileHandler.relocateFiles(files, savedTempTalkPick.getId(), TEMP_TALK_PICK);
relocateFilesIfContainsFileIds(request, savedTempTalkPick.getId());
}

private void relocateFilesIfContainsFileIds(SaveTempTalkPickRequest request, Long tempTalkPickId) {
if (request.containsFileIds()) {
List<File> files = fileRepository.findAllById(request.getFileIds());
fileHandler.relocateFiles(files, tempTalkPickId, TEMP_TALK_PICK);
}
}

public FindTempTalkPickResponse findTempTalkPick(ApiMember apiMember) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/balancetalk/talkpick/dto/TalkPickDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public TalkPick toEntity(Member member) {
.editedAt(LocalDateTime.now())
.build();
}

public boolean containsFileIds() {
return fileIds != null;
}
}

@Schema(description = "톡픽 상세 조회 응답")
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/balancetalk/talkpick/dto/TempTalkPickDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public TempTalkPick toEntity(Member member) {
.member(member)
.build();
}

public boolean containsFileIds() {
return fileIds != null;
}
}

@Schema(description = "임시 저장한 톡픽 조회 응답")
Expand Down

0 comments on commit 965b660

Please sign in to comment.