Skip to content

Commit d5ca384

Browse files
authored
Merge pull request #142 from dnd-side-project/feature/#141-deleteComment
Feature/#141 delete comment
2 parents 327b746 + 95b20e1 commit d5ca384

File tree

11 files changed

+57
-22
lines changed

11 files changed

+57
-22
lines changed

src/main/java/com/dnd/reevserver/domain/comment/dto/response/CommentResponseDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
@Builder
66
public record CommentResponseDto(Long commentId, String userId, Long retrospectId,
77
String content, String nickName,String timeMessage,
8-
boolean isDeleted, Integer likeCount, boolean isAuthor) {
8+
Integer likeCount, boolean isAuthor) {
99
}

src/main/java/com/dnd/reevserver/domain/comment/dto/response/ReplyResponseDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
@Builder
66
public record ReplyResponseDto(Long commentId, String userId, Long retrospectId,
77
String content, String nickName,String timeMessage,
8-
boolean isDeleted, Integer likeCount, boolean isAuthor) {
8+
Integer likeCount, boolean isAuthor) {
99
}

src/main/java/com/dnd/reevserver/domain/comment/entity/Comment.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
import lombok.NoArgsConstructor;
1111
import org.hibernate.annotations.ColumnDefault;
1212
import org.hibernate.annotations.SQLDelete;
13+
import org.hibernate.annotations.SQLRestriction;
1314

1415
@Entity
1516
@Getter
1617
@NoArgsConstructor(access = AccessLevel.PROTECTED)
1718
@SQLDelete(sql = "update comment set is_deleted = true where comment_id = ?")
19+
@SQLRestriction("is_deleted = false")
1820
public class Comment extends BaseEntity {
1921

2022
@Id

src/main/java/com/dnd/reevserver/domain/comment/repository/CommentRepository.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010

1111
public interface CommentRepository extends JpaRepository<Comment, Long> {
1212
@Query("SELECT c FROM Comment c " +
13-
"JOIN FETCH c.member " +
14-
"JOIN FETCH c.retrospect " +
15-
"WHERE c.retrospect.retrospectId = :retrospectId " +
16-
"and c.parentComment is null")
13+
"JOIN FETCH c.member " +
14+
"JOIN FETCH c.retrospect " +
15+
"WHERE c.retrospect.retrospectId = :retrospectId " +
16+
"and c.parentComment is null")
1717
List<Comment> findByRetrospectId(@Param("retrospectId") Long retrospectId);
1818

1919

2020
@Query("SELECT c FROM Comment c " +
21-
"JOIN FETCH c.member " +
22-
"JOIN FETCH c.retrospect " +
23-
"WHERE c.parentComment.commentId = :parentCommentId")
21+
"JOIN FETCH c.member " +
22+
"JOIN FETCH c.retrospect " +
23+
"WHERE c.parentComment.commentId = :parentCommentId")
2424
List<Comment> findAllByParentCommentId(@Param("parentCommentId") Long parentCommentId);
2525

2626

2727
int countByRetrospect(Retrospect retrospect);
2828

2929
void deleteAllByRetrospectRetrospectId(Long retrospectId);
30-
}
30+
}

src/main/java/com/dnd/reevserver/domain/comment/service/CommentService.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ private CommentResponseDto convertToCommentDto(Comment comment, boolean isAuthor
143143
.content(comment.getContent())
144144
.nickName(comment.getMember().getNickname())
145145
.timeMessage(timeStringUtil.getTimeString(comment.getUpdatedAt()))
146-
.isDeleted(comment.isDeleted())
147146
.likeCount(comment.getLikeCount())
148147
.isAuthor(isCommentAuthor(comment))
149148
.build();
@@ -155,7 +154,6 @@ private CommentResponseDto convertToCommentDto(Comment comment, boolean isAuthor
155154
.content(comment.getContent())
156155
.nickName(comment.getMember().getNickname())
157156
.timeMessage(timeStringUtil.getTimeString(comment.getUpdatedAt()))
158-
.isDeleted(comment.isDeleted())
159157
.build();
160158
}
161159

@@ -168,7 +166,6 @@ private ReplyResponseDto convertToReplyDto(Comment reply, boolean isAuthorExiste
168166
.content(reply.getContent())
169167
.nickName(reply.getMember().getNickname())
170168
.timeMessage(timeStringUtil.getTimeString(reply.getUpdatedAt()))
171-
.isDeleted(reply.isDeleted())
172169
.likeCount(reply.getLikeCount())
173170
.isAuthor(isCommentAuthor(reply))
174171
.build();
@@ -180,7 +177,6 @@ private ReplyResponseDto convertToReplyDto(Comment reply, boolean isAuthorExiste
180177
.content(reply.getContent())
181178
.nickName(reply.getMember().getNickname())
182179
.timeMessage(timeStringUtil.getTimeString(reply.getUpdatedAt()))
183-
.isDeleted(reply.isDeleted())
184180
.build();
185181
}
186182
}

src/main/java/com/dnd/reevserver/domain/memo/controller/MemoController.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,26 @@
1919
public class MemoController {
2020
private final MemoService memoService;
2121

22+
@Operation(summary = "메모 단일 조회, 그룹이 없을 경우 groupId가 0으로 표시됩니다.")
2223
@GetMapping("/{memoId}")
2324
public ResponseEntity<MemoResponseDto> findMemoById(@PathVariable Long memoId) {
2425
return ResponseEntity.ok(memoService.findMemoById(memoId));
2526
}
2627

27-
@Operation(summary = "유저의 전체 메모 조회")
28+
@Operation(summary = "유저의 전체 메모 조회, 그룹이 없을 경우 groupId가 0으로 표시됩니다.")
2829
@GetMapping
2930
public ResponseEntity<List<MemoResponseDto>> findMemosByUserId(@AuthenticationPrincipal String userId) {
3031
List<MemoResponseDto> memos = memoService.findMemosByUserId(userId);
3132
return ResponseEntity.ok(memos);
3233
}
3334

35+
@Operation(summary = "유저와 그룹으로 메모들 조회")
36+
@GetMapping("/group/{groupId}")
37+
public ResponseEntity<List<MemoResponseDto>> findMemosByUserIdAndGroupId(@AuthenticationPrincipal String userId,
38+
@PathVariable Long groupId) {
39+
return ResponseEntity.ok(memoService.findMemosByUserIdAndGroupId(userId, groupId));
40+
}
41+
3442
@Operation(summary = "유저의 메모 수 조회")
3543
@GetMapping("/count")
3644
public ResponseEntity<Integer> countMemosByUserId(@AuthenticationPrincipal String userId) {

src/main/java/com/dnd/reevserver/domain/memo/dto/request/CreateMemoRequestDto.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
import java.util.List;
44

5-
public record CreateMemoRequestDto(String title, String content, String templateName, List<String> categoriesName) {
5+
public record CreateMemoRequestDto(String title, String content, String templateName,
6+
List<String> categoriesName, Long groupId) {
67
}

src/main/java/com/dnd/reevserver/domain/memo/dto/response/MemoResponseDto.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
import java.util.List;
66

77
@Builder
8-
public record MemoResponseDto(Long memoId, String userId, String title, String content, String templateName, List<String> categories){
8+
public record MemoResponseDto(Long memoId, String userId, String title,
9+
String content, String templateName, List<String> categories, Long groupId){
910
}

src/main/java/com/dnd/reevserver/domain/memo/entity/Memo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.dnd.reevserver.domain.category.entity.MemoCategory;
44
import com.dnd.reevserver.domain.member.entity.Member;
5+
import com.dnd.reevserver.domain.team.entity.Team;
56
import com.dnd.reevserver.domain.template.entity.Template;
67
import com.dnd.reevserver.global.common.entity.BaseEntity;
78
import jakarta.persistence.*;
@@ -38,4 +39,8 @@ public class Memo extends BaseEntity {
3839

3940
@OneToMany(mappedBy = "memo", cascade = CascadeType.REMOVE, orphanRemoval = true)
4041
private List<MemoCategory> memoCategories = new ArrayList<>();
42+
43+
@ManyToOne(fetch = FetchType.LAZY)
44+
@JoinColumn(name = "group_id")
45+
private Team team;
4146
}

src/main/java/com/dnd/reevserver/domain/memo/repository/MemoRepository.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ public interface MemoRepository extends JpaRepository<Memo, Long> {
1111
@Query("SELECT m FROM Memo m " +
1212
"JOIN FETCH m.member " +
1313
"JOIN FETCH m.template " +
14+
"JOIN FETCH m.team "+
1415
"WHERE m.member.userId = :userId")
1516
List<Memo> findMemosByMemberUserId(@Param("userId") String userId);
17+
18+
@Query("SELECT m FROM Memo m " +
19+
"JOIN FETCH m.member " +
20+
"JOIN FETCH m.template " +
21+
"JOIN FETCH m.team "+
22+
"WHERE m.member.userId = :userId " +
23+
"AND m.team.groupId = :groupId")
24+
List<Memo> findMemosByMemberUserIdAndGroupId(@Param("userId") String userId, @Param("groupId") Long groupId);
1625
}

0 commit comments

Comments
 (0)