Skip to content

Commit

Permalink
refactor : FeedType에 따른 FileMetaData 삭제로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
KoSeonJe committed Jan 8, 2025
1 parent 639d68a commit eb38e0a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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<DomainType> 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ List<FileMetaData> getCoupledAllByDomainTypeAndEntityIdOrderedAsc(DomainType dom
void update(List<String> ids, DomainType domainType, Long entityId);

void updateWithOrder(List<FileMetaDataIdOrderDto> fileMetaDataIdOrderDtos, DomainType domainType, Long entityId);

void updateStatusToDeleteByEntityId(Class<?> classType, Long entityId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,6 @@ public void updateWithOrder(List<FileMetaDataIdOrderDto> fileMetaDataIdOrderDtos
updateStatusToCoupledWithOrder(fileMetaDataIdOrderDtos, domainType, entityId);
}

@Transactional
@Override
public void updateStatusToDeleteByEntityId(Class<?> classType, Long entityId) {
List<DomainType> domainTypes = DomainType.findAllByClassType(classType);
domainTypes.forEach(domainType -> {
updateStatusToDelete(domainType, entityId);
});
}

@Transactional
@Override
public void updateStatusToDelete(DomainType domainType, Long entityId) {
Expand Down

0 comments on commit eb38e0a

Please sign in to comment.