diff --git a/src/main/java/com/umc/naoman/domain/agenda/dto/AgendaResponse.java b/src/main/java/com/umc/naoman/domain/agenda/dto/AgendaResponse.java index 85bce4c..95a8a6b 100644 --- a/src/main/java/com/umc/naoman/domain/agenda/dto/AgendaResponse.java +++ b/src/main/java/com/umc/naoman/domain/agenda/dto/AgendaResponse.java @@ -39,7 +39,7 @@ public static class PagedAgendaDetailInfo { private List agendaDetailInfoList; private int totalPages; private long totalElements; // 해당 조건에 부합하는 요소의 총 개수 - private boolean isFirst; // 첫 페이지 여부 - private boolean isLast; // 마지막 페이지 여부 + private Boolean isFirst; // 첫 페이지 여부 + private Boolean isLast; // 마지막 페이지 여부 } } diff --git a/src/main/java/com/umc/naoman/domain/agenda/entity/AgendaPhoto.java b/src/main/java/com/umc/naoman/domain/agenda/entity/AgendaPhoto.java index e09f69b..9f174da 100644 --- a/src/main/java/com/umc/naoman/domain/agenda/entity/AgendaPhoto.java +++ b/src/main/java/com/umc/naoman/domain/agenda/entity/AgendaPhoto.java @@ -40,4 +40,8 @@ public void delete() { } super.delete(); } + + public void nullifyPhoto() { + this.photo = null; + } } \ No newline at end of file diff --git a/src/main/java/com/umc/naoman/domain/agenda/repository/AgendaPhotoRepository.java b/src/main/java/com/umc/naoman/domain/agenda/repository/AgendaPhotoRepository.java index 47e518f..31da359 100644 --- a/src/main/java/com/umc/naoman/domain/agenda/repository/AgendaPhotoRepository.java +++ b/src/main/java/com/umc/naoman/domain/agenda/repository/AgendaPhotoRepository.java @@ -2,6 +2,7 @@ import com.umc.naoman.domain.agenda.entity.AgendaPhoto; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import java.util.List; @@ -10,4 +11,5 @@ public interface AgendaPhotoRepository extends JpaRepository { List findByAgendaId(Long agendaId); List findByPhotoId(Long photoId); + List findByPhotoIdIn(List photoIdList); } diff --git a/src/main/java/com/umc/naoman/domain/agenda/service/AgendaPhotoService.java b/src/main/java/com/umc/naoman/domain/agenda/service/AgendaPhotoService.java index 74ec969..0677b68 100644 --- a/src/main/java/com/umc/naoman/domain/agenda/service/AgendaPhotoService.java +++ b/src/main/java/com/umc/naoman/domain/agenda/service/AgendaPhotoService.java @@ -11,4 +11,5 @@ public interface AgendaPhotoService { AgendaPhoto findAgendaPhoto(Long agendaPhotoId); List findAgendaPhotoList(Long agendaId); List findAgendaPhotoListByPhotoId(Long photoId); + void nullifyPhotoInAgendaPhotoList(List photoIdList); } diff --git a/src/main/java/com/umc/naoman/domain/agenda/service/AgendaPhotoServiceImpl.java b/src/main/java/com/umc/naoman/domain/agenda/service/AgendaPhotoServiceImpl.java index 8ad4211..c2fa617 100644 --- a/src/main/java/com/umc/naoman/domain/agenda/service/AgendaPhotoServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/agenda/service/AgendaPhotoServiceImpl.java @@ -5,7 +5,7 @@ import com.umc.naoman.domain.agenda.entity.AgendaPhoto; import com.umc.naoman.domain.agenda.repository.AgendaPhotoRepository; import com.umc.naoman.domain.photo.entity.Photo; -import com.umc.naoman.domain.photo.service.PhotoService; +import com.umc.naoman.domain.photo.service.PhotoQueryService; import com.umc.naoman.global.error.BusinessException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -19,14 +19,14 @@ @Transactional(readOnly = true) @RequiredArgsConstructor public class AgendaPhotoServiceImpl implements AgendaPhotoService { - private final PhotoService photoService; + private final PhotoQueryService photoQueryService; private final AgendaPhotoRepository agendaPhotoRepository; @Override @Transactional public void saveAgendaPhotoList(Agenda agenda, List photos) { for (Long photoId : photos) { - Photo photo = photoService.findPhoto(photoId); + Photo photo = photoQueryService.findPhoto(photoId); agendaPhotoRepository.save(AgendaPhotoConverter.toEntity(agenda, photo)); } } @@ -46,4 +46,12 @@ public List findAgendaPhotoList(Long agendaId) { public List findAgendaPhotoListByPhotoId(Long photoId) { return agendaPhotoRepository.findByPhotoId(photoId); } + + @Override + @Transactional + public void nullifyPhotoInAgendaPhotoList(List photoIdList) { + List agendaPhotoList = agendaPhotoRepository.findByPhotoIdIn(photoIdList); + agendaPhotoList + .forEach(AgendaPhoto::nullifyPhoto); + } } diff --git a/src/main/java/com/umc/naoman/domain/agenda/service/AgendaServiceImpl.java b/src/main/java/com/umc/naoman/domain/agenda/service/AgendaServiceImpl.java index 6bc386e..4092972 100644 --- a/src/main/java/com/umc/naoman/domain/agenda/service/AgendaServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/agenda/service/AgendaServiceImpl.java @@ -28,9 +28,9 @@ @Transactional(readOnly = true) @RequiredArgsConstructor public class AgendaServiceImpl implements AgendaService { - private final AgendaRepository agendaRepository; private final ShareGroupService shareGroupService; private final AgendaPhotoService agendaPhotoService; + private final AgendaRepository agendaRepository; private final AgendaConverter agendaConverter; @Override diff --git a/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java b/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java index 5d218d7..d02f5c8 100644 --- a/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java @@ -13,6 +13,7 @@ import com.umc.naoman.domain.member.entity.SocialType; import com.umc.naoman.domain.member.repository.MemberRepository; import com.umc.naoman.domain.member.service.redis.RefreshTokenService; +import com.umc.naoman.domain.photo.service.PhotoQueryService; import com.umc.naoman.domain.photo.service.PhotoService; import com.umc.naoman.domain.shareGroup.entity.Profile; import com.umc.naoman.domain.shareGroup.entity.Role; @@ -35,6 +36,7 @@ public class MemberServiceImpl implements MemberService { private final RefreshTokenService refreshTokenService; private final PhotoService photoService; + private final PhotoQueryService photoQueryService; private final MemberRepository memberRepository; private final MemberConverter memberConverter; private final ShareGroupService shareGroupService; @@ -97,7 +99,7 @@ public CheckMemberRegistration checkRegistration(LoginRequest request) { @Override public HasSamplePhoto hasSamplePhoto(Member member) { - boolean hasSamplePhoto = photoService.hasSamplePhoto(member); + boolean hasSamplePhoto = photoQueryService.hasSamplePhoto(member); return memberConverter.toHasSamplePhoto(hasSamplePhoto); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoQueryService.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoQueryService.java new file mode 100644 index 0000000..b34d257 --- /dev/null +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoQueryService.java @@ -0,0 +1,9 @@ +package com.umc.naoman.domain.photo.service; + +import com.umc.naoman.domain.member.entity.Member; +import com.umc.naoman.domain.photo.entity.Photo; + +public interface PhotoQueryService { + Photo findPhoto(Long photoId); + boolean hasSamplePhoto(Member member); +} diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoQueryServiceImpl.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoQueryServiceImpl.java new file mode 100644 index 0000000..229a485 --- /dev/null +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoQueryServiceImpl.java @@ -0,0 +1,31 @@ +package com.umc.naoman.domain.photo.service; + +import com.umc.naoman.domain.member.entity.Member; +import com.umc.naoman.domain.photo.entity.Photo; +import com.umc.naoman.domain.photo.repository.PhotoRepository; +import com.umc.naoman.domain.photo.repository.SamplePhotoRepository; +import com.umc.naoman.global.error.BusinessException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import static com.umc.naoman.global.error.code.S3ErrorCode.PHOTO_NOT_FOUND; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class PhotoQueryServiceImpl implements PhotoQueryService { + private final PhotoRepository photoRepository; + private final SamplePhotoRepository samplePhotoRepository; + + @Override + public Photo findPhoto(Long photoId) { + return photoRepository.findById(photoId) + .orElseThrow(() -> new BusinessException(PHOTO_NOT_FOUND)); + } + + @Override + public boolean hasSamplePhoto(Member member) { + return samplePhotoRepository.existsByMemberId(member.getId()); + } +} diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java index a75c1e6..7e714cc 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoService.java @@ -34,7 +34,7 @@ public interface PhotoService { void deleteSamplePhotoList(Member member); - Photo findPhoto(Long photoId); +// Photo findPhoto(Long photoId); - boolean hasSamplePhoto(Member member); +// boolean hasSamplePhoto(Member member); } diff --git a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java index 5bb8495..8967522 100644 --- a/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/photo/service/PhotoServiceImpl.java @@ -5,6 +5,7 @@ import com.amazonaws.services.s3.Headers; import com.amazonaws.services.s3.model.CannedAccessControlList; import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; +import com.umc.naoman.domain.agenda.service.AgendaPhotoService; import com.umc.naoman.domain.member.entity.Member; import com.umc.naoman.domain.photo.converter.PhotoConverter; import com.umc.naoman.domain.photo.converter.SamplePhotoConverter; @@ -51,6 +52,7 @@ @RequiredArgsConstructor public class PhotoServiceImpl implements PhotoService { private final ShareGroupService shareGroupService; + private final AgendaPhotoService agendaPhotoService; private final FaceDetectionService faceDetectionService; private final PhotoRepository photoRepository; private final SamplePhotoRepository samplePhotoRepository; @@ -346,8 +348,10 @@ public void deletePhotoListByShareGroupId(Long shareGroupId) { // Elasticsearch 사진 데이터 삭제 List photoIdList = photoEsClientRepository.deletePhotoEsByShareGroupId(shareGroupId); - List photoList = photoRepository.findByIdIn(photoIdList); + // 삭제하려는 사진들 중 안건 후보로 등록된 것들에 대하여, 해당 사진들의 참조를 삭제 + agendaPhotoService.nullifyPhotoInAgendaPhotoList(photoIdList); + List photoList = photoRepository.findByIdIn(photoIdList); // S3 버킷 사진 데이터 삭제 for (Photo photo : photoList) { deletePhoto(photo.getName()); @@ -380,6 +384,7 @@ private void validateShareGroupAndProfile(Long shareGroupId, Member member) { shareGroupService.findProfile(shareGroupId, member.getId()); } + /* @Override public Photo findPhoto(Long photoId) { return photoRepository.findById(photoId) @@ -390,4 +395,5 @@ public Photo findPhoto(Long photoId) { public boolean hasSamplePhoto(Member member) { return samplePhotoRepository.existsByMemberId(member.getId()); } + */ }