-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAttachment.java
More file actions
57 lines (50 loc) · 1.71 KB
/
Attachment.java
File metadata and controls
57 lines (50 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package clap.server.domain.model.task;
import clap.server.domain.model.common.BaseTime;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
@Getter
@SuperBuilder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Attachment extends BaseTime {
private Long attachmentId;
private Task task;
private Comment comment;
private String originalName;
private String fileUrl;
private String fileSize;
private boolean isDeleted;
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();
}
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))
.isDeleted(false)
.build();
}
public void softDelete() {
this.isDeleted = true;
}
public static String formatFileSize(long size) {
if (size < 1024) {
return size + " B";
} else if (size < 1024 * 1024) {
return String.format("%.1f KB", size / 1024.0);
} else {
return String.format("%.1f MB", size / (1024.0 * 1024.0));
}
}
}