Skip to content

Commit 38d1ad0

Browse files
authored
Merge pull request #180 from TaskFlow-CLAP/CLAP-181
CLAP-181 댓글 수정 및 삭제 api 구현
2 parents e5d9942 + e12a11f commit 38d1ad0

File tree

17 files changed

+244
-35
lines changed

17 files changed

+244
-35
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package clap.server.adapter.inbound.web.comment;
2+
3+
import clap.server.adapter.inbound.security.SecurityUserDetails;
4+
import clap.server.adapter.inbound.web.dto.task.DeleteCommentRequest;
5+
import clap.server.adapter.inbound.web.dto.task.PostAndEditCommentRequest;
6+
import clap.server.application.port.inbound.comment.CommandCommentUsecase;
7+
import clap.server.common.annotation.architecture.WebAdapter;
8+
import io.swagger.v3.oas.annotations.Operation;
9+
import io.swagger.v3.oas.annotations.Parameter;
10+
import io.swagger.v3.oas.annotations.enums.ParameterIn;
11+
import io.swagger.v3.oas.annotations.tags.Tag;
12+
import lombok.RequiredArgsConstructor;
13+
import org.springframework.security.access.annotation.Secured;
14+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
15+
import org.springframework.web.bind.annotation.*;
16+
17+
@Tag(name = "02. Task", description = "작업 생성/수정 API")
18+
@WebAdapter
19+
@RestController
20+
@RequiredArgsConstructor
21+
@RequestMapping("/api/comment")
22+
public class CommandCommentController {
23+
24+
private final CommandCommentUsecase commandCommentUsecase;
25+
26+
@Operation(summary = "댓글 수정")
27+
@Parameter(name = "commentId", description = "수정할 댓글 고유 ID", required = true, in = ParameterIn.PATH)
28+
@PatchMapping("/{commentId}")
29+
@Secured({"ROLE_MANAGER", "ROLE_USER"})
30+
public void editComment(
31+
@AuthenticationPrincipal SecurityUserDetails userInfo,
32+
@PathVariable Long commentId,
33+
@RequestBody PostAndEditCommentRequest request) {
34+
commandCommentUsecase.updateComment(userInfo.getUserId(), commentId, request);
35+
}
36+
37+
@Operation(summary = "댓글 삭제", description = "첨부파일 댓글일 경우 request body에 삭제할 파일 ID를 리스트로 전달")
38+
@Parameter(name = "commentId", description = "수정할 댓글 고유 ID", required = true, in = ParameterIn.PATH)
39+
@DeleteMapping("/{commentId}")
40+
@Secured({"ROLE_MANAGER", "ROLE_USER"})
41+
public void deleteComment(
42+
@AuthenticationPrincipal SecurityUserDetails userInfo,
43+
@PathVariable Long commentId,
44+
@RequestBody DeleteCommentRequest request) {
45+
commandCommentUsecase.deleteComment(userInfo.getUserId(), commentId, request);
46+
}
47+
48+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package clap.server.adapter.inbound.web.dto.task;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
import jakarta.validation.constraints.NotNull;
5+
6+
import java.util.List;
7+
8+
public record DeleteCommentRequest(
9+
@Schema(description = "삭제할 파일 ID 목록, 없을 경우 emptylist 전송")
10+
@NotNull
11+
List<Long> attachmentsToDelete
12+
) {
13+
}

src/main/java/clap/server/adapter/outbound/persistense/AttachmentPersistenceAdapter.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ public List<Attachment> findAllByTaskIdAndCommentIsNullAndAttachmentId(final Lon
5353
.collect(Collectors.toList());
5454
}
5555

56+
@Override
57+
public List<Attachment> findAllyByTaskIdAndCommentIdAndAttachmentId(Long taskId, Long commentId, List<Long> attachmentIds) {
58+
List<AttachmentEntity> attachmentEntities = attachmentRepository.findActiveAttachmentsByTask_TaskIdAndComment_CommentIdAndAttachmentIdIn(taskId, commentId, attachmentIds);
59+
return attachmentEntities.stream()
60+
.map(attachmentPersistenceMapper::toDomain)
61+
.collect(Collectors.toList());
62+
}
63+
5664
@Override
5765
public List<Attachment> findAllByTaskIdAndCommentIsNotNull(final Long taskId) {
5866
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNotNullAndIsDeletedIsFalse(taskId);

src/main/java/clap/server/adapter/outbound/persistense/CommentPersistenceAdapter.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ public class CommentPersistenceAdapter implements LoadCommentPort, CommandCommen
1919
private final CommentPersistenceMapper commentPersistenceMapper;
2020

2121
@Override
22-
public Optional<Comment> findById(Long id) {
23-
return Optional.empty();
22+
public Optional<Comment> findById(Long commentId) {
23+
Optional<CommentEntity> commentEntity = commentRepository.findById(commentId);
24+
return commentEntity.map(commentPersistenceMapper::toDomain);
25+
}
26+
27+
@Override
28+
public Comment saveComment(Comment comment) {
29+
CommentEntity commentEntity = commentRepository.save(commentPersistenceMapper.toEntity(comment));
30+
return commentPersistenceMapper.toDomain(commentEntity);
2431
}
2532

2633
@Override

src/main/java/clap/server/adapter/outbound/persistense/entity/member/MemberEntity.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,15 @@ public class MemberEntity extends BaseTimeEntity {
4545
@Column(nullable = false)
4646
private MemberStatus status;
4747

48+
// TODO: spring security 적용 예정
4849
@Column(nullable = false)
4950
private String password;
5051

5152
@Column
5253
private String imageUrl;
5354

5455
@Column
55-
private Boolean kakaoworkNotificationEnabled;
56-
@Column
57-
private Boolean agitNotificationEnabled;
58-
@Column
59-
private Boolean emailNotificationEnabled;
56+
private Boolean notificationEnabled;
6057

6158
@ManyToOne(fetch = FetchType.LAZY)
6259
@JoinColumn(name = "admin_id")

src/main/java/clap/server/adapter/outbound/persistense/entity/task/CommentEntity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ public class CommentEntity extends BaseTimeEntity {
3232

3333
@Column(name = "is_modified", nullable = false)
3434
private boolean isModified;
35+
36+
@Column(name="is_deleted", nullable = false)
37+
private boolean isDeleted;
3538
}

src/main/java/clap/server/adapter/outbound/persistense/mapper/CommentPersistenceMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ public interface CommentPersistenceMapper extends PersistenceMapper<CommentEnti
1414

1515
@Override
1616
@Mapping(source = "modified", target = "isModified")
17+
@Mapping(source = "deleted", target = "isDeleted")
1718
Comment toDomain(final CommentEntity entity);
1819

1920
@Override
2021
@Mapping(source = "modified", target = "isModified")
22+
@Mapping(source = "deleted", target = "isDeleted")
2123
CommentEntity toEntity(final Comment domain);
2224
}

src/main/java/clap/server/adapter/outbound/persistense/repository/task/AttachmentRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
public interface AttachmentRepository extends JpaRepository<AttachmentEntity, Long> {
1010
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNullAndIsDeletedIsFalse(Long taskId);
1111
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNullAndIsDeletedIsFalseAndAttachmentIdIn(Long task_taskId, List<Long> attachmentId);
12+
List<AttachmentEntity> findActiveAttachmentsByTask_TaskIdAndComment_CommentIdAndAttachmentIdIn(Long task_taskId, Long comment_commentId, List<Long> attachmentIds);
1213
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNotNullAndIsDeletedIsFalse(Long taskId);
1314
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package clap.server.application.port.inbound.comment;
2+
3+
import clap.server.adapter.inbound.web.dto.task.DeleteCommentRequest;
4+
import clap.server.adapter.inbound.web.dto.task.PostAndEditCommentRequest;
5+
6+
import java.util.List;
7+
8+
public interface CommandCommentUsecase {
9+
10+
void updateComment(Long userId, Long commentId, PostAndEditCommentRequest request);
11+
12+
void deleteComment(Long userId, Long commentId, DeleteCommentRequest request);
13+
}

src/main/java/clap/server/application/port/outbound/task/LoadAttachmentPort.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
public interface LoadAttachmentPort {
99
List<Attachment> findAllByTaskIdAndCommentIsNull(Long taskId);
1010
List<Attachment> findAllByTaskIdAndCommentIsNullAndAttachmentId(Long taskId, List<Long> attachmentIds);
11+
List<Attachment> findAllyByTaskIdAndCommentIdAndAttachmentId(Long taskId, Long commentId, List<Long> attachmentIds);
1112
List<Attachment> findAllByTaskIdAndCommentIsNotNull(Long taskId);
1213
}

0 commit comments

Comments
 (0)