Skip to content

Commit c1bd0d5

Browse files
committed
CLAP-375 Fix: comment 속성 추가 스키마 분리
1 parent e55295d commit c1bd0d5

File tree

6 files changed

+33
-25
lines changed

6 files changed

+33
-25
lines changed

src/main/java/clap/server/application/mapper/response/TaskHistoryResponseMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public static FindTaskHistoryResponse toFindTaskHistoryResponse(List<TaskHistory
5959
};
6060
return new FindTaskHistoryResponse.TaskHistoryResponse(
6161
taskHistory.getTaskHistoryId(),
62-
taskHistory.getUpdatedAt().toLocalDate(),
63-
taskHistory.getUpdatedAt().toLocalTime(),
62+
taskHistory.getCreatedAt().toLocalDate(),
63+
taskHistory.getCreatedAt().toLocalTime(),
6464
taskHistory.getType(),
6565
details
6666
);

src/main/java/clap/server/application/service/history/PostCommentService.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
import java.util.Objects;
2929

30+
import static clap.server.domain.model.task.Attachment.formatFileSize;
31+
3032
@ApplicationService
3133
@RequiredArgsConstructor
3234
public class PostCommentService implements SaveCommentUsecase, SaveCommentAttachmentUsecase {
@@ -48,7 +50,7 @@ public void save(Long memberId, Long taskId, CreateCommentRequest request) {
4850

4951
// 일반 회원일 경우 => 요청자인지 확인
5052
taskCommentPolicy.validateCommentPermission(task, member);
51-
Comment comment = Comment.createComment(member, task, request.content());
53+
Comment comment = Comment.createComment(member, task, request.content(), null, null, null);
5254
Comment savedComment = commandCommentPort.saveComment(comment);
5355

5456
TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.COMMENT, task, null, member, savedComment);
@@ -71,11 +73,14 @@ public void saveCommentAttachment(Long memberId, Long taskId, MultipartFile file
7173
Member member = memberService.findActiveMember(memberId);
7274

7375
taskCommentPolicy.validateCommentPermission(task, member);
74-
Comment comment = Comment.createComment(member, task, null);
76+
77+
String fileUrl = s3UploadPort.uploadSingleFile(FilePathConstants.TASK_COMMENT, file);
78+
String fileName = file.getOriginalFilename();
79+
80+
Comment comment = Comment.createComment(member, task, null, fileName, fileUrl, formatFileSize(file.getSize()));
7581
Comment savedComment = commandCommentPort.saveComment(comment);
76-
String fileName = saveAttachment(file, task);
7782

78-
TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.COMMENT_FILE, task, null, member, savedComment);
83+
TaskHistory taskHistory = TaskHistory.createTaskHistory(TaskHistoryType.COMMENT_FILE, null, null, null, savedComment);
7984
commandTaskHistoryPort.save(taskHistory);
8085

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

8994
}
9095

91-
private String saveAttachment(MultipartFile file, Task task) {
92-
String fileUrl = s3UploadPort.uploadSingleFile(FilePathConstants.TASK_COMMENT, file);
93-
Attachment attachment = Attachment.createCommentAttachment(task, file.getOriginalFilename(), fileUrl, file.getSize());
94-
commandAttachmentPort.save(attachment);
95-
return file.getOriginalFilename();
96-
}
96+
@Deprecated
97+
// private String saveAttachment(MultipartFile file, Task task) {
98+
// String fileUrl = s3UploadPort.uploadSingleFile(FilePathConstants.TASK_COMMENT, file);
99+
// Attachment attachment = Attachment.createCommentAttachment(task, null, file.getOriginalFilename(), fileUrl, file.getSize());
100+
// commandAttachmentPort.save(attachment);
101+
// return file.getOriginalFilename();
102+
// }
97103

98104
private void publishNotification(Member receiver, Task task, String message, String commenterName) {
99105
boolean isManager = receiver.getMemberInfo().getRole() == MemberRole.ROLE_MANAGER;

src/main/java/clap/server/domain/model/task/Attachment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static Attachment createAttachment(Task task, String originalName, String
2727
.build();
2828
}
2929

30+
@Deprecated
3031
public static Attachment createCommentAttachment(Task task, Comment comment, String originalName, String fileUrl, long fileSize) {
3132
return Attachment.builder()
3233
.task(task)
@@ -50,5 +51,4 @@ public static String formatFileSize(long size) {
5051
return String.format("%.1f MB", size / (1024.0 * 1024.0));
5152
}
5253
}
53-
5454
}

src/main/java/clap/server/domain/model/task/Comment.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ public class Comment extends BaseTime {
2222
private boolean isModified;
2323
private boolean isDeleted;
2424

25-
public static Comment createComment(Member member, Task task, String content) {
25+
public static Comment createComment(Member member, Task task, String content, String originalName, String fileUrl, String fileSize) {
2626
return Comment.builder()
2727
.member(member)
2828
.task(task)
2929
.content(content)
30+
.originalName(originalName)
31+
.fileUrl(fileUrl)
32+
.fileSize(fileSize)
3033
.build();
3134
}
3235

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTER TABLE comment
2+
ADD COLUMN original_name VARCHAR(255),
3+
ADD COLUMN file_url VARCHAR(255),
4+
ADD COLUMN file_size VARCHAR(255);
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
-- Step 1: comment 테이블에 컬럼 추가
2-
ALTER TABLE comment
3-
ADD COLUMN original_name VARCHAR(255),
4-
ADD COLUMN file_url VARCHAR(255),
5-
ADD COLUMN file_size VARCHAR(255);
6-
7-
-- Step 2: attachment 데이터 복사
81
START TRANSACTION;
2+
-- Step 1: attachment 데이터 복사
93
UPDATE comment c
104
JOIN attachment a ON c.comment_id = a.comment_id
115
SET
126
c.original_name = a.original_name,
137
c.file_url = a.file_url,
14-
c.file_size = a.file_size,
15-
WHERE c.attachment_id IS NOT NULL;
8+
c.file_size = a.file_size
9+
WHERE a.attachment_id IS NOT NULL;
1610
COMMIT;
1711

18-
-- Step 3: attachment 테이블에 제약조건 제거
12+
-- Step 2: attachment 테이블에 제약조건 제거
1913
ALTER TABLE attachment
2014
DROP FOREIGN KEY FKds6u1rptrsif835t89kb15cyo,
21-
DROP COLUMN comment_id;
15+
DROP COLUMN comment_id;
16+

0 commit comments

Comments
 (0)