Skip to content

Commit

Permalink
๐Ÿ”€ :: (#220) ๊ฒŒ์‹œ๊ธ€, ๋Œ“๊ธ€ soft delete ์ถ”๊ฐ€ (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
jyk1029 authored Aug 18, 2023
1 parent a2550f6 commit 99f58ec
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public class Comment {
private final LocalDateTime createAt;

private final LocalDateTime updatedAt;

private final Boolean isDeleted = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ public interface CommandCommentSpi {
void deleteCommentById(UUID commentId);

void updateComment(UpdateCommentDomainRequest request);

void deleteAllCommentByFeedId(UUID feedId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public class Feed {
private final String authorityType;

private final Integer commentCount;

private final Boolean isDeleted = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public SaveFeedResponse saveFeed(DomainCreateFeedRequest request) {

UUID feedId = commandFeedSpi.saveFeed(feed);

if (category.getName().equals(CategoryEnum.NOTICE.getName())) {
if (CategoryEnum.NOTICE.getName().equals(category.getName())) {
notificationSpi.sendGroupNotification(
FEED_NOTICE,
CONTENT,
Expand All @@ -95,7 +95,6 @@ public void deleteFeedById(UUID feedId) {
Feed feed = queryFeedSpi.queryFeedById(feedId);
UUID currentUserId = securitySpi.getCurrentUserId();
feedUserSpi.validateUserId(feed.getUserId(), currentUserId);
commandCommentSpi.deleteAllCommentByFeedId(feedId);
commandFeedImageSpi.deleteAllFeedImage(feedId);
commandFeedLikeSpi.deleteFeedLikeByFeedId(feedId);
commandFeedSpi.deleteFeed(feed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ public class CommentEntity extends BaseUUIDEntity {
@Column(nullable = false)
private LocalDateTime updatedAt;

@Column(columnDefinition = "BIT(1) default 0", nullable = false)
private Boolean isDeleted;

public CommentEntity updateComment(String content) {
this.content = content;
this.updatedAt = LocalDateTime.now();
return this;
}

public void updatedIsDeleted(Boolean isDeleted) {
this.isDeleted = isDeleted;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ public interface CommentRepository extends CrudRepository<CommentEntity, UUID> {

void deleteById(UUID commentId);

void deleteAllByFeedEntityId(UUID feedId);

boolean existsByUserId(UUID userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void saveComment(Comment comment) {

@Override
public void deleteCommentById(UUID commentId) {
commentRepository.deleteById(commentId);
CommentEntity comment = getCommentById(commentId);
comment.updatedIsDeleted(true);
}

@Override
Expand All @@ -48,12 +49,6 @@ public void updateComment(UpdateCommentDomainRequest request) {
commentRepository.save(comment.updateComment(request.getContent()));
}

@Transactional
@Override
public void deleteAllCommentByFeedId(UUID feedId) {
commentRepository.deleteAllByFeedEntityId(feedId);
}

@Override
public Comment queryCommentById(UUID commentId) {
CommentEntity comment = getCommentById(commentId);
Expand All @@ -68,7 +63,8 @@ public List<UUID> queryAllCommentUserIdByFeed(Feed feed) {
.on(feedEntity.id.eq(feed.getId()))
.where(
feedEntity.id.eq(feed.getId()),
feedEntity.authorityType.eq("UKN").not()
feedEntity.authorityType.eq("UKN").not(),
commentEntity.isDeleted.eq(false)
)
.orderBy(commentEntity.createAt.desc())
.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ public class FeedEntity extends BaseUUIDEntity {
@Column(nullable = false)
private String authorityType;

@Column(columnDefinition = "BIT(1) default 0", nullable = false)
private Boolean isDeleted;

@OneToMany(mappedBy = "feedEntity")
private Set<FeedImageEntity> feedImageEntities;

public void updateFeedContent(String title, String content) {
this.title = title;
this.content = content;
}

public void updateIsDeleted(Boolean isDeleted) {
this.isDeleted = isDeleted;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ public UUID saveFeed(Feed feed) {

@Override
public void deleteFeed(Feed feed) {
feedRepository.delete(
feedMapper.domainToEntity(feed)
);
FeedEntity feedEntity = getFeedEntityById(feed.getId());
feedEntity.updateIsDeleted(true);
}

@Transactional
Expand Down Expand Up @@ -81,7 +80,7 @@ public FeedPageList queryAllFeedByCategory(UUID categoryId, LocalDateTime time,
.on(feedEntity.id.eq(feedLikeEntity.feedEntity.id))
.leftJoin(commentEntity)
.on(feedEntity.id.eq(commentEntity.feedEntity.id))
.where(expression.and(categoryIdEq(categoryId)))
.where(expression.and(categoryIdEq(categoryId)), feedEntity.isDeleted.eq(false))
.groupBy(feedEntity.id)
.orderBy(feedEntity.createdAt.desc())
.limit(limit)
Expand All @@ -108,7 +107,7 @@ public List<UUID> queryAllFeedUserIdByCategory(UUID categoryId) {
.selectFrom(feedEntity).distinct()
.leftJoin(feedLikeEntity)
.on(feedEntity.id.eq(feedLikeEntity.feedEntity.id))
.where(categoryIdEq(categoryId), feedEntity.authorityType.eq("UKN").not())
.where(categoryIdEq(categoryId), feedEntity.authorityType.eq("UKN").not(), feedEntity.isDeleted.eq(false))
.orderBy(feedEntity.createdAt.desc())
.fetch();

Expand All @@ -135,7 +134,7 @@ public List<FeedList> queryAllFeedByUserId(UUID userId) {
.on(feedEntity.id.eq(feedLikeEntity.feedEntity.id))
.leftJoin(commentEntity)
.on(feedEntity.id.eq(commentEntity.feedEntity.id))
.where(feedEntity.userId.eq(userId))
.where(feedEntity.userId.eq(userId), feedEntity.isDeleted.eq(false))
.groupBy(feedEntity.id)
.orderBy(feedEntity.createdAt.desc())
.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public SaveFeedResponse saveFeed(@Valid @RequestBody WebCreateFeedRequest reques
.title(request.getTitle())
.content(request.getContent())
.categoryId(request.getCategoryId())
.authorityType(request.getType())
.authorityType(request.getAuthorityType())
.build();

return feedApi.saveFeed(domainRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ public class WebCreateFeedRequest {
private UUID categoryId;

@NotBlank
private String type;
private String authorityType;
}

0 comments on commit 99f58ec

Please sign in to comment.