Skip to content

Commit 614d02c

Browse files
committed
시간 타입 변경 및 새로운 도메인 추가
1 parent ead328e commit 614d02c

File tree

10 files changed

+279
-64
lines changed

10 files changed

+279
-64
lines changed

src/main/java/com/sprint/mission/discodeit/JavaApplication.java

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -85,44 +85,44 @@
8585
// }
8686
// }
8787
//}
88-
89-
public class JavaApplication {
90-
public static void main(String[] args) {
91-
UserRepository userRepository = new FileUserRepository(Paths.get("data/users"));
92-
ChannelRepository channelRepository = new FileChannelRepository(Paths.get("data/channels"));
93-
MessageRepository messageRepository = new FileMessageRepository(Paths.get("data/messages"));
94-
95-
UserService userService = new BasicUserService(userRepository);
96-
ChannelService channelService = new BasicChannelService(channelRepository);
97-
MessageService messageService = new BasicMessageService(messageRepository);
98-
99-
UserIntegration userIntegration = new UserIntegration(userService, channelService);
100-
ChannelIntegration channelIntegration = new ChannelIntegration(channelService, userService, messageService);
101-
MessageIntegration messageIntegration = new MessageIntegration(messageService, userService, channelService);
102-
103-
Scanner scanner = new Scanner(System.in);
104-
while (true) {
105-
System.out.println("\n===== MAIN MENU =====");
106-
System.out.println("1. 사용자 메뉴");
107-
System.out.println("2. 채널 메뉴");
108-
System.out.println("3. 메시지 메뉴");
109-
System.out.println("0. 종료");
110-
System.out.print("번호를 입력하세요: ");
111-
String input = scanner.nextLine();
112-
113-
switch (input) {
114-
case "1" -> UserMenu.manageUsers(scanner, userService, userIntegration);
115-
case "2" -> ChannelMenu.manageChannels(scanner, channelService, channelIntegration);
116-
case "3" -> MessageMenu.manageMessages(scanner, messageService, messageIntegration);
117-
case "0" -> {
118-
System.out.println("종료합니다.");
119-
return;
120-
}
121-
default -> System.out.println("올바른 번호를 입력하세요.");
122-
}
123-
}
124-
}
125-
}
88+
//
89+
//public class JavaApplication {
90+
// public static void main(String[] args) {
91+
// UserRepository userRepository = new FileUserRepository(Paths.get("data/users"));
92+
// ChannelRepository channelRepository = new FileChannelRepository(Paths.get("data/channels"));
93+
// MessageRepository messageRepository = new FileMessageRepository(Paths.get("data/messages"));
94+
//
95+
// UserService userService = new BasicUserService(userRepository);
96+
// ChannelService channelService = new BasicChannelService(channelRepository);
97+
// MessageService messageService = new BasicMessageService(messageRepository);
98+
//
99+
// UserIntegration userIntegration = new UserIntegration(userService, channelService);
100+
// ChannelIntegration channelIntegration = new ChannelIntegration(channelService, userService, messageService);
101+
// MessageIntegration messageIntegration = new MessageIntegration(messageService, userService, channelService);
102+
//
103+
// Scanner scanner = new Scanner(System.in);
104+
// while (true) {
105+
// System.out.println("\n===== MAIN MENU =====");
106+
// System.out.println("1. 사용자 메뉴");
107+
// System.out.println("2. 채널 메뉴");
108+
// System.out.println("3. 메시지 메뉴");
109+
// System.out.println("0. 종료");
110+
// System.out.print("번호를 입력하세요: ");
111+
// String input = scanner.nextLine();
112+
//
113+
// switch (input) {
114+
// case "1" -> UserMenu.manageUsers(scanner, userService, userIntegration);
115+
// case "2" -> ChannelMenu.manageChannels(scanner, channelService, channelIntegration);
116+
// case "3" -> MessageMenu.manageMessages(scanner, messageService, messageIntegration);
117+
// case "0" -> {
118+
// System.out.println("종료합니다.");
119+
// return;
120+
// }
121+
// default -> System.out.println("올바른 번호를 입력하세요.");
122+
// }
123+
// }
124+
// }
125+
//}
126126

127127
/*
128128
JCF*Service, File*Service와 Basic*Service의 차이
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.sprint.mission.discodeit.entity;
2+
3+
import lombok.Getter;
4+
5+
import java.io.Serial;
6+
import java.io.Serializable;
7+
import java.time.Instant;
8+
import java.util.Arrays;
9+
import java.util.UUID;
10+
11+
@Getter
12+
public class BinaryContent implements Serializable {
13+
14+
@Serial
15+
private static final long serialVersionUID = 1887370024504996215L;
16+
17+
private final UUID id;
18+
private final Instant createdAt;
19+
20+
private final byte[] data;
21+
private final String contentType;
22+
private final String fileName;
23+
24+
public BinaryContent(byte[] data, String contentType, String fileName) {
25+
this.id = UUID.randomUUID();
26+
this.createdAt = Instant.now();
27+
this.data = data;
28+
this.contentType = contentType;
29+
this.fileName = fileName;
30+
}
31+
32+
@Override
33+
public String toString() {
34+
return "BinaryContent{" +
35+
"id=" + id +
36+
", createdAt=" + createdAt +
37+
", data=" + Arrays.toString(data) +
38+
", contentType='" + contentType + '\'' +
39+
", fileName='" + fileName + '\'' +
40+
'}';
41+
}
42+
}

src/main/java/com/sprint/mission/discodeit/entity/Channel.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,33 @@
22

33
import lombok.Getter;
44

5+
import java.io.Serial;
56
import java.io.Serializable;
7+
import java.time.Instant;
68
import java.util.*;
79

810
@Getter
911
public class Channel implements Serializable {
12+
13+
@Serial
1014
private static final long serialVersionUID = 3253334103732539416L;
1115

1216
private final UUID id;
13-
private final Long createdAt;
14-
private Long updatedAt;
17+
private final Instant createdAt;
18+
private Instant updatedAt;
1519
private String channelName;
1620
private final Set<UUID> userIds = new HashSet<>();
1721
private final List<UUID> messageIds = new ArrayList<>();
1822

1923
public Channel(String channelName) {
2024
this.id = UUID.randomUUID();
21-
this.createdAt = System.currentTimeMillis();
25+
this.createdAt = Instant.now();
2226
this.updatedAt = createdAt;
2327
this.channelName = channelName;
2428
}
2529

2630
public void updateTime() {
27-
this.updatedAt = System.currentTimeMillis();
31+
this.updatedAt = Instant.now();
2832
}
2933

3034
public void updateChannelName(String channelName) {
@@ -48,8 +52,8 @@ public String toString() {
4852
"channelName='" + channelName + '\'' +
4953
", userIds=" + userIds +
5054
", messageIds=" + messageIds +
51-
", createdAt=" + new Date(getCreatedAt()) +
52-
", updatedAt=" + new Date(getUpdatedAt()) +
55+
", createdAt=" + Date.from(createdAt) +
56+
", updatedAt=" + Date.from(updatedAt) +
5357
'}';
5458
}
5559
}

src/main/java/com/sprint/mission/discodeit/entity/Message.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,36 @@
22

33
import lombok.Getter;
44

5+
import java.io.Serial;
56
import java.io.Serializable;
6-
import java.util.Date;
7-
import java.util.Objects;
8-
import java.util.UUID;
7+
import java.time.Instant;
8+
import java.util.*;
99

1010
@Getter
1111
public class Message implements Serializable {
12+
13+
@Serial
1214
private static final long serialVersionUID = 5140283631663474458L;
1315

1416
private final UUID id;
15-
private final Long createdAt;
16-
private Long updatedAt;
17+
private final Instant createdAt;
18+
private Instant updatedAt;
1719
private String msgContent;
18-
private final UUID senderId;
20+
private final UUID authorId;
1921
private final UUID channelId;
22+
private final List<UUID> attachmentIds = new ArrayList<>();
2023

21-
public Message(String msgContent, UUID senderId, UUID channelId) {
24+
public Message(String msgContent, UUID authorId, UUID channelId) {
2225
this.id = UUID.randomUUID();
23-
this.createdAt = new Date().getTime();
24-
this.updatedAt = new Date().getTime();
26+
this.createdAt = Instant.now();
27+
this.updatedAt = createdAt;
2528
this.msgContent = msgContent;
26-
this.senderId = senderId;
29+
this.authorId = authorId;
2730
this.channelId = channelId;
2831
}
2932

3033
public void updateTime() {
31-
this.updatedAt = System.currentTimeMillis();
34+
this.updatedAt = Instant.now();
3235
}
3336

3437
public void updateMsgContent(String msgContent) {
@@ -40,16 +43,21 @@ public boolean isUpdated() {
4043
return !Objects.equals(getUpdatedAt(), getCreatedAt());
4144
}
4245

46+
public void addAttachment(UUID attachmentId) {
47+
this.attachmentIds.add(attachmentId);
48+
updateTime();
49+
}
50+
4351
@Override
4452
public String toString() {
4553
StringBuilder sb = new StringBuilder();
46-
long displayTime = isUpdated() ? getUpdatedAt() : getCreatedAt();
47-
sb.append("[").append(new Date(displayTime)).append("] ");
54+
Instant displayTime = isUpdated() ? getUpdatedAt() : getCreatedAt();
55+
sb.append("[").append(Date.from(displayTime)).append("] ");
4856
sb.append(msgContent);
4957
if (isUpdated()) {
5058
sb.append(" (수정됨)");
5159
}
52-
sb.append(" [").append(senderId).append("] ");
60+
sb.append(" [").append(authorId).append("] ");
5361
return sb.toString();
5462
}
5563
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.sprint.mission.discodeit.entity;
2+
3+
import lombok.Getter;
4+
5+
import java.io.Serial;
6+
import java.time.Instant;
7+
import java.util.UUID;
8+
9+
@Getter
10+
public class ReadStatus implements java.io.Serializable {
11+
12+
@Serial
13+
private static final long serialVersionUID = 4852408247773241680L;
14+
15+
private final UUID id;
16+
private final Instant createdAt;
17+
private Instant updatedAt;
18+
19+
private final UUID userId;
20+
private final UUID channelId;
21+
private Instant readAt;
22+
23+
public ReadStatus(UUID userId, UUID channelId, Instant readAt) {
24+
this.id = UUID.randomUUID();
25+
this.createdAt = Instant.now();
26+
this.updatedAt = createdAt;
27+
this.userId = userId;
28+
this.channelId = channelId;
29+
this.readAt = readAt;
30+
}
31+
32+
public void updateTime() {
33+
this.updatedAt = Instant.now();
34+
}
35+
36+
public void updateReadTime(Instant readAt) {
37+
this.readAt = readAt;
38+
updateTime();
39+
}
40+
41+
@Override
42+
public String toString() {
43+
return "ReadStatus{" +
44+
"id=" + id +
45+
", createdAt=" + createdAt +
46+
", updatedAt=" + updatedAt +
47+
", userId=" + userId +
48+
", channelId=" + channelId +
49+
", readAt=" + readAt +
50+
'}';
51+
}
52+
}

src/main/java/com/sprint/mission/discodeit/entity/User.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,53 @@
22

33
import lombok.Getter;
44

5+
import java.io.Serial;
56
import java.io.Serializable;
7+
import java.time.Instant;
68
import java.util.Date;
79
import java.util.UUID;
810

911
@Getter
1012
public class User implements Serializable {
13+
14+
@Serial
1115
private static final long serialVersionUID = -1421022282607757997L;
1216

1317
private final UUID id;
14-
private final Long createdAt;
15-
private Long updatedAt;
18+
private final Instant createdAt;
19+
private Instant updatedAt;
1620
private String userName;
1721

22+
private UUID profileId;
23+
1824
public User(String userName) {
1925
this.id = UUID.randomUUID();
20-
this.createdAt = new Date().getTime();
26+
this.createdAt = Instant.now();
2127
this.updatedAt = createdAt;
2228
this.userName = userName;
2329
}
2430

2531
public void updateTime() {
26-
this.updatedAt = System.currentTimeMillis();
32+
this.updatedAt = Instant.now();
2733
}
2834

2935
public void updateUserName(String userName) {
3036
this.userName = userName;
3137
updateTime();
3238
}
3339

40+
public void updateProfileId(UUID profileId) {
41+
this.profileId = profileId;
42+
updateTime();
43+
}
44+
3445
@Override
3546
public String toString() {
3647
return "User{" +
3748
"userName='" + userName + '\'' +
38-
", createdAt=" + new Date(getCreatedAt()) +
39-
", updatedAt=" + new Date(getUpdatedAt()) +
49+
", profileId=" + profileId +
50+
", createdAt=" + Date.from(createdAt) +
51+
", updatedAt=" + Date.from(updatedAt) +
4052
'}';
4153
}
4254
}

0 commit comments

Comments
 (0)