Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ”€ :: (#220) ๊ฒŒ์‹œ๊ธ€, ๋Œ“๊ธ€ soft delete ์ถ”๊ฐ€ #108

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p4) deleted๋„ ๋‚˜์˜์ง€์•Š์„ ๊ฒƒ ๊ฐ™๋„ค์š”~

}
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q) BIT๋ฅผ ์‚ฌ์šฉํ•œ ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”?

private Boolean isDeleted;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p3) nullable์€ false์ธ๋ฐ Primitive type์œผ๋กœ ์„ค์ •ํ•˜๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.


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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4) comment.delete()๊ฐ€ ๋” ๋ช…ํ™•ํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

}

@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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q) Enum Type์œผ๋กœ ํ•˜์ง€ ์•Š์€ ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”?


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q) nullable false ์ธ๋ฐ primitive ์‚ฌ์šฉํ•˜์ง€ ์•Š์€ ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”?


@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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p1) ์—ฌ๊ธฐ์„œ manualํ•˜๊ฒŒ saveํ•ด์„œ update๋ฅผ ํ•ด์ฃผ๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค

}

@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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q) isDeleted๊ฐ€ true์ด๋ฉด soft-delete๋œ ๊ฐ’์ผํ…๋ฐ, ์ด๊ฑด ๋”ฐ๋กœ BooleanExpression์œผ๋กœ ๋นผ์„œ ๊ด€๋ฆฌํ•˜๋Š”๊ฒŒ ์–ด๋–ค๊ฐ€์š”?

.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;
}