From e2aac97832ce4b36f74f2ace7982658d80b71cea Mon Sep 17 00:00:00 2001 From: "tae.y" <0211ilyoil@gmail.com> Date: Sun, 17 Nov 2024 23:54:38 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20::=20(856)=20=EC=9E=AC?= =?UTF-8?q?=EC=A7=80=EC=9B=90=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/usecase/DeleteApplicationUseCase.java | 2 ++ .../jobis/domain/notice/usecase/CreateNoticeUseCase.java | 2 +- .../persistence/ApplicationPersistenceAdapter.java | 4 +--- .../application/persistence/entity/ApplicationEntity.java | 3 ++- .../persistence/repository/ApplicationJpaRepository.java | 6 +++++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/DeleteApplicationUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/DeleteApplicationUseCase.java index d96fbaf11..1ab869e47 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/DeleteApplicationUseCase.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/DeleteApplicationUseCase.java @@ -17,11 +17,13 @@ public class DeleteApplicationUseCase { private final SecurityPort securityPort; public void execute(Long applicationId) { + Student student = securityPort.getCurrentStudent(); Application application = queryApplicationPort.getByIdOrThrow(applicationId); application.checkIsDeletable(student); + commandApplicationPort.deleteAllByApplicationId(applicationId); commandApplicationPort.delete(application); } } diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/notice/usecase/CreateNoticeUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/notice/usecase/CreateNoticeUseCase.java index ef50e5135..662ac89d6 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/notice/usecase/CreateNoticeUseCase.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/notice/usecase/CreateNoticeUseCase.java @@ -20,7 +20,7 @@ public class CreateNoticeUseCase { public void execute(CreateNoticeRequest request) { List attachments = request.getAttachments().stream() - .filter(attachment -> attachment.getUrl() != null && attachment.getType() != null) // URL과 Type이 null이 아닌 경우만 필터링 + .filter(attachment -> attachment.getUrl() != null && attachment.getType() != null) .map(attachment -> new NoticeAttachment(attachment.getUrl(), attachment.getType())) .toList(); diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/persistence/ApplicationPersistenceAdapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/persistence/ApplicationPersistenceAdapter.java index eb646111d..6b2d030e5 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/persistence/ApplicationPersistenceAdapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/persistence/ApplicationPersistenceAdapter.java @@ -323,9 +323,7 @@ public void saveAll(List applications) { @Override public void deleteAllByApplicationId(Long applicationId) { - queryFactory.delete(applicationAttachmentEntity) - .where(applicationAttachmentEntity.application.id.eq(applicationId)) - .execute(); + applicationJpaRepository.deleteAttachmentsByApplicationId(applicationId); } @Override diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/persistence/entity/ApplicationEntity.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/persistence/entity/ApplicationEntity.java index 32a145ac2..39d49ecdd 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/persistence/entity/ApplicationEntity.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/persistence/entity/ApplicationEntity.java @@ -22,6 +22,7 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import team.retum.jobis.domain.application.model.ApplicationStatus; +import team.retum.jobis.domain.notice.persistence.entity.NoticeAttachmentEntity; import team.retum.jobis.domain.recruitment.persistence.entity.RecruitmentEntity; import team.retum.jobis.domain.student.persistence.entity.StudentEntity; import team.retum.jobis.global.entity.BaseTimeEntity; @@ -64,7 +65,7 @@ public class ApplicationEntity extends BaseTimeEntity { @JoinColumn(name = "recruitment_id", nullable = false) private RecruitmentEntity recruitment; - @OneToMany(mappedBy = "application", cascade = CascadeType.ALL, orphanRemoval = true) + @OneToMany(mappedBy = "application", cascade = CascadeType.ALL) private List applicationAttachments = new ArrayList<>(); @LastModifiedDate diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/persistence/repository/ApplicationJpaRepository.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/persistence/repository/ApplicationJpaRepository.java index a1a47b0e5..c02892a60 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/persistence/repository/ApplicationJpaRepository.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/persistence/repository/ApplicationJpaRepository.java @@ -1,8 +1,8 @@ package team.retum.jobis.domain.application.persistence.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; -import team.retum.jobis.domain.application.model.ApplicationStatus; import team.retum.jobis.domain.application.persistence.entity.ApplicationEntity; import java.util.List; @@ -14,6 +14,10 @@ public interface ApplicationJpaRepository extends JpaRepository applicationIds); + @Modifying + @Query("delete from ApplicationAttachmentEntity a where a.application.id = ?1") + void deleteAttachmentsByApplicationId(Long applicationId); + @Query("select a from ApplicationEntity a join fetch a.applicationAttachments where a.id=?1") Optional findByIdFetch(Long applicationId); }