-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,9 +36,16 @@ public class CommentEntity extends BaseUUIDEntity { | |
@Column(nullable = false) | ||
private LocalDateTime updatedAt; | ||
|
||
@Column(columnDefinition = "BIT(1) default 0", nullable = false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q) BIT๋ฅผ ์ฌ์ฉํ ์ด์ ๊ฐ ์๋์? |
||
private Boolean isDeleted; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P4) comment.delete()๊ฐ ๋ ๋ช ํํ ๊ฒ ๊ฐ์ต๋๋ค! |
||
} | ||
|
||
@Override | ||
|
@@ -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); | ||
|
@@ -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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,11 +42,18 @@ public class FeedEntity extends BaseUUIDEntity { | |
@Column(nullable = false) | ||
private String authorityType; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p1) ์ฌ๊ธฐ์ manualํ๊ฒ saveํด์ update๋ฅผ ํด์ฃผ๋๊ฒ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค |
||
} | ||
|
||
@Transactional | ||
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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(); | ||
|
||
|
@@ -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(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p4) deleted๋ ๋์์ง์์ ๊ฒ ๊ฐ๋ค์~