Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a280750
feat(domain): college, invite, user, relation, tag, attachment 관련 엔티티 추가
mk3058 Aug 21, 2023
c65be37
feat(domain): add default entities
mk3058 Aug 22, 2023
45b31eb
refactor: 일부 잘못된 패키지 경로 수정. 패키지/클래스 이름 수정
mk3058 Aug 23, 2023
ffc3874
refactor(entity): 문자열 컬럼 길이 지정, 일부 생성자 값 검즘 추가
mk3058 Aug 23, 2023
3b13bba
refactor(dto): Request Dto protected 생성자 추가
mk3058 Aug 26, 2023
deb1214
refactor: domain계층이 presentation계층에 의존하지 않도록 수정
mk3058 Aug 26, 2023
a241e1a
fix(user): 유저의 나이가 20-30 범위로 제한되도록 수정
mk3058 Aug 27, 2023
b650a6e
refactor(dto): dto 이름 수정
mk3058 Aug 27, 2023
da54071
fix(User): 참조 타입에 대한 값 검증 추가
mk3058 Aug 27, 2023
34ce3d8
refactor(matchpost): 패키지 이름 수정
mk3058 Aug 27, 2023
37bfa4e
fix(User): 나이 검증 조건 수정
mk3058 Aug 27, 2023
65fdd5c
feat(chat): 기본 클래스 추가
mk3058 Sep 4, 2023
5746534
feat(college): 기본 클래스 추가
mk3058 Sep 4, 2023
6205617
feat(invite): 기본 클래스 추가
mk3058 Sep 4, 2023
2a734f1
feat(matchPost): 기본 클래스 추가
mk3058 Sep 4, 2023
2e41c43
feat(relation): 기본 클래스 추가
mk3058 Sep 4, 2023
26a257c
fix(matchPost): MatchServicePost 클래스를 순환 참조하던 문제 수정
mk3058 Sep 4, 2023
426437b
feat(tag): 기본 클래스 추가
mk3058 Sep 4, 2023
bffdf80
feat(user): 기본 클래스 추가
mk3058 Sep 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/main/java/com/sequence/anonymous/chat/domain/Chat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.sequence.anonymous.chat.domain;

import com.google.common.base.Preconditions;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import java.util.UUID;
import lombok.Getter;

@Entity
@Getter
public class Chat {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false, unique = true)
private UUID chatIdentifier;

protected Chat() {
}

public Chat(UUID chatIdentifier) {
Preconditions.checkArgument(chatIdentifier != null, "chatIdentifier must be provided");

this.id = null;
this.chatIdentifier = chatIdentifier;
}
}
42 changes: 42 additions & 0 deletions src/main/java/com/sequence/anonymous/college/domain/College.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.sequence.anonymous.college.domain;

import com.google.common.base.Preconditions;
import com.sequence.anonymous.college.domain.presentation.dto.CollegeUpdateDto;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Getter;
import org.springframework.data.geo.Point;

@Entity
@Getter
public class College {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false, unique = true)
private String name;

private Point location;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Point와 같은 Value Object를 사용하시려면 사용하는 엔티티 프로퍼티에 @Embedded를 달아주시고,
Point 클래스에 @Embeddable을 달아주셔야 합니다.


protected College() {
}

public College(String name, Point location) {
Preconditions.checkArgument(name != null, "name must be provided");
Preconditions.checkArgument(location != null, "location must be provided");

this.id = null;
this.name = name;
this.location = location;
}

public void updateName(CollegeUpdateDto dto) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domain layer는 presentation layer에 속한 dto에 의존하지 않는 것이 좋습니다!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래의 아티클을 확인해보시면 좋을 것 같습니다.
https://techblog.woowahan.com/2647

this.name = dto.getName();
this.location = dto.getLocation();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.sequence.anonymous.college.domain;

import com.google.common.base.Preconditions;
import com.sequence.anonymous.college.domain.presentation.dto.DepartmentUpdateDto;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Getter;

@Entity
@Getter
public class Department {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private String name;

@ManyToOne
@JoinColumn(name = "college_id")
private College college;

protected Department() {
}

public Department(String name, College college) {
Preconditions.checkArgument(name != null, "name must be provided");
Preconditions.checkArgument(college != null, "college must be provided");

this.id = null;
this.name = name;
this.college = college;
}

public void updateName(DepartmentUpdateDto dto) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domain layer는 presentation layer에 속한 dto에 의존하지 않는 것이 좋습니다!

this.name = dto.getName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sequence.anonymous.college.domain.presentation.dto;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presentation 패키지의 위치가 잘못된 것 같습니다!


import lombok.Getter;
import org.springframework.data.geo.Point;

@Getter
public class CollegeUpdateDto {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RequestDto는 유저의 request body를 매핑하는 용도로만 사용하기 때문에 다른 클래스에서 접근이 불가능하도록 public 생성자가 아닌 protected 생성자를 임의로 만들어주는 것이 좋습니다!


private String name;

private Point location;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.sequence.anonymous.college.domain.presentation.dto;

import java.awt.Point;
import lombok.Getter;

@Getter
public class DepartmentUpdateDto {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RequestDto는 유저의 request body를 매핑하는 용도로만 사용하기 때문에 다른 클래스에서 접근이 불가능하도록 public 생성자가 아닌 protected 생성자를 임의로 만들어주는 것이 좋습니다!


private String name;
}
26 changes: 26 additions & 0 deletions src/main/java/com/sequence/anonymous/common/BaseTimeEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.sequence.anonymous.common;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import java.time.LocalDate;
import java.time.LocalDateTime;
import lombok.Getter;
import org.springframework.context.event.EventListener;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseTimeEntity{

@CreatedDate
@Column(updatable = false)
private LocalDateTime createdAt;

@LastModifiedDate
private LocalDateTime updatedAt;
}
59 changes: 59 additions & 0 deletions src/main/java/com/sequence/anonymous/invite/domain/Invite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.sequence.anonymous.invite.domain;

import com.google.common.base.Preconditions;
import com.sequence.anonymous.invite.presentation.dto.InviteUpdateDto;
import com.sequence.anonymous.user.domain.User;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Getter;

@Entity
@Getter
public class Invite {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@JoinColumn(name = "inviter_id")
private User inviter;

@ManyToOne
@JoinColumn(name = "invitee_id")
private User invitee;

@Enumerated(EnumType.STRING)
private InviteStatus status;

@Enumerated(EnumType.STRING)
private InviteKind kind;

protected Invite() {
}

public Invite(User inviter, User invitee, InviteKind kind) {
this(inviter, invitee, kind, InviteStatus.WAIT);
}

private Invite(User inviter, User invitee, InviteKind kind, InviteStatus status) {
Preconditions.checkArgument(inviter != null, "inviter must be provided");
Preconditions.checkArgument(invitee != null, "invitee must be provided");
Preconditions.checkArgument(kind != null, "kind must be provided");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status에 대한 검증 로직도 추가해주시면 좋을 것 같습니다~

this.inviter = inviter;
this.invitee = invitee;
this.kind = kind;
this.status = status;
}

public void updateStatus(InviteUpdateDto dto) {
this.status = dto.getStatus();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.sequence.anonymous.invite.domain;

public enum InviteKind {
MATCH_POST, FRIEND
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.sequence.anonymous.invite.domain;

public enum InviteStatus {
WAIT, DONE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.sequence.anonymous.invite.presentation.dto;

import com.sequence.anonymous.invite.domain.InviteStatus;
import lombok.Getter;

@Getter
public class InviteUpdateDto {

private InviteStatus status;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.sequence.anonymous.matchPost.domain;

import com.fasterxml.jackson.databind.deser.DataFormatReaders.Match;
import com.google.common.base.Preconditions;
import com.sequence.anonymous.common.BaseTimeEntity;
import com.sequence.anonymous.matchPost.presentation.dto.MatchPostUpdateDto;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Getter;

@Entity
@Getter
public class MatchPost extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private String title;

@Column(columnDefinition = "TEXT", nullable = false)
private String introduce;

private String appeal;

@Enumerated(EnumType.STRING)
private MatchPostStatus status;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Column(length= <number>)를 통해 각 컬럼의 길이를 지정해주면 좋을 것 같습니다!


protected MatchPost() {
}

public MatchPost(String title, String introduce) {
this(title, introduce, "No Data");
}

public MatchPost(String title, String introduce, String appeal) {
this(null, title, introduce, appeal, MatchPostStatus.RECRUIT);
}

protected MatchPost(Long id, String title, String introduce, String appeal,
MatchPostStatus status) {
Preconditions.checkArgument(title != null, "title must be provided");
Preconditions.checkArgument(introduce != null, "introduce must be provided");

this.id = id;
this.title = title;
this.introduce = introduce;
this.appeal = appeal;
this.status = status;
}

public void updateMatchPost(MatchPostUpdateDto dto) {
this.title = dto.getTitle();
this.introduce = dto.getIntroduce();
this.appeal = dto.getAppeal();
this.status = dto.getStatus();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domain layer는 presentation layer에 속한 dto에 의존하지 않는 것이 좋습니다!

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.sequence.anonymous.matchPost.domain;

public enum MatchPostStatus {
RECRUIT, DONE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.sequence.anonymous.matchPost.presentation.dto;

import com.sequence.anonymous.matchPost.domain.MatchPostStatus;
import lombok.Getter;

@Getter
public class MatchPostUpdateDto {

private String title;

private String introduce;

private String appeal;

private MatchPostStatus status;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RequestDto는 유저의 request body를 매핑하는 용도로만 사용하기 때문에 다른 클래스에서 접근이 불가능하도록 public 생성자가 아닌 protected 생성자를 임의로 만들어주는 것이 좋습니다!

52 changes: 52 additions & 0 deletions src/main/java/com/sequence/anonymous/relation/domain/Relation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.sequence.anonymous.relation.domain;

import com.google.common.base.Preconditions;
import com.sequence.anonymous.invite.domain.InviteStatus;
import com.sequence.anonymous.relation.presentation.dto.RelationUpdateDto;
import com.sequence.anonymous.user.domain.User;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Getter;

@Entity
@Getter
public class Relation {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@JoinColumn(name = "user1_id")
private User user1;

@ManyToOne
@JoinColumn(name = "user2_id")
private User user2;

@Enumerated(EnumType.STRING)
private RelationStatus status;

protected Relation() {
}

public Relation(User user1, User user2, RelationStatus status) {
Preconditions.checkArgument(user1 != null, "user1 must be provided");
Preconditions.checkArgument(user2 != null, "user2 must be provided");
Preconditions.checkArgument(status != null, "status must be provided");

this.user1 = user1;
this.user2 = user2;
this.status = status;
}

public void updateStatus(RelationUpdateDto dto) {
this.status = dto.getStatus();
}
}
Loading