Skip to content
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 @@ -39,7 +39,6 @@ public static record CommentFileDetails(
Long commentId,
String nickName,
String profileImageUrl,
boolean isModified,
String fileName,
String url,
String size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,18 @@ public void saveAll(final List<Attachment> attachments) {
}

@Override
public List<Attachment> findAllByTaskIdAndCommentIsNull(final Long taskId) {
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNull(taskId);
public List<Attachment> findAllByTaskId(final Long taskId) {
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskId(taskId);
return attachmentEntities.stream()
.map(attachmentPersistenceMapper::toDomain)
.collect(Collectors.toList());
}

@Override
public List<Attachment> findAllByTaskIdAndCommentIsNullAndAttachmentId(final Long taskId, final List<Long> attachmentIds) {
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNullAndAttachmentIdIn(taskId, attachmentIds);
public List<Attachment> findAllByTaskIdAndAttachmentId(final Long taskId, final List<Long> attachmentIds) {
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndAttachmentIdIn(taskId, attachmentIds);
return attachmentEntities.stream()
.map(attachmentPersistenceMapper::toDomain)
.collect(Collectors.toList());
}

@Override
public Optional<Attachment> findByCommentId(final Long commentId) {
Optional<AttachmentEntity> attachmentEntity = attachmentRepository.findByComment_CommentId(commentId);
return attachmentEntity.map(attachmentPersistenceMapper::toDomain);
}

@Override
public List<Attachment> findAllByTaskIdAndCommentIsNotNull(final Long taskId) {
List<AttachmentEntity> attachmentEntities = attachmentRepository.findAllByTask_TaskIdAndCommentIsNotNull(taskId);
return attachmentEntities.stream()
.map(attachmentPersistenceMapper::toDomain)
.collect(Collectors.toList());
}

@Override
public boolean exitsByCommentId(final Long commentId) {
return attachmentRepository.existsByComment_CommentId(commentId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,4 @@ public Comment saveComment(final Comment comment) {
public void deleteCommentWithTaskHistory(final Long commentId) {
commentRepository.deleteCommentWithTaskHistory(commentId);
}

@Override
public void deleteComment(final Comment comment) {
commentRepository.delete(commentPersistenceMapper.toEntity(comment));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public class MemberEntity extends BaseTimeEntity {

@Column(name = "kakaowork_notification_enabled")
@Builder.Default
private Boolean kakaoworkNotificationEnabled = Boolean.TRUE;;
private Boolean kakaoworkNotificationEnabled = Boolean.TRUE;

@Column(name = "email_notification_enabled")
@Builder.Default
private Boolean emailNotificationEnabled = Boolean.TRUE;;
private Boolean emailNotificationEnabled = Boolean.TRUE;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "admin_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ public class AttachmentEntity extends BaseTimeEntity {
@JoinColumn(name = "task_id")
private TaskEntity task;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "comment_id")
private CommentEntity comment;

@Column(name= "is_deleted", nullable = false)
@Builder.Default
private boolean isDeleted = Boolean.FALSE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@ public class CommentEntity extends BaseTimeEntity {
@Column(name = "content")
private String content;

@Column
private String originalName;

@Column
private String fileUrl;

@Column
private String fileSize;

@Column(name = "is_modified", nullable = false)
private boolean isModified;
@Builder.Default
private boolean isModified = Boolean.FALSE;

@Column(name="is_deleted", nullable = false)
@Builder.Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

@Repository
public interface AttachmentRepository extends JpaRepository<AttachmentEntity, Long> {
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNull(Long taskId);
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNullAndAttachmentIdIn(Long task_taskId, List<Long> attachmentId);
Optional<AttachmentEntity> findByComment_CommentId(Long commentId);
boolean existsByComment_CommentId(Long commentId);
List<AttachmentEntity> findAllByTask_TaskIdAndCommentIsNotNull(Long taskId);
List<AttachmentEntity> findAllByTask_TaskId(Long taskId);
List<AttachmentEntity> findAllByTask_TaskIdAndAttachmentIdIn(Long task_taskId, List<Long> attachmentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private TaskHistoryResponseMapper() {
throw new IllegalArgumentException("Utility class");
}

public static FindTaskHistoryResponse toFindTaskHistoryResponse(List<TaskHistory> taskHistories, List<Attachment> attachments) {
public static FindTaskHistoryResponse toFindTaskHistoryResponse(List<TaskHistory> taskHistories) {
List<FindTaskHistoryResponse.TaskHistoryResponse> historyResponses = taskHistories.stream()
.map(taskHistory -> {
FindTaskHistoryResponse.Details details =
Expand Down Expand Up @@ -47,25 +47,20 @@ public static FindTaskHistoryResponse toFindTaskHistoryResponse(List<TaskHistory
case COMMENT_FILE -> new FindTaskHistoryResponse.Details(
null,
null,
attachments.stream()
.filter(attachment -> attachment.getComment().getCommentId().equals(taskHistory.getComment().getCommentId()))
.findFirst()
.map(attachment -> new FindTaskHistoryResponse.CommentFileDetails(
taskHistory.getComment().getCommentId(),
taskHistory.getComment().getMember().getNickname(),
taskHistory.getComment().getMember().getImageUrl(),
taskHistory.getComment().isModified(),
attachment.getOriginalName(),
attachment.getFileUrl(),
attachment.getFileSize()
))
.orElse(null)
new FindTaskHistoryResponse.CommentFileDetails(
taskHistory.getComment().getCommentId(),
taskHistory.getComment().getMember().getNickname(),
taskHistory.getComment().getMember().getImageUrl(),
taskHistory.getComment().getOriginalName(),
taskHistory.getComment().getFileUrl(),
taskHistory.getComment().getFileSize()
)
);
};
return new FindTaskHistoryResponse.TaskHistoryResponse(
taskHistory.getTaskHistoryId(),
taskHistory.getUpdatedAt().toLocalDate(),
taskHistory.getUpdatedAt().toLocalTime(),
taskHistory.getCreatedAt().toLocalDate(),
taskHistory.getCreatedAt().toLocalTime(),
taskHistory.getType(),
details
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ public interface CommandCommentPort {
Comment saveComment(Comment comment);

void deleteCommentWithTaskHistory(Long commentId);

void deleteComment(Comment comment);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
import clap.server.domain.model.task.Attachment;

import java.util.List;
import java.util.Optional;


public interface LoadAttachmentPort {
List<Attachment> findAllByTaskIdAndCommentIsNull(Long taskId);
List<Attachment> findAllByTaskIdAndCommentIsNullAndAttachmentId(Long taskId, List<Long> attachmentIds);
Optional<Attachment> findByCommentId(Long commentId);
List<Attachment> findAllByTaskIdAndCommentIsNotNull(Long taskId);
boolean exitsByCommentId(Long commentId);
List<Attachment> findAllByTaskId(Long taskId);
List<Attachment> findAllByTaskIdAndAttachmentId(Long taskId, List<Long> attachmentIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ public class CommandCommentService implements EditCommentUsecase, DeleteCommentU

private final MemberService memberService;
private final CommentService commentService;

private final CommandCommentPort commandCommentPort;
private final LoadAttachmentPort loadAttachmentPort;
private final CommandAttachmentPort commandAttachmentPort;

@Transactional
@Override
Expand All @@ -54,23 +51,8 @@ public void editComment(Long memberId, Long commentId, EditCommentRequest reques
@Transactional
@Override
public void deleteComment(Long memberId, Long commentId) {
Member member = memberService.findActiveMember(memberId);
Comment comment = commentService.findById(commentId);

if (comment.getMember().getMemberId().equals(member.getMemberId())) {
if (loadAttachmentPort.exitsByCommentId(commentId)) {
deleteAttachments(commentId);
}
commandCommentPort.deleteCommentWithTaskHistory(commentId);
}else{
throw new ApplicationException(CommentErrorCode.NOT_A_COMMENT_WRITER);
}
}

private void deleteAttachments(Long commentId) {
Attachment attachment = loadAttachmentPort.findByCommentId(commentId)
.orElseThrow(() -> new ApplicationException(CommentErrorCode.COMMENT_ATTACHMENT_NOT_FOUND));
attachment.softDelete();
commandAttachmentPort.save(attachment);
memberService.findActiveMember(memberId);
commentService.findById(commentId);
commandCommentPort.deleteCommentWithTaskHistory(commentId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public FindTaskHistoryResponse findTaskHistories(Long memberId, Long taskId) {
memberService.findActiveMember(memberId);
Task task = loadTaskPort.findById(taskId)
.orElseThrow(()-> new DomainException(TaskErrorCode.TASK_NOT_FOUND));
List<Attachment> attachments = loadAttachmentPort.findAllByTaskIdAndCommentIsNotNull(task.getTaskId());
List<TaskHistory> taskHistories = loadTaskHistoryPort.findAllTaskHistoriesByTaskId(task.getTaskId());
return TaskHistoryResponseMapper.toFindTaskHistoryResponse(taskHistories, attachments);
return TaskHistoryResponseMapper.toFindTaskHistoryResponse(taskHistories);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import java.util.Objects;

import static clap.server.domain.model.task.Attachment.formatFileSize;

@ApplicationService
@RequiredArgsConstructor
public class PostCommentService implements SaveCommentUsecase, SaveCommentAttachmentUsecase {
Expand All @@ -48,7 +50,7 @@ public void save(Long memberId, Long taskId, CreateCommentRequest request) {

// 일반 회원일 경우 => 요청자인지 확인
taskCommentPolicy.validateCommentPermission(task, member);
Comment comment = Comment.createComment(member, task, request.content());
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);
Expand All @@ -71,11 +73,14 @@ public void saveCommentAttachment(Long memberId, Long taskId, MultipartFile file
Member member = memberService.findActiveMember(memberId);

taskCommentPolicy.validateCommentPermission(task, member);
Comment comment = Comment.createComment(member, task, null);

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 savedComment = commandCommentPort.saveComment(comment);
String fileName = saveAttachment(file, task, savedComment);

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

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

}

private String saveAttachment(MultipartFile file, Task task, Comment comment) {
String fileUrl = s3UploadPort.uploadSingleFile(FilePathConstants.TASK_COMMENT, file);
Attachment attachment = Attachment.createCommentAttachment(task, comment, file.getOriginalFilename(), fileUrl, file.getSize());
commandAttachmentPort.save(attachment);
return file.getOriginalFilename();
}
@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public FindTaskDetailsResponse findRequestedTaskDetails(final Long requesterId,
memberService.findActiveMember(requesterId);
Task task = loadTaskPort.findById(taskId)
.orElseThrow(()-> new ApplicationException(TaskErrorCode.TASK_NOT_FOUND));
List<Attachment> attachments = loadAttachmentPort.findAllByTaskIdAndCommentIsNull(taskId);
List<Attachment> attachments = loadAttachmentPort.findAllByTaskId(taskId);
return TaskResponseMapper.toFindTaskDetailResponse(task, attachments);
}

Expand All @@ -40,7 +40,7 @@ public FindTaskDetailsForManagerResponse findTaskDetailsForManager(final Long re
memberService.findActiveMember(requesterId);
Task task = loadTaskPort.findById(taskId)
.orElseThrow(() -> new ApplicationException(TaskErrorCode.TASK_NOT_FOUND));
List<Attachment> attachments = loadAttachmentPort.findAllByTaskIdAndCommentIsNull(taskId);
List<Attachment> attachments = loadAttachmentPort.findAllByTaskId(taskId);
return TaskResponseMapper.toFindTaskDetailForManagerResponse(task, attachments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void updateAttachments(List<Long> attachmentIdsToDelete, List<MultipartF
}

private List<Attachment> validateAndGetAttachments(List<Long> attachmentIdsToDelete, Task task) {
List<Attachment> attachmentsOfTask = loadAttachmentPort.findAllByTaskIdAndCommentIsNullAndAttachmentId(task.getTaskId(), attachmentIdsToDelete);
List<Attachment> attachmentsOfTask = loadAttachmentPort.findAllByTaskIdAndAttachmentId(task.getTaskId(), attachmentIdsToDelete);
if (attachmentsOfTask.size() != attachmentIdsToDelete.size()) {
throw new ApplicationException(TaskErrorCode.TASK_ATTACHMENT_NOT_FOUND);
}
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/clap/server/domain/model/task/Attachment.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
public class Attachment extends BaseTime {
private Long attachmentId;
private Task task;
private Comment comment;
private String originalName;
private String fileUrl;
private String fileSize;
Expand All @@ -21,18 +20,17 @@ public class Attachment extends BaseTime {
public static Attachment createAttachment(Task task, String originalName, String fileUrl, long fileSize) {
return Attachment.builder()
.task(task)
.comment(null)
.originalName(originalName)
.fileUrl(fileUrl)
.fileSize(formatFileSize(fileSize))
.isDeleted(false)
.build();
}

@Deprecated
public static Attachment createCommentAttachment(Task task, Comment comment, String originalName, String fileUrl, long fileSize) {
return Attachment.builder()
.task(task)
.comment(comment)
.originalName(originalName)
.fileUrl(fileUrl)
.fileSize(formatFileSize(fileSize))
Expand All @@ -53,5 +51,4 @@ public static String formatFileSize(long size) {
return String.format("%.1f MB", size / (1024.0 * 1024.0));
}
}

}
10 changes: 8 additions & 2 deletions src/main/java/clap/server/domain/model/task/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import clap.server.domain.model.common.BaseTime;
import clap.server.domain.model.member.Member;
import jakarta.persistence.Column;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -15,15 +16,20 @@ public class Comment extends BaseTime {
private Member member;
private Task task;
private String content;
private String originalName;
private String fileUrl;
private String fileSize;
private boolean isModified;
private boolean isDeleted;

public static Comment createComment(Member member, Task task, String content) {
public static Comment createComment(Member member, Task task, String content, String originalName, String fileUrl, String fileSize) {
return Comment.builder()
.member(member)
.task(task)
.content(content)
.isModified(false)
.originalName(originalName)
.fileUrl(fileUrl)
.fileSize(fileSize)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE comment
ADD COLUMN original_name VARCHAR(255),
ADD COLUMN file_url VARCHAR(255),
ADD COLUMN file_size VARCHAR(255);
Loading