-
Notifications
You must be signed in to change notification settings - Fork 58
[박태식] sprint3 #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "part1-\uBC15\uD0DC\uC2DD-sprint3"
[박태식] sprint3 #170
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip | ||
#distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.sprint.mission.discodeit.domain; | ||
|
||
public enum ChannelType { | ||
Private, Public; | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.sprint.mission.discodeit.domain; | ||
|
||
public enum Mimetype { | ||
User, Message; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.sprint.mission.discodeit.dto; | ||
|
||
import com.sprint.mission.discodeit.domain.ChannelType; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public record ChannelRequest( | ||
String name, | ||
String description, | ||
List<UUID> member, | ||
UUID owner, | ||
ChannelType channelType | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.sprint.mission.discodeit.dto; | ||
|
||
import com.sprint.mission.discodeit.domain.ChannelType; | ||
import com.sprint.mission.discodeit.entity.Channel; | ||
|
||
import javax.naming.directory.NoSuchAttributeException; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public record ChannelResponse( | ||
String name, | ||
String description, | ||
List<UUID> member, | ||
UUID owner, | ||
ChannelType channelType | ||
) { | ||
public static ChannelResponse fromEntity(Channel channel){ | ||
return new ChannelResponse( | ||
channel.getName(), | ||
channel.getDescription(), | ||
channel.getMember(), | ||
channel.getOwner(), | ||
channel.getChannelType() | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.sprint.mission.discodeit.dto; | ||
|
||
import java.util.UUID; | ||
|
||
public record MessageRequest( | ||
String content, | ||
UUID senderId, | ||
UUID recipientId, | ||
UUID channelId, | ||
UUID attachedFileId | ||
) { | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.sprint.mission.discodeit.dto; | ||
|
||
import com.sprint.mission.discodeit.entity.Message; | ||
|
||
import java.util.UUID; | ||
|
||
public record MessageResponse( | ||
String content, | ||
UUID senderId, | ||
UUID recipientId, | ||
UUID channelId | ||
) { | ||
public static MessageResponse fromEntity(Message message){ | ||
return new MessageResponse( | ||
message.getContent(), | ||
message.getSenderId(), | ||
message.getRecipientId(), | ||
message.getChannelId() | ||
); | ||
Comment on lines
+14
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 저번 리뷰를 잘 반영해주신 것 같아요. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.sprint.mission.discodeit.dto; | ||
|
||
import com.sprint.mission.discodeit.domain.ChannelType; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public record PrivateChannelRequest( | ||
List<UUID> member, | ||
UUID owner, | ||
ChannelType channelType | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.sprint.mission.discodeit.dto; | ||
|
||
import com.sprint.mission.discodeit.domain.ChannelType; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public record PublicChannelRequest( | ||
String name, | ||
String description, | ||
UUID owner, | ||
ChannelType channelType | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.sprint.mission.discodeit.dto; | ||
|
||
import java.util.UUID; | ||
|
||
public record UserRequest( | ||
String username, | ||
String password, | ||
String email, | ||
String phoneNumber, | ||
UUID profileImageId | ||
// String profileImageName | ||
) { | ||
} | ||
Comment on lines
+5
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Record의 히스토리를 한번 공부해보시는 걸 추천합니다.
Spring에서는 JSON 요청을 객체로 변환할 때 Jackson을 사용해 역직렬화를 수행하는데요. record에서는 기본적으로 기본 생성자가 따로 없습니다. 그래서 아래와 같이 작성해주셔야 합니다. public record UserRequest(
@JsonProperty("username") String username,
@JsonProperty("password") String password,
@JsonProperty("email") String email,
@JsonProperty("phoneNumber") String phoneNumber,
@JsonProperty("profileImageId") UUID profileImageId
// @JsonProperty("profileImageName") String profileImageName
) {
// @JsonCreator를 추가하여 명시적으로 생성자를 지정
@JsonCreator
public UserRequest(
@JsonProperty("username") String username,
@JsonProperty("password") String password,
@JsonProperty("email") String email,
@JsonProperty("phoneNumber") String phoneNumber,
@JsonProperty("profileImageId") UUID profileImageId
// @JsonProperty("profileImageName") String profileImageName
) {
this.username = username;
this.password = password;
this.email = email;
this.phoneNumber = phoneNumber;
this.profileImageId = profileImageId;
// this.profileImageName = profileImageName; // 주석처리된 부분도 필요에 맞게 추가 가능
}
} 뭔가 상당히 불편해 보이시지 않나요 ^-^..? @JsonCreator를 통해서 생성자를 명시적으로 지정하여 Jackson이 record 객체를 생성할 때 사용할 생성자를 알 수 있도록 해야 하고, @JsonProperty를 사용해서 JSON 필드 이름과 record 필드명을 매핑시켜줘야 역직렬화가 이루어지게 됩니다. 이러한 이유들 때문에 예전에는 안쓰는 팀도 많았습니다. 단순히 class에 Lombok 어노테이션을 쓰면 간소화 할 수 있기 때문이지요. 그런데 JDK 14부터는 그런 문제들이 해결되었다고 하더라구요. 그렇기 때문에 Record 도입은 버전을 잘 고려하시면서 적용시키면 좋을 것 같습니다 (나중에 프로젝트를 하시고, 면접에 가셨을 때 DTO를 record를 쓰신 이유를 물어보거나 역직렬화 이슈에 대해 면접관들이 물어보면, 잘 대답해주시면 면접관들이 좋아 죽습니다 😄) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.sprint.mission.discodeit.dto; | ||
|
||
import com.sprint.mission.discodeit.entity.User; | ||
|
||
import java.util.UUID; | ||
|
||
public record UserResponse( | ||
UUID id, | ||
String username, | ||
String email, | ||
String phoneNumber, | ||
boolean isOnline | ||
) { | ||
public static UserResponse fromEntity(User user, Boolean isOnline) { | ||
return new UserResponse(user.getId(), user.getUsername(), user.getEmail(), user.getPhoneNumber(), isOnline); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,30 @@ | ||
package com.sprint.mission.discodeit.entity; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import lombok.Getter; | ||
|
||
import java.io.Serializable; | ||
import java.time.Instant; | ||
import java.util.UUID; | ||
|
||
//@Entity | ||
@Getter | ||
public abstract class BaseEntity implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
// @Id | ||
private UUID id; | ||
private Long createdAt; | ||
private Long updatedAt; | ||
private Instant createdAt; | ||
private Instant updatedAt; | ||
|
||
public BaseEntity(){ | ||
this.id = id != null ? id : UUID.randomUUID(); | ||
// System.out.println("새로 생성된 UUID: " + this.id); // 로그 추가 | ||
this.createdAt = System.currentTimeMillis(); | ||
this.createdAt = Instant.ofEpochMilli(System.currentTimeMillis()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 라이브러리 메소드를 사용하는 부분이 인상적이네요 잘하셨습니다 👍 |
||
this.updatedAt = createdAt; | ||
} | ||
|
||
public UUID getId(){ | ||
return id; | ||
} | ||
|
||
public Long getCreatedAt(){ | ||
return createdAt; | ||
} | ||
|
||
public Long getUpdatedAt(){ | ||
return updatedAt; | ||
} | ||
|
||
public void update(){ | ||
this.updatedAt = System.currentTimeMillis(); | ||
this.updatedAt = Instant.ofEpochMilli(System.currentTimeMillis()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.sprint.mission.discodeit.entity; | ||
|
||
import com.sprint.mission.discodeit.domain.Mimetype; | ||
import lombok.Getter; | ||
|
||
import java.io.Serializable; | ||
import java.time.Instant; | ||
import java.util.UUID; | ||
|
||
@Getter | ||
public class BinaryContent implements Serializable { | ||
private static final long getSerialVersionUID = 1L; | ||
private UUID id; | ||
private final Instant createdAt; | ||
private final UUID typeId; | ||
// private final byte[] content; | ||
private final Mimetype mimetype; | ||
|
||
public BinaryContent(UUID typeId, Mimetype mimetype) { | ||
this.id = id != null ? id : UUID.randomUUID(); | ||
this.createdAt = Instant.ofEpochMilli(System.currentTimeMillis()); | ||
this.typeId = typeId; | ||
// this.content = content; | ||
this.mimetype = mimetype; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,39 @@ | ||
package com.sprint.mission.discodeit.entity; | ||
|
||
import com.sprint.mission.discodeit.domain.ChannelType; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Getter @Setter | ||
@Getter | ||
public class Channel extends BaseEntity implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
private String name; | ||
private String description; | ||
private List<User> member; | ||
private User owner; | ||
private List<UUID> member; | ||
private UUID owner; | ||
private ChannelType channelType; | ||
|
||
public Channel(String name, String description, List<User> member, User owner){ | ||
public Channel(String name, String description, List<UUID> member, UUID owner, ChannelType channelType){ | ||
super(); | ||
this.name = name; | ||
this.description = description; | ||
this.member = member; | ||
this.owner = owner; | ||
this.channelType = channelType; | ||
} | ||
|
||
public void setName(String name){ | ||
this.name = name; | ||
} | ||
|
||
public void setDescription(String description){ | ||
this.description = description; | ||
} | ||
|
||
public boolean isPrivate(){ | ||
return this.channelType == ChannelType.Private; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
package com.sprint.mission.discodeit.entity; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.io.Serializable; | ||
import java.util.UUID; | ||
|
||
|
||
@Getter @Setter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 엇.. 엔티티에 @Setter가 열려있는 것 같습니다. |
||
public class Message extends BaseEntity implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
private String content; | ||
private User sender; | ||
private User recipient; | ||
private Channel channel; | ||
|
||
|
||
public Message(String content, User sender, Channel channel) { | ||
super(); | ||
this.content = content; | ||
this.sender = sender; | ||
this.channel = channel; | ||
} | ||
private UUID senderId; | ||
private UUID recipientId; | ||
private UUID channelId; | ||
private BinaryContent attachedFileId; | ||
|
||
public Message(String content, User sender, User recipient) { | ||
public Message(String content, UUID senderId, UUID recipientId, UUID channelId) { | ||
super(); | ||
this.content = content; | ||
this.sender = sender; | ||
this.recipient = recipient; | ||
this.senderId = senderId; | ||
this.recipientId = recipientId; | ||
this.channelId = channelId; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.sprint.mission.discodeit.entity; | ||
|
||
import lombok.Getter; | ||
|
||
import java.io.Serializable; | ||
import java.time.Instant; | ||
|
||
@Getter | ||
public class ReadStatus extends BaseEntity implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
private final String userId; | ||
private final String channelId; | ||
private Instant lastReadAt; | ||
|
||
public ReadStatus(String userId, String channelId, Instant lastReadAt) { | ||
super(); | ||
this.userId = userId; | ||
this.channelId = channelId; | ||
this.lastReadAt = lastReadAt; | ||
} | ||
|
||
public void updateLastRead(Instant timestamp) { | ||
this.lastReadAt = timestamp; | ||
update(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
개인적인 취향 차이일 수도 있는데요. 이렇게 enum 타입을 따로 클래스로 빼서 관리하는 팀들도 있지만, 타입에 대해서 도메인으로 묶어버리시는 분들도 많아요
개인적으로는 단순히 code를 관리하는 목적이라고 한다면 Channel 도메인에 넣어두는게 좋을 것 같아요 :D
클래스 내부에서 선언하는 방법도 알아두시면 좋을 것 같아요
향로님 enum 블로그