Skip to content

Commit b9fb9a2

Browse files
committed
메시지 시간 표현
1 parent c25068f commit b9fb9a2

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public static void main(String[] args) {
6363
System.out.println("채널 : " + channel1.getChannelName() + "의 모든 메시지 목록");
6464
messageService.getAllMessages().stream()
6565
.filter(message -> message.getChannelId().equals(channel1.getId()))
66-
.forEach(message -> System.out.println(message.getId() + " - " + message.getMsgContent()));
66+
.forEach(message -> System.out.println(message.getId() + " - " + message));
6767

6868
System.out.println("채널 : " + channel2.getChannelName() + "의 모든 메시지 목록");
6969
messageService.getAllMessages().stream()
7070
.filter(message -> message.getChannelId().equals(channel2.getId()))
71-
.forEach(message -> System.out.println(message.getId() + " - " + message.getMsgContent()));
71+
.forEach(message -> System.out.println(message.getId() + " - " + message));
7272

7373
System.out.println();
7474
System.out.print("수정된 유저 정보 : ");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ public long getUpdatedAt() {
2929
public void updateTime() {
3030
this.updatedAt = System.currentTimeMillis();
3131
}
32+
3233
}

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

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

3+
import java.util.Date;
34
import java.util.UUID;
45

56
public class Message extends BaseEntity {
@@ -26,12 +27,19 @@ public UUID getChannelId() {
2627
return channelId;
2728
}
2829

30+
public boolean isUpdated() {
31+
return getUpdatedAt() != getCreatedAt();
32+
}
33+
2934
@Override
3035
public String toString() {
31-
return "Message{senderId=" + senderId +
32-
", channelId=" + channelId +
33-
", msgContent=" + msgContent +
34-
", createdAt=" + getCreatedAt() +
35-
", updatedAt=" + getUpdatedAt() + '}';
36+
StringBuilder sb = new StringBuilder();
37+
long displayTime = isUpdated() ? getUpdatedAt() : getCreatedAt();
38+
sb.append("[").append(new Date(displayTime)).append("] ");
39+
sb.append(msgContent);
40+
if (isUpdated()) {
41+
sb.append(" (수정됨)");
42+
}
43+
return sb.toString();
3644
}
3745
}

src/main/java/com/sprint/mission/discodeit/service/jcf/JCFMessageService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public Message createMessageCheck(String msgContent, UUID senderId, UUID channel
6262
}
6363

6464
Message message = new Message(msgContent, senderId, channelId);
65-
data.put(message.getId(), message);
66-
channelService.addMessageToChannel(channelId,message.getId());
67-
return message;
65+
Message created = createMessage(message);
66+
channelService.addMessageToChannel(channelId, created.getId());
67+
return created;
6868
}
6969
}

0 commit comments

Comments
 (0)