Skip to content

Commit ead328e

Browse files
committed
기본 요구사항 완료
1 parent ca237ff commit ead328e

18 files changed

+164
-69
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
333 Bytes
Binary file not shown.
333 Bytes
Binary file not shown.
Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,60 @@
11
package com.sprint.mission.discodeit;
22

3+
import com.sprint.mission.discodeit.entity.Channel;
4+
import com.sprint.mission.discodeit.entity.Message;
5+
import com.sprint.mission.discodeit.entity.User;
6+
import com.sprint.mission.discodeit.service.ChannelService;
7+
import com.sprint.mission.discodeit.service.MessageService;
8+
import com.sprint.mission.discodeit.service.UserService;
39
import org.springframework.boot.SpringApplication;
410
import org.springframework.boot.autoconfigure.SpringBootApplication;
11+
import org.springframework.context.ConfigurableApplicationContext;
12+
13+
import java.util.Scanner;
514

615
@SpringBootApplication
716
public class DiscodeitApplication {
817

918
public static void main(String[] args) {
10-
SpringApplication.run(DiscodeitApplication.class, args);
19+
ConfigurableApplicationContext context = SpringApplication.run(DiscodeitApplication.class, args);
20+
21+
UserService userService = context.getBean(UserService.class);
22+
ChannelService channelService = context.getBean(ChannelService.class);
23+
MessageService messageService = context.getBean(MessageService.class);
24+
25+
User user = setupUser(userService);
26+
Channel channel = setupChannel(channelService);
27+
28+
messageCreateTest(messageService, channel, user);
29+
}
30+
31+
private static User setupUser(UserService userService) {
32+
Scanner scanner = new Scanner(System.in);
33+
System.out.print("사용자 이름 입력: ");
34+
String userName = scanner.nextLine();
35+
User user = new User(userName);
36+
userService.createUser(user);
37+
System.out.println("생성된 사용자: " + user);
38+
return user;
39+
}
40+
41+
private static Channel setupChannel(ChannelService channelService) {
42+
Scanner scanner = new Scanner(System.in);
43+
System.out.print("채널 이름 입력: ");
44+
String channelName = scanner.nextLine();
45+
Channel channel = new Channel(channelName);
46+
channelService.createChannel(channel);
47+
System.out.println("생성된 채널: " + channel);
48+
return channel;
49+
}
50+
51+
private static void messageCreateTest(MessageService messageService, Channel channel, User user) {
52+
Scanner scanner = new Scanner(System.in);
53+
System.out.print("보낼 메시지 입력: ");
54+
String msgContent = scanner.nextLine();
55+
Message message = new Message(msgContent, user.getId(), channel.getId());
56+
messageService.createMessage(message);
57+
System.out.println("메시지 전송: " + message);
1158
}
1259

1360
}

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

Lines changed: 0 additions & 35 deletions
This file was deleted.

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
11
package com.sprint.mission.discodeit.entity;
22

3+
import lombok.Getter;
4+
35
import java.io.Serializable;
46
import java.util.*;
57

6-
public class Channel extends BaseEntity implements Serializable {
8+
@Getter
9+
public class Channel implements Serializable {
710
private static final long serialVersionUID = 3253334103732539416L;
11+
12+
private final UUID id;
13+
private final Long createdAt;
14+
private Long updatedAt;
815
private String channelName;
916
private final Set<UUID> userIds = new HashSet<>();
1017
private final List<UUID> messageIds = new ArrayList<>();
1118

1219
public Channel(String channelName) {
20+
this.id = UUID.randomUUID();
21+
this.createdAt = System.currentTimeMillis();
22+
this.updatedAt = createdAt;
1323
this.channelName = channelName;
1424
}
1525

16-
public String getChannelName() {
17-
return channelName;
26+
public void updateTime() {
27+
this.updatedAt = System.currentTimeMillis();
1828
}
1929

2030
public void updateChannelName(String channelName) {
2131
this.channelName = channelName;
2232
updateTime();
2333
}
2434

25-
public Set<UUID> getUserIds() {
26-
return userIds;
27-
}
28-
29-
public List<UUID> getMessageIds() { return messageIds; }
30-
3135
public void addUser(UUID userId) {
3236
userIds.add(userId);
3337
updateTime();

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,43 @@
11
package com.sprint.mission.discodeit.entity;
22

3+
import lombok.Getter;
4+
35
import java.io.Serializable;
46
import java.util.Date;
7+
import java.util.Objects;
58
import java.util.UUID;
69

7-
public class Message extends BaseEntity implements Serializable {
10+
@Getter
11+
public class Message implements Serializable {
812
private static final long serialVersionUID = 5140283631663474458L;
13+
14+
private final UUID id;
15+
private final Long createdAt;
16+
private Long updatedAt;
917
private String msgContent;
1018
private final UUID senderId;
1119
private final UUID channelId;
1220

1321
public Message(String msgContent, UUID senderId, UUID channelId) {
22+
this.id = UUID.randomUUID();
23+
this.createdAt = new Date().getTime();
24+
this.updatedAt = new Date().getTime();
1425
this.msgContent = msgContent;
1526
this.senderId = senderId;
1627
this.channelId = channelId;
1728
}
1829

30+
public void updateTime() {
31+
this.updatedAt = System.currentTimeMillis();
32+
}
33+
1934
public void updateMsgContent(String msgContent) {
2035
this.msgContent = msgContent;
2136
updateTime();
2237
}
2338

24-
public UUID getSenderId() { return senderId; }
25-
26-
public UUID getChannelId() {
27-
return channelId;
28-
}
29-
3039
public boolean isUpdated() {
31-
return getUpdatedAt() != getCreatedAt();
40+
return !Objects.equals(getUpdatedAt(), getCreatedAt());
3241
}
3342

3443
@Override

0 commit comments

Comments
 (0)