From 965b6609fc32c404d4c9e04117c2ae308e8ad43c Mon Sep 17 00:00:00 2001 From: Hanjaemo <110653660+Hanjaemo@users.noreply.github.com> Date: Thu, 7 Nov 2024 02:43:33 +0900 Subject: [PATCH] =?UTF-8?q?=ED=86=A1=ED=94=BD=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EC=8B=9C=20=ED=8C=8C=EC=9D=BC=20ID=20=EB=AA=A9=EB=A1=9D?= =?UTF-8?q?=EC=9D=84=20=EC=A0=84=EB=8B=AC=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=9D=84=20=EB=95=8C=20=EB=B0=9C=EC=83=9D=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0=20(#696)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: TempTalkPick의 모든 필드를 공백 허용하도록 수정 * refactor: DTO 필드 검증 로직 분리 * feat: 톡픽 생성 또는 임시저장 시 이미지 업로드하지 않았을 경우 조건 처리 --- .../talkpick/application/TalkPickService.java | 16 +++++++++++----- .../application/TempTalkPickService.java | 12 +++++++++--- .../balancetalk/talkpick/dto/TalkPickDto.java | 4 ++++ .../talkpick/dto/TempTalkPickDto.java | 4 ++++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main/java/balancetalk/talkpick/application/TalkPickService.java b/src/main/java/balancetalk/talkpick/application/TalkPickService.java index f431047d4..ab9a5fa9e 100644 --- a/src/main/java/balancetalk/talkpick/application/TalkPickService.java +++ b/src/main/java/balancetalk/talkpick/application/TalkPickService.java @@ -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 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 files = fileRepository.findAllById(request.getFileIds()); + fileHandler.relocateFiles(files, talkPickId, TALK_PICK); + } } @Transactional @@ -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 files = fileRepository.findAllById(request.getFileIds()); - fileHandler.relocateFiles(files, talkPick.getId(), TALK_PICK); + relocateFilesIfContainsFileIds(request, talkPick.getId()); } @Transactional diff --git a/src/main/java/balancetalk/talkpick/application/TempTalkPickService.java b/src/main/java/balancetalk/talkpick/application/TempTalkPickService.java index f3bfd523f..d46367e8c 100644 --- a/src/main/java/balancetalk/talkpick/application/TempTalkPickService.java +++ b/src/main/java/balancetalk/talkpick/application/TempTalkPickService.java @@ -31,16 +31,22 @@ public class TempTalkPickService { @Transactional public void createTempTalkPick(SaveTempTalkPickRequest request, ApiMember apiMember) { Member member = apiMember.toMember(memberRepository); - List 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 files = fileRepository.findAllById(request.getFileIds()); + fileHandler.relocateFiles(files, tempTalkPickId, TEMP_TALK_PICK); + } } public FindTempTalkPickResponse findTempTalkPick(ApiMember apiMember) { diff --git a/src/main/java/balancetalk/talkpick/dto/TalkPickDto.java b/src/main/java/balancetalk/talkpick/dto/TalkPickDto.java index c29d3feaa..decbd5a5b 100644 --- a/src/main/java/balancetalk/talkpick/dto/TalkPickDto.java +++ b/src/main/java/balancetalk/talkpick/dto/TalkPickDto.java @@ -47,6 +47,10 @@ public TalkPick toEntity(Member member) { .editedAt(LocalDateTime.now()) .build(); } + + public boolean containsFileIds() { + return fileIds != null; + } } @Schema(description = "톡픽 상세 조회 응답") diff --git a/src/main/java/balancetalk/talkpick/dto/TempTalkPickDto.java b/src/main/java/balancetalk/talkpick/dto/TempTalkPickDto.java index 7222bd715..009bbaa3f 100644 --- a/src/main/java/balancetalk/talkpick/dto/TempTalkPickDto.java +++ b/src/main/java/balancetalk/talkpick/dto/TempTalkPickDto.java @@ -30,6 +30,10 @@ public TempTalkPick toEntity(Member member) { .member(member) .build(); } + + public boolean containsFileIds() { + return fileIds != null; + } } @Schema(description = "임시 저장한 톡픽 조회 응답")