From a26f1dee02d320895be30c7c3d6e2020f2f00710 Mon Sep 17 00:00:00 2001 From: KoSeonJe <127813439+KoSeonJe@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:12:29 +0900 Subject: [PATCH 1/8] =?UTF-8?q?feat=20:=20=ED=94=BC=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/feed/api/ClubFeedApi.java | 17 ++++++++++++++--- .../feed/controller/ClubFeedController.java | 5 +++++ .../feed/service/FacadeClubFeedService.java | 1 + .../feed/service/FacadeClubFeedServiceImpl.java | 15 +++++++++++++++ .../domain/feed/service/FeedService.java | 2 ++ .../domain/feed/service/GeneralFeedService.java | 5 +++++ 6 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/main/java/ddingdong/ddingdongBE/domain/feed/api/ClubFeedApi.java b/src/main/java/ddingdong/ddingdongBE/domain/feed/api/ClubFeedApi.java index 551bbc2c..5d305614 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/feed/api/ClubFeedApi.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/feed/api/ClubFeedApi.java @@ -10,6 +10,7 @@ import jakarta.validation.Valid; import org.springframework.http.HttpStatus; import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -18,14 +19,14 @@ import org.springframework.web.bind.annotation.ResponseStatus; @Tag(name = "Feed - Club", description = "Feed API") -@RequestMapping("/server") +@RequestMapping("/server/central") public interface ClubFeedApi { @Operation(summary = "동아리 피드 생성 API") @ApiResponse(responseCode = "201", description = "동아리 피드 생성 성공") @ResponseStatus(HttpStatus.CREATED) @SecurityRequirement(name = "AccessToken") - @PostMapping("/central/clubs/feeds") + @PostMapping("/clubs/feeds") void createFeed( @RequestBody @Valid CreateFeedRequest createFeedRequest, @AuthenticationPrincipal PrincipalDetails principalDetails @@ -35,9 +36,19 @@ void createFeed( @ApiResponse(responseCode = "204", description = "동아리 피드 수정 성공") @ResponseStatus(HttpStatus.NO_CONTENT) @SecurityRequirement(name = "AccessToken") - @PutMapping("/central/clubs/feeds/{feedId}") + @PutMapping("/clubs/feeds/{feedId}") void updateFeed( @PathVariable("feedId") Long feedId, @RequestBody @Valid UpdateFeedRequest updateFeedRequest ); + + @Operation(summary = "동아리 피드 삭제 API") + @ApiResponse(responseCode = "204", description = "동아리 피드 삭제 성공") + @ResponseStatus(HttpStatus.NO_CONTENT) + @SecurityRequirement(name = "AccessToken") + @DeleteMapping("/clubs/feeds/{feedId}") + void deleteFeed( + @PathVariable("feedId") Long feedId + ); + } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/feed/controller/ClubFeedController.java b/src/main/java/ddingdong/ddingdongBE/domain/feed/controller/ClubFeedController.java index 7c54e6c6..28ea356f 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/feed/controller/ClubFeedController.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/feed/controller/ClubFeedController.java @@ -31,4 +31,9 @@ public void updateFeed( ) { facadeClubFeedService.update(updateFeedRequest.toCommand(feedId)); } + + @Override + public void deleteFeed(Long feedId) { + facadeClubFeedService.delete(feedId); + } } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedService.java b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedService.java index 1da7ba72..2278ffc0 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedService.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedService.java @@ -9,4 +9,5 @@ public interface FacadeClubFeedService { void update(UpdateFeedCommand command); + void delete(Long feedId); } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java index eb3caaa2..582d156c 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java @@ -29,6 +29,7 @@ public void create(CreateFeedCommand command) { if (feed.isImage()) { fileMetaDataService.updateStatusToCoupled(command.mediaId(), DomainType.FEED_IMAGE, createdId); + return; } if (feed.isVideo()) { @@ -43,4 +44,18 @@ public void update(UpdateFeedCommand command) { Feed updateFeed = command.toEntity(); originFeed.update(updateFeed); } + + @Override + public void delete(Long feedId) { + Feed feed = feedService.getById(feedId); + feedService.delete(feed); + if (feed.isImage()) { + fileMetaDataService.updateStatusToDelete(DomainType.FEED_IMAGE, feedId); + return; + } + + if (feed.isVideo()) { + fileMetaDataService.updateStatusToDelete(DomainType.FEED_VIDEO, feedId); + } + } } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FeedService.java b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FeedService.java index a1880a71..cfde800c 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FeedService.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FeedService.java @@ -12,4 +12,6 @@ public interface FeedService { Feed getById(Long feedId); Long create(Feed feed); + + void delete(Feed feed); } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/GeneralFeedService.java b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/GeneralFeedService.java index c1512f42..d289c4b1 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/GeneralFeedService.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/GeneralFeedService.java @@ -37,4 +37,9 @@ public Long create(Feed feed) { Feed savedFeed = feedRepository.save(feed); return savedFeed.getId(); } + + @Override + public void delete(Feed feed) { + feedRepository.delete(feed); + } } From f845b05f8322fd9f02f437e751d3898e5447b57f Mon Sep 17 00:00:00 2001 From: KoSeonJe <127813439+KoSeonJe@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:12:42 +0900 Subject: [PATCH 2/8] =?UTF-8?q?test=20:=20=ED=94=BC=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20API=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FacadeClubFeedServiceImplTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/test/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImplTest.java b/src/test/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImplTest.java index 8d6dd1c1..340efc33 100644 --- a/src/test/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImplTest.java +++ b/src/test/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImplTest.java @@ -19,6 +19,7 @@ import ddingdong.ddingdongBE.domain.filemetadata.entity.FileMetaData; import ddingdong.ddingdongBE.domain.filemetadata.entity.FileStatus; import ddingdong.ddingdongBE.domain.filemetadata.repository.FileMetaDataRepository; +import ddingdong.ddingdongBE.domain.filemetadata.service.FileMetaDataServiceImpl; import ddingdong.ddingdongBE.domain.scorehistory.entity.Score; import ddingdong.ddingdongBE.domain.user.entity.User; import ddingdong.ddingdongBE.domain.user.repository.UserRepository; @@ -47,6 +48,8 @@ class FacadeClubFeedServiceImplTest extends TestContainerSupport { private EntityManager entityManager; private final FixtureMonkey fixtureMonkey = FixtureMonkeyFactory.getNotNullBuilderIntrospectorMonkey(); + @Autowired + private FileMetaDataServiceImpl fileMetaDataServiceImpl; @DisplayName("요청된 Command를 사용하여 feed를 생성하며, FileMetaData를 Couple 상태로 변경한다.") @Test @@ -111,4 +114,36 @@ void update() { assertThat(finded).isNotNull(); assertThat(finded.getActivityContent()).isEqualTo("변경된 활동내용"); } + + @DisplayName("주어진 feedId를 가진 Feed 엔터티를 삭제 및 fileMetaData 상태를 DELETED로 변경") + @Test + void delete() { + // given + Long entityId = 1L; + UUID uuid = UuidCreator.getTimeOrderedEpoch(); + + fileMetaDataRepository.save( + fixtureMonkey.giveMeBuilder(FileMetaData.class) + .set("id", uuid) + .set("entityId", entityId) + .set("domainType", DomainType.FEED_IMAGE) + .set("fileStatus", FileStatus.COUPLED) + .sample() + ); + feedRepository.save( + fixtureMonkey.giveMeBuilder(Feed.class) + .set("id", entityId) + .set("feedType", FeedType.IMAGE) + .set("club", null) + .sample() + ); + // when + facadeClubFeedService.delete(entityId); + // then + Feed feed = feedRepository.findById(entityId).orElse(null); + FileMetaData fileMetaData = fileMetaDataRepository.findById(uuid).orElse(null); + assertThat(feed).isNull(); + assertThat(fileMetaData).isNotNull(); + assertThat(fileMetaData.getFileStatus()).isEqualTo(FileStatus.DELETED); + } } From f893e7725c141cd1f22d3868b7bcaab054a07654 Mon Sep 17 00:00:00 2001 From: KoSeonJe <127813439+KoSeonJe@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:21:31 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feat=20:=20@Transactional=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/feed/service/FacadeClubFeedServiceImpl.java | 1 + .../ddingdongBE/domain/feed/service/GeneralFeedService.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java index 582d156c..da629ff3 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java @@ -46,6 +46,7 @@ public void update(UpdateFeedCommand command) { } @Override + @Transactional public void delete(Long feedId) { Feed feed = feedService.getById(feedId); feedService.delete(feed); diff --git a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/GeneralFeedService.java b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/GeneralFeedService.java index d289c4b1..47c66fd5 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/GeneralFeedService.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/GeneralFeedService.java @@ -39,6 +39,7 @@ public Long create(Feed feed) { } @Override + @Transactional public void delete(Feed feed) { feedRepository.delete(feed); } From 3846a831e9cd63e0a009d3fcaf7e8e6d32afa9b1 Mon Sep 17 00:00:00 2001 From: KoSeonJe <127813439+KoSeonJe@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:50:12 +0900 Subject: [PATCH 4/8] =?UTF-8?q?test=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FacadeClubFeedServiceImplTest.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/test/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImplTest.java b/src/test/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImplTest.java index 340efc33..ab45223f 100644 --- a/src/test/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImplTest.java +++ b/src/test/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImplTest.java @@ -119,28 +119,30 @@ void update() { @Test void delete() { // given - Long entityId = 1L; UUID uuid = UuidCreator.getTimeOrderedEpoch(); + + Feed savedFeed = feedRepository.save( + fixtureMonkey.giveMeBuilder(Feed.class) + .set("feedType", FeedType.IMAGE) + .set("activityContent", "활동내용") + .set("club", null) + .sample() + ); fileMetaDataRepository.save( fixtureMonkey.giveMeBuilder(FileMetaData.class) .set("id", uuid) - .set("entityId", entityId) + .set("entityId", savedFeed.getId()) .set("domainType", DomainType.FEED_IMAGE) .set("fileStatus", FileStatus.COUPLED) .sample() ); - feedRepository.save( - fixtureMonkey.giveMeBuilder(Feed.class) - .set("id", entityId) - .set("feedType", FeedType.IMAGE) - .set("club", null) - .sample() - ); + entityManager.flush(); // when - facadeClubFeedService.delete(entityId); + facadeClubFeedService.delete(savedFeed.getId()); + entityManager.flush(); // then - Feed feed = feedRepository.findById(entityId).orElse(null); + Feed feed = feedRepository.findById(savedFeed.getId()).orElse(null); FileMetaData fileMetaData = fileMetaDataRepository.findById(uuid).orElse(null); assertThat(feed).isNull(); assertThat(fileMetaData).isNotNull(); From 34ef7ed815c3d28bbf414941abf5afde0384d481 Mon Sep 17 00:00:00 2001 From: KoSeonJe <127813439+KoSeonJe@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:04:54 +0900 Subject: [PATCH 5/8] =?UTF-8?q?test=20:=20video=EC=9D=BC=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FacadeClubFeedServiceImplTest.java | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/test/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImplTest.java b/src/test/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImplTest.java index ab45223f..0a6d1f24 100644 --- a/src/test/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImplTest.java +++ b/src/test/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImplTest.java @@ -115,9 +115,9 @@ void update() { assertThat(finded.getActivityContent()).isEqualTo("변경된 활동내용"); } - @DisplayName("주어진 feedId를 가진 Feed 엔터티를 삭제 및 fileMetaData 상태를 DELETED로 변경") + @DisplayName("주어진 feedId를 가진 Feed 엔터티를 삭제 및 fileMetaData 상태를 DELETED로 변경 - IMAGE") @Test - void delete() { + void deleteImage() { // given UUID uuid = UuidCreator.getTimeOrderedEpoch(); @@ -148,4 +148,38 @@ void delete() { assertThat(fileMetaData).isNotNull(); assertThat(fileMetaData.getFileStatus()).isEqualTo(FileStatus.DELETED); } + + @DisplayName("주어진 feedId를 가진 Feed 엔터티를 삭제 및 fileMetaData 상태를 DELETED로 변경 - VIDEO") + @Test + void deleteVideo() { + // given + UUID uuid = UuidCreator.getTimeOrderedEpoch(); + + + Feed savedFeed = feedRepository.save( + fixtureMonkey.giveMeBuilder(Feed.class) + .set("feedType", FeedType.VIDEO) + .set("activityContent", "활동내용") + .set("club", null) + .sample() + ); + fileMetaDataRepository.save( + fixtureMonkey.giveMeBuilder(FileMetaData.class) + .set("id", uuid) + .set("entityId", savedFeed.getId()) + .set("domainType", DomainType.FEED_VIDEO) + .set("fileStatus", FileStatus.COUPLED) + .sample() + ); + entityManager.flush(); + // when + facadeClubFeedService.delete(savedFeed.getId()); + entityManager.flush(); + // then + Feed feed = feedRepository.findById(savedFeed.getId()).orElse(null); + FileMetaData fileMetaData = fileMetaDataRepository.findById(uuid).orElse(null); + assertThat(feed).isNull(); + assertThat(fileMetaData).isNotNull(); + assertThat(fileMetaData.getFileStatus()).isEqualTo(FileStatus.DELETED); + } } From c9827497ca77f79ab199aa3b28c717d43e5386d5 Mon Sep 17 00:00:00 2001 From: KoSeonJe <127813439+KoSeonJe@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:23:55 +0900 Subject: [PATCH 6/8] =?UTF-8?q?refactor=20:=20fileMetaData=EC=9D=98=20File?= =?UTF-8?q?Status=20Delete=20=EB=B3=80=ED=99=98=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FacadeClubFeedServiceImpl.java | 9 +--- .../filemetadata/entity/DomainType.java | 44 ++++++++++++++----- .../service/FileMetaDataService.java | 2 + .../service/FileMetaDataServiceImpl.java | 8 ++++ 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java index da629ff3..b3e3ac2b 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java @@ -50,13 +50,6 @@ public void update(UpdateFeedCommand command) { public void delete(Long feedId) { Feed feed = feedService.getById(feedId); feedService.delete(feed); - if (feed.isImage()) { - fileMetaDataService.updateStatusToDelete(DomainType.FEED_IMAGE, feedId); - return; - } - - if (feed.isVideo()) { - fileMetaDataService.updateStatusToDelete(DomainType.FEED_VIDEO, feedId); - } + fileMetaDataService.updateStatusToDeleteByEntityId(Feed.class, feed.getId()); } } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/entity/DomainType.java b/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/entity/DomainType.java index 35f06e7c..7baa72ee 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/entity/DomainType.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/entity/DomainType.java @@ -1,15 +1,37 @@ package ddingdong.ddingdongBE.domain.filemetadata.entity; +import ddingdong.ddingdongBE.domain.activityreport.domain.ActivityReport; +import ddingdong.ddingdongBE.domain.banner.entity.Banner; +import ddingdong.ddingdongBE.domain.club.entity.Club; +import ddingdong.ddingdongBE.domain.documents.entity.Document; +import ddingdong.ddingdongBE.domain.feed.entity.Feed; +import ddingdong.ddingdongBE.domain.fixzone.entity.FixZone; +import ddingdong.ddingdongBE.domain.notice.entity.Notice; +import java.util.Arrays; +import java.util.List; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter public enum DomainType { - CLUB_PROFILE, - CLUB_INTRODUCTION, - FIX_ZONE_IMAGE, - NOTICE_IMAGE, - NOTICE_FILE, - DOCUMENT_FILE, - ACTIVITY_REPORT_IMAGE, - BANNER_WEB_IMAGE, - BANNER_MOBILE_IMAGE, - FEED_IMAGE, - FEED_VIDEO + CLUB_PROFILE(Club.class), + CLUB_INTRODUCTION(Club.class), + FIX_ZONE_IMAGE(FixZone.class), + NOTICE_IMAGE(Notice.class), + NOTICE_FILE(Notice.class), + DOCUMENT_FILE(Document.class), + ACTIVITY_REPORT_IMAGE(ActivityReport.class), + BANNER_WEB_IMAGE(Banner.class), + BANNER_MOBILE_IMAGE(Banner.class), + FEED_IMAGE(Feed.class), + FEED_VIDEO(Feed.class); + + private final Class classType; + + public static List findAllByClassType(Class classType) { + return Arrays.stream(values()) + .filter(domainType -> domainType.getClassType() == classType) + .toList(); + } } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataService.java b/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataService.java index 03e2dd79..27e94115 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataService.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataService.java @@ -34,4 +34,6 @@ List getCoupledAllByDomainTypeAndEntityIdOrderedAsc(DomainType dom void update(List ids, DomainType domainType, Long entityId); void updateWithOrder(List fileMetaDataIdOrderDtos, DomainType domainType, Long entityId); + + void updateStatusToDeleteByEntityId(Class classType, Long entityId); } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataServiceImpl.java b/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataServiceImpl.java index f43adfb4..f85c8048 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataServiceImpl.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataServiceImpl.java @@ -160,6 +160,14 @@ public void updateWithOrder(List fileMetaDataIdOrderDtos updateStatusToCoupledWithOrder(fileMetaDataIdOrderDtos, domainType, entityId); } + @Override + public void updateStatusToDeleteByEntityId(Class classType, Long entityId) { + List domainTypes = DomainType.findAllByClassType(classType); + domainTypes.forEach(domainType -> { + updateStatusToDelete(domainType, entityId); + }); + } + @Transactional @Override public void updateStatusToDelete(DomainType domainType, Long entityId) { From 639d68a377084b82e0f72873dae2ef20dfa4b35a Mon Sep 17 00:00:00 2001 From: KoSeonJe <127813439+KoSeonJe@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:38:37 +0900 Subject: [PATCH 7/8] =?UTF-8?q?fix=20:=20@Transactional=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/filemetadata/service/FileMetaDataServiceImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataServiceImpl.java b/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataServiceImpl.java index f85c8048..4cfcabb9 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataServiceImpl.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataServiceImpl.java @@ -92,6 +92,7 @@ public void updateStatusToCoupled(String id, DomainType domainType, Long entityI fileMetaData.updateStatus(COUPLED); } + @Transactional @Override public void updateStatusToCoupledWithOrder( List fileMetaDataIdOrderDtos, @@ -160,6 +161,7 @@ public void updateWithOrder(List fileMetaDataIdOrderDtos updateStatusToCoupledWithOrder(fileMetaDataIdOrderDtos, domainType, entityId); } + @Transactional @Override public void updateStatusToDeleteByEntityId(Class classType, Long entityId) { List domainTypes = DomainType.findAllByClassType(classType); From eb38e0a006fbc77429ac84d6ff0d0a0100aa84c5 Mon Sep 17 00:00:00 2001 From: KoSeonJe <127813439+KoSeonJe@users.noreply.github.com> Date: Wed, 8 Jan 2025 23:30:12 +0900 Subject: [PATCH 8/8] =?UTF-8?q?refactor=20:=20FeedType=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=A5=B8=20FileMetaData=20=EC=82=AD=EC=A0=9C=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/feed/entity/FeedType.java | 10 ++++- .../service/FacadeClubFeedServiceImpl.java | 2 +- .../filemetadata/entity/DomainType.java | 39 ++++++------------- .../service/FileMetaDataService.java | 2 - .../service/FileMetaDataServiceImpl.java | 9 ----- 5 files changed, 21 insertions(+), 41 deletions(-) diff --git a/src/main/java/ddingdong/ddingdongBE/domain/feed/entity/FeedType.java b/src/main/java/ddingdong/ddingdongBE/domain/feed/entity/FeedType.java index 26cb77f7..1170634b 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/feed/entity/FeedType.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/feed/entity/FeedType.java @@ -1,9 +1,17 @@ package ddingdong.ddingdongBE.domain.feed.entity; +import ddingdong.ddingdongBE.domain.filemetadata.entity.DomainType; import java.util.Arrays; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +@Getter +@RequiredArgsConstructor public enum FeedType { - IMAGE, VIDEO; + IMAGE(DomainType.FEED_IMAGE), + VIDEO(DomainType.FEED_VIDEO); + + private final DomainType domainType; public static FeedType findByContentType(String contentType) { return Arrays.stream(values()) diff --git a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java index b3e3ac2b..ea2b41a8 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeClubFeedServiceImpl.java @@ -50,6 +50,6 @@ public void update(UpdateFeedCommand command) { public void delete(Long feedId) { Feed feed = feedService.getById(feedId); feedService.delete(feed); - fileMetaDataService.updateStatusToDeleteByEntityId(Feed.class, feed.getId()); + fileMetaDataService.updateStatusToDelete(feed.getFeedType().getDomainType(), feed.getId()); } } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/entity/DomainType.java b/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/entity/DomainType.java index 7baa72ee..ec68870d 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/entity/DomainType.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/entity/DomainType.java @@ -1,37 +1,20 @@ package ddingdong.ddingdongBE.domain.filemetadata.entity; -import ddingdong.ddingdongBE.domain.activityreport.domain.ActivityReport; -import ddingdong.ddingdongBE.domain.banner.entity.Banner; -import ddingdong.ddingdongBE.domain.club.entity.Club; -import ddingdong.ddingdongBE.domain.documents.entity.Document; -import ddingdong.ddingdongBE.domain.feed.entity.Feed; -import ddingdong.ddingdongBE.domain.fixzone.entity.FixZone; -import ddingdong.ddingdongBE.domain.notice.entity.Notice; -import java.util.Arrays; -import java.util.List; import lombok.Getter; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @Getter public enum DomainType { - CLUB_PROFILE(Club.class), - CLUB_INTRODUCTION(Club.class), - FIX_ZONE_IMAGE(FixZone.class), - NOTICE_IMAGE(Notice.class), - NOTICE_FILE(Notice.class), - DOCUMENT_FILE(Document.class), - ACTIVITY_REPORT_IMAGE(ActivityReport.class), - BANNER_WEB_IMAGE(Banner.class), - BANNER_MOBILE_IMAGE(Banner.class), - FEED_IMAGE(Feed.class), - FEED_VIDEO(Feed.class); - - private final Class classType; - - public static List findAllByClassType(Class classType) { - return Arrays.stream(values()) - .filter(domainType -> domainType.getClassType() == classType) - .toList(); - } + CLUB_PROFILE, + CLUB_INTRODUCTION, + FIX_ZONE_IMAGE, + NOTICE_IMAGE, + NOTICE_FILE, + DOCUMENT_FILE, + ACTIVITY_REPORT_IMAGE, + BANNER_WEB_IMAGE, + BANNER_MOBILE_IMAGE, + FEED_IMAGE, + FEED_VIDEO; } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataService.java b/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataService.java index 27e94115..03e2dd79 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataService.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataService.java @@ -34,6 +34,4 @@ List getCoupledAllByDomainTypeAndEntityIdOrderedAsc(DomainType dom void update(List ids, DomainType domainType, Long entityId); void updateWithOrder(List fileMetaDataIdOrderDtos, DomainType domainType, Long entityId); - - void updateStatusToDeleteByEntityId(Class classType, Long entityId); } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataServiceImpl.java b/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataServiceImpl.java index 4cfcabb9..e59dfcb8 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataServiceImpl.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/filemetadata/service/FileMetaDataServiceImpl.java @@ -161,15 +161,6 @@ public void updateWithOrder(List fileMetaDataIdOrderDtos updateStatusToCoupledWithOrder(fileMetaDataIdOrderDtos, domainType, entityId); } - @Transactional - @Override - public void updateStatusToDeleteByEntityId(Class classType, Long entityId) { - List domainTypes = DomainType.findAllByClassType(classType); - domainTypes.forEach(domainType -> { - updateStatusToDelete(domainType, entityId); - }); - } - @Transactional @Override public void updateStatusToDelete(DomainType domainType, Long entityId) {