Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public void editComment(
editCommentUsecase.editComment(userInfo.getUserId(), commentId, request);
}

@Operation(summary = "댓글 삭제", description = "첨부파일 댓글일 경우 request body에 삭제할 파일 ID를 리스트로 전달")
@Parameter(name = "commentId", description = "수정할 댓글 고유 ID", required = true, in = ParameterIn.PATH)
@Operation(summary = "댓글 삭제")
@Parameter(name = "commentId", description = "삭제할 댓글 고유 ID", required = true, in = ParameterIn.PATH)
@DeleteMapping("/{commentId}")
@Secured({"ROLE_MANAGER", "ROLE_USER"})
public void deleteComment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import clap.server.adapter.inbound.security.service.SecurityUserDetails;
import clap.server.adapter.inbound.web.dto.history.response.FindTaskHistoryResponse;
import clap.server.adapter.outbound.persistense.entity.log.constant.LogStatus;
import clap.server.application.port.inbound.history.FindTaskHistoriesUsecase;
import clap.server.common.annotation.architecture.WebAdapter;
import clap.server.common.annotation.log.LogType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
Expand All @@ -15,7 +13,6 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Tag(name = "03. Task History")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package clap.server.adapter.outbound.persistense.entity.task;

import clap.server.adapter.outbound.persistense.entity.common.BaseTimeEntity;
import clap.server.adapter.outbound.persistense.entity.member.MemberEntity;
import clap.server.adapter.outbound.persistense.entity.task.constant.TaskHistoryType;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;

@Entity
Expand All @@ -30,6 +30,10 @@ public class TaskHistoryEntity extends BaseTimeEntity {
@Embedded
private TaskModificationInfo taskModificationInfo;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "modified_member_id")
private MemberEntity modifiedMember;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "comment_id")
private CommentEntity comment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package clap.server.adapter.outbound.persistense.entity.task;

import clap.server.adapter.outbound.persistense.entity.member.MemberEntity;
import jakarta.persistence.*;
import jakarta.persistence.Embeddable;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -17,10 +19,6 @@ public class TaskModificationInfo {
@JoinColumn(name = "task_id")
private TaskEntity task;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "modified_member_id")
private MemberEntity modifiedMember;

@JoinColumn(name = "modified_status")
private String modifiedStatus;
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
package clap.server.adapter.outbound.persistense.mapper;

import clap.server.adapter.outbound.persistense.entity.task.CommentEntity;

import clap.server.adapter.outbound.persistense.mapper.common.PersistenceMapper;

import clap.server.domain.model.member.Member;
import clap.server.domain.model.task.Comment;

import org.hibernate.Hibernate;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.springframework.beans.factory.annotation.Autowired;

@Mapper(componentModel = "spring", uses = {MemberPersistenceMapper.class, TaskPersistenceMapper.class})
public interface CommentPersistenceMapper extends PersistenceMapper<CommentEntity, Comment> {
public abstract class CommentPersistenceMapper {

@Autowired
MemberPersistenceMapper memberPersistenceMapper;

@Override
@Mapping(source = "modified", target = "isModified")
@Mapping(source = "deleted", target = "isDeleted")
Comment toDomain(final CommentEntity entity);
@Mapping(target = "member", expression = "java(mapMember(entity))")
@Mapping(target = "task", ignore = true)
public abstract Comment toDomain(final CommentEntity entity);

@Override
@Mapping(source = "modified", target = "isModified")
@Mapping(source = "deleted", target = "isDeleted")
CommentEntity toEntity(final Comment domain);
public abstract CommentEntity toEntity(final Comment domain);

protected Member mapMember(CommentEntity entity) {
if (entity == null || entity.getMember() == null || !Hibernate.isInitialized(entity.getMember())) {
return null;
}
return memberPersistenceMapper.toDomain(entity.getMember());
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package clap.server.adapter.outbound.persistense.repository.history;

import clap.server.adapter.outbound.persistense.entity.member.QMemberEntity;
import clap.server.adapter.outbound.persistense.entity.task.QCommentEntity;
import clap.server.adapter.outbound.persistense.entity.task.QTaskHistoryEntity;
import clap.server.adapter.outbound.persistense.entity.task.TaskHistoryEntity;
Expand All @@ -18,9 +19,11 @@ public class TaskHistoryCustomRepositoryImpl implements TaskHistoryCustomReposit
public List<TaskHistoryEntity> findAllTaskHistoriesByTaskId(Long taskId) {
QTaskHistoryEntity taskHistory = QTaskHistoryEntity.taskHistoryEntity;
QCommentEntity comment = QCommentEntity.commentEntity;
QMemberEntity member = QMemberEntity.memberEntity;

return queryFactory.selectFrom(taskHistory)
.leftJoin(taskHistory.comment, comment).fetchJoin() // TaskHistory와 Comment를 조인
.leftJoin(taskHistory.comment, comment).fetchJoin()
.leftJoin(taskHistory.modifiedMember, member).fetchJoin()
.where(
// Comment가 없는 경우에는 TaskModificationInfo의 Task 기준
taskHistory.comment.isNull()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package clap.server.adapter.outbound.persistense.repository.task;

import clap.server.adapter.inbound.web.dto.task.request.FilterTaskListRequest;
import clap.server.adapter.inbound.web.dto.task.request.FilterTaskBoardRequest;
import clap.server.adapter.inbound.web.dto.task.request.FilterTaskListRequest;
import clap.server.adapter.inbound.web.dto.task.request.FilterTeamStatusRequest;
import clap.server.adapter.inbound.web.dto.task.response.TeamTaskResponse;
import clap.server.adapter.outbound.persistense.entity.task.TaskEntity;
import clap.server.adapter.outbound.persistense.entity.task.constant.TaskStatus;
import org.springframework.data.domain.Page;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static FindTaskHistoryResponse toFindTaskHistoryResponse(List<TaskHistory
switch (taskHistory.getType()) {
case PROCESSOR_CHANGED, PROCESSOR_ASSIGNED -> new FindTaskHistoryResponse.Details(
new FindTaskHistoryResponse.TaskDetails(
taskHistory.getTaskModificationInfo().getModifiedMember().getNickname()
taskHistory.getModifiedMember().getNickname()
),
null,
null
Expand All @@ -37,8 +37,8 @@ public static FindTaskHistoryResponse toFindTaskHistoryResponse(List<TaskHistory
null,
new FindTaskHistoryResponse.CommentDetails(
taskHistory.getComment().getCommentId(),
taskHistory.getComment().getMember().getNickname(),
taskHistory.getComment().getMember().getImageUrl(),
taskHistory.getModifiedMember().getNickname(),
taskHistory.getModifiedMember().getImageUrl(),
taskHistory.getComment().isModified(),
taskHistory.getComment().getContent()
),
Expand All @@ -49,8 +49,8 @@ public static FindTaskHistoryResponse toFindTaskHistoryResponse(List<TaskHistory
null,
new FindTaskHistoryResponse.CommentFileDetails(
taskHistory.getComment().getCommentId(),
taskHistory.getComment().getMember().getNickname(),
taskHistory.getComment().getMember().getImageUrl(),
taskHistory.getModifiedMember().getNickname(),
taskHistory.getModifiedMember().getImageUrl(),
taskHistory.getComment().getOriginalName(),
taskHistory.getComment().getFileUrl(),
taskHistory.getComment().getFileSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import clap.server.application.port.outbound.task.LoadTaskPort;
import clap.server.application.port.outbound.taskhistory.LoadTaskHistoryPort;
import clap.server.common.annotation.architecture.ApplicationService;
import clap.server.domain.model.member.Member;
import clap.server.domain.model.task.Task;
import clap.server.domain.model.task.TaskHistory;
import clap.server.exception.DomainException;
import clap.server.exception.ApplicationException;
import clap.server.exception.code.TaskErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -29,7 +28,7 @@ public class FindTaskHistoriesService implements FindTaskHistoriesUsecase {
public FindTaskHistoryResponse findTaskHistories(Long memberId, Long taskId) {
memberService.findActiveMember(memberId);
Task task = loadTaskPort.findById(taskId)
.orElseThrow(()-> new DomainException(TaskErrorCode.TASK_NOT_FOUND));
.orElseThrow(()-> new ApplicationException(TaskErrorCode.TASK_NOT_FOUND));
List<TaskHistory> taskHistories = loadTaskHistoryPort.findAllTaskHistoriesByTaskId(task.getTaskId());
return TaskHistoryResponseMapper.toFindTaskHistoryResponse(taskHistories);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@
import clap.server.application.port.inbound.history.SaveCommentAttachmentUsecase;
import clap.server.application.port.inbound.history.SaveCommentUsecase;
import clap.server.application.port.outbound.s3.S3UploadPort;
import clap.server.application.port.outbound.task.CommandAttachmentPort;
import clap.server.application.port.outbound.task.CommandCommentPort;
import clap.server.application.port.outbound.taskhistory.CommandTaskHistoryPort;
import clap.server.application.service.webhook.SendNotificationService;
import clap.server.common.annotation.architecture.ApplicationService;
import clap.server.common.constants.FilePathConstants;
import clap.server.domain.model.member.Member;
import clap.server.domain.model.task.Attachment;
import clap.server.domain.model.task.Comment;
import clap.server.domain.model.task.Task;
import clap.server.domain.model.task.TaskHistory;
import clap.server.common.constants.FilePathConstants;
import clap.server.domain.policy.task.TaskCommentPolicy;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -53,7 +51,7 @@ public void save(Long memberId, Long taskId, CreateCommentRequest request) {
Comment comment = Comment.createComment(member, task, request.content(), null, null, null);
Comment savedComment = commandCommentPort.saveComment(comment);

TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.COMMENT, task, null, member, savedComment);
TaskHistory taskHistory = TaskHistory.createCommentTaskHistory(TaskHistoryType.COMMENT, member, savedComment);
commandTaskHistoryPort.save(taskHistory);

Member processor = task.getProcessor();
Expand All @@ -76,10 +74,10 @@ public void saveCommentAttachment(Long memberId, Long taskId, MultipartFile file
String fileUrl = s3UploadPort.uploadSingleFile(FilePathConstants.TASK_COMMENT, file);
String fileName = file.getOriginalFilename();

Comment comment = Comment.createComment(member, task, null, fileName, fileUrl, formatFileSize(file.getSize()));
Comment comment = Comment.createComment(member, task, null, fileName, fileUrl, formatFileSize(file.getSize()));
Comment savedComment = commandCommentPort.saveComment(comment);

TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.COMMENT_FILE, null, null, null, savedComment);
TaskHistory taskHistory = TaskHistory.createCommentTaskHistory(TaskHistoryType.COMMENT_FILE, member, savedComment);
commandTaskHistoryPort.save(taskHistory);

Member processor = task.getProcessor();
Expand All @@ -93,14 +91,6 @@ public void saveCommentAttachment(Long memberId, Long taskId, MultipartFile file

}

@Deprecated
// private String saveAttachment(MultipartFile file, Task task) {
// String fileUrl = s3UploadPort.uploadSingleFile(FilePathConstants.TASK_COMMENT, file);
// Attachment attachment = Attachment.createCommentAttachment(task, null, file.getOriginalFilename(), fileUrl, file.getSize());
// commandAttachmentPort.save(attachment);
// return file.getOriginalFilename();
// }

private void publishNotification(Member receiver, Task task, String message, String commenterName) {
boolean isManager = receiver.getMemberInfo().getRole() == MemberRole.ROLE_MANAGER;
sendNotificationService.sendPushNotification(receiver, NotificationType.COMMENT, task, message, null, commenterName, isManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ApprovalTaskResponse approvalTaskByReviewer(Long reviewerId, Long taskId,
updateProcessorTaskCountService.handleTaskStatusChange(processor, TaskStatus.REQUESTED, TaskStatus.IN_PROGRESS);
task.approveTask(reviewer, processor, approvalTaskRequest.dueDate(), category, label);

TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.PROCESSOR_ASSIGNED, task, null, processor, null);
TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.PROCESSOR_ASSIGNED, task, null, processor);
commandTaskHistoryPort.save(taskHistory);

String processorName = processor.getNickname();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void terminateTask(Long memberId, Long taskId, String reason) {
task.terminateTask();
taskService.upsert(task);

TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.TASK_TERMINATED, task, reason, null, null);
TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.TASK_TERMINATED, task, reason, null);
commandTaskHistoryPort.save(taskHistory);

publishNotification(task.getRequester(), task, task.getTaskStatus().getDescription(), reason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void updateTaskOrderAndStatus(Long processorId, UpdateTaskOrderRequest re
updatedTask = updateNewTaskOrderAndStatus(targetStatus, targetTask, newOrder);
}

TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.STATUS_SWITCHED, updatedTask, targetStatus.getDescription(), null,null);
TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.STATUS_SWITCHED, updatedTask, targetStatus.getDescription(), null);
commandTaskHistoryPort.save(taskHistory);
publishNotification(targetTask);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void updateTaskStatus(Long memberId, Long taskId, TaskStatus targetTaskSt
task.updateTaskStatus(targetTaskStatus);
Task updatedTask = taskService.upsert(task);

saveTaskHistory(TaskHistory.createTaskHistory(TaskHistoryType.STATUS_SWITCHED, task, targetTaskStatus.getDescription(), null, null));
saveTaskHistory(TaskHistory.createTaskHistory(TaskHistoryType.STATUS_SWITCHED, task, targetTaskStatus.getDescription(), null));

List<Member> receivers = List.of(task.getRequester());
publishNotification(receivers, updatedTask, NotificationType.STATUS_SWITCHED, targetTaskStatus.getDescription());
Expand All @@ -79,7 +79,7 @@ public void updateTaskProcessor(Long taskId, Long memberId, UpdateTaskProcessorR
task.updateProcessor(processor);
Task updatedTask = taskService.upsert(task);

saveTaskHistory(TaskHistory.createTaskHistory(TaskHistoryType.PROCESSOR_CHANGED, task, null, processor, null));
saveTaskHistory(TaskHistory.createTaskHistory(TaskHistoryType.PROCESSOR_CHANGED, task, null, processor));

List<Member> receivers = List.of(updatedTask.getRequester());
publishNotification(receivers, updatedTask, NotificationType.PROCESSOR_CHANGED, processor.getNickname());
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/clap/server/domain/model/task/TaskHistory.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package clap.server.domain.model.task;

import clap.server.adapter.outbound.persistense.entity.task.constant.TaskHistoryType;

import clap.server.domain.model.common.BaseTime;
import clap.server.domain.model.member.Member;

import lombok.*;
import lombok.experimental.SuperBuilder;

Expand All @@ -15,6 +13,7 @@ public class TaskHistory extends BaseTime {
private Long taskHistoryId;
private TaskHistoryType type;
private TaskModificationInfo taskModificationInfo;
private Member modifiedMember;
private Comment comment;

@Getter
Expand All @@ -23,20 +22,33 @@ public class TaskHistory extends BaseTime {
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public static class TaskModificationInfo {
private Task task;
private Member modifiedMember;
private String modifiedStatus;
}

public static TaskHistory createTaskHistory(TaskHistoryType type, Task task, String statusDescription, Member member, Comment comment) {
public static TaskHistory createTaskHistory(TaskHistoryType type, Task task, String statusDescription, Member member) {
return TaskHistory.builder()
.type(type)
.modifiedMember(member)
.taskModificationInfo(
TaskModificationInfo.builder()
.task(task)
.modifiedMember(member)
.modifiedStatus(statusDescription)
.build()
)
.comment(null)
.build();
}

public static TaskHistory createCommentTaskHistory(TaskHistoryType type, Member member, Comment comment) {
return TaskHistory.builder()
.type(type)
.modifiedMember(member)
.taskModificationInfo(
TaskModificationInfo.builder()
.task(null)
.modifiedStatus(null)
.build()
)
.comment(comment)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
START TRANSACTION;

UPDATE task_history th
SET modified_member_id = (
SELECT member_id FROM comment c WHERE c.comment_id = th.comment_id
)
WHERE th.comment_id IS NOT NULL AND th.type='COMMENT_FILE';

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
START TRANSACTION;

UPDATE task_history th
SET modified_member_id = (
SELECT member_id FROM comment c WHERE c.comment_id = th.comment_id
)
WHERE th.comment_id IS NOT NULL AND th.type='COMMENT_FILE';

COMMIT;
Loading