From 244afd2b39d523eb916dc9f461a114cce578994b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=97=88=EB=B3=B4=EC=84=B1?= Date: Sat, 2 Jul 2022 18:14:12 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20User=20=ED=85=8C=EC=9D=B4=EB=B8=94=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20(#18)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Feat] restdocs 관련 gradle 설정 추가 * [Feat] restdocs util 추가 * [Fix] restdocs 관련 gradle task 수정 * [Fix] openapi3 server 실행 프로필 따라 바뀌도록 설정 * [Feat] 유저 엔티티 작성 * [Fix] ActivityPart -> Activity, api 문서 주소 변경 --- bridge-api/src/main/resources/application.yml | 4 ++ .../src/main/java/ccc/common/Link.java | 19 +++++++ .../src/main/java/ccc/common/Photo.java | 5 ++ .../main/java/ccc/common/enums/Activity.java | 13 +++++ .../main/java/ccc/common/enums/LinkType.java | 7 +++ .../java/ccc/common/enums/MainActivity.java | 6 +++ .../src/main/java/ccc/user/Buddy.java | 19 +++++++ .../src/main/java/ccc/user/Profile.java | 52 +++++++++++++++++++ .../src/main/java/ccc/user/ProfileLink.java | 23 ++++++++ .../src/main/java/ccc/user/ProfilePhoto.java | 13 +++++ .../src/main/java/ccc/user/User.java | 41 +++++++++++++++ .../src/main/java/ccc/user/enums/Privacy.java | 6 +++ .../main/java/ccc/user/enums/UserStatus.java | 7 +++ .../src/main/resources/application-domain.yml | 25 +++++++++ .../src/main/resources/application.yml | 1 - build.gradle | 4 +- 16 files changed, 243 insertions(+), 2 deletions(-) create mode 100644 bridge-domain/src/main/java/ccc/common/Link.java create mode 100644 bridge-domain/src/main/java/ccc/common/Photo.java create mode 100644 bridge-domain/src/main/java/ccc/common/enums/Activity.java create mode 100644 bridge-domain/src/main/java/ccc/common/enums/LinkType.java create mode 100644 bridge-domain/src/main/java/ccc/common/enums/MainActivity.java create mode 100644 bridge-domain/src/main/java/ccc/user/Buddy.java create mode 100644 bridge-domain/src/main/java/ccc/user/Profile.java create mode 100644 bridge-domain/src/main/java/ccc/user/ProfileLink.java create mode 100644 bridge-domain/src/main/java/ccc/user/ProfilePhoto.java create mode 100644 bridge-domain/src/main/java/ccc/user/User.java create mode 100644 bridge-domain/src/main/java/ccc/user/enums/Privacy.java create mode 100644 bridge-domain/src/main/java/ccc/user/enums/UserStatus.java create mode 100644 bridge-domain/src/main/resources/application-domain.yml delete mode 100644 bridge-domain/src/main/resources/application.yml diff --git a/bridge-api/src/main/resources/application.yml b/bridge-api/src/main/resources/application.yml index ac155db9..b3bf12d2 100644 --- a/bridge-api/src/main/resources/application.yml +++ b/bridge-api/src/main/resources/application.yml @@ -1,3 +1,7 @@ +spring: + profiles: + include: domain + server: tomcat: basedir: . diff --git a/bridge-domain/src/main/java/ccc/common/Link.java b/bridge-domain/src/main/java/ccc/common/Link.java new file mode 100644 index 00000000..151ac023 --- /dev/null +++ b/bridge-domain/src/main/java/ccc/common/Link.java @@ -0,0 +1,19 @@ +package ccc.common; + +import ccc.common.enums.LinkType; + +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; + +@Embeddable +public class Link { + + @Column(name = "url") + private String url; + + @Column(name = "type") + @Enumerated(EnumType.STRING) + private LinkType type; +} diff --git a/bridge-domain/src/main/java/ccc/common/Photo.java b/bridge-domain/src/main/java/ccc/common/Photo.java new file mode 100644 index 00000000..e0cbd53a --- /dev/null +++ b/bridge-domain/src/main/java/ccc/common/Photo.java @@ -0,0 +1,5 @@ +package ccc.common; + + +public class Photo { +} diff --git a/bridge-domain/src/main/java/ccc/common/enums/Activity.java b/bridge-domain/src/main/java/ccc/common/enums/Activity.java new file mode 100644 index 00000000..8ed6d777 --- /dev/null +++ b/bridge-domain/src/main/java/ccc/common/enums/Activity.java @@ -0,0 +1,13 @@ +package ccc.common.enums; + +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public enum Activity { + + KPOP(MainActivity.음악), + 축구(MainActivity.운동); + + MainActivity mainActivity; +} + diff --git a/bridge-domain/src/main/java/ccc/common/enums/LinkType.java b/bridge-domain/src/main/java/ccc/common/enums/LinkType.java new file mode 100644 index 00000000..5c860ec1 --- /dev/null +++ b/bridge-domain/src/main/java/ccc/common/enums/LinkType.java @@ -0,0 +1,7 @@ +package ccc.common.enums; + +public enum LinkType { + YOUTUBE, + INSTAGRAM, + FACEBOOK +} diff --git a/bridge-domain/src/main/java/ccc/common/enums/MainActivity.java b/bridge-domain/src/main/java/ccc/common/enums/MainActivity.java new file mode 100644 index 00000000..12c6fef3 --- /dev/null +++ b/bridge-domain/src/main/java/ccc/common/enums/MainActivity.java @@ -0,0 +1,6 @@ +package ccc.common.enums; + +public enum MainActivity { + 음악, + 운동 +} diff --git a/bridge-domain/src/main/java/ccc/user/Buddy.java b/bridge-domain/src/main/java/ccc/user/Buddy.java new file mode 100644 index 00000000..50b6bbaf --- /dev/null +++ b/bridge-domain/src/main/java/ccc/user/Buddy.java @@ -0,0 +1,19 @@ +package ccc.user; + +import javax.persistence.*; + +import static javax.persistence.FetchType.LAZY; + +@Entity +public class Buddy { + @Id + private Long id; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "follower_id") + private Profile follower; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "followee_id") + private Profile followee; +} diff --git a/bridge-domain/src/main/java/ccc/user/Profile.java b/bridge-domain/src/main/java/ccc/user/Profile.java new file mode 100644 index 00000000..cdd19f04 --- /dev/null +++ b/bridge-domain/src/main/java/ccc/user/Profile.java @@ -0,0 +1,52 @@ +package ccc.user; + +import ccc.common.enums.Activity; +import ccc.user.enums.Privacy; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +import static javax.persistence.FetchType.LAZY; + +@Entity +@Table(name = "profile") +public class Profile { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "profile_id") + private Long id; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "user_id") + private User user; + + @Column(name = "nickname", unique = true, nullable = false) + private String nickname; // 닉네임 + + @Column(name = "link", unique = true, nullable = false) + private String link; // 프로필 링크 + + @Column(name = "privacy") + @Enumerated(EnumType.STRING) + private Privacy privacy; + + @OneToOne + @JoinColumn(name = "profile_photo_id") + private ProfilePhoto profilePhoto; + + @ElementCollection + @Enumerated(EnumType.STRING) + private List keywords = new ArrayList<>(); // 나를 나타내는 키워드 목록 + + @OneToMany(mappedBy = "follower", fetch = LAZY) + private List followers = new ArrayList<>(); // 내가 팔로우하는 사람들 + + @OneToMany(mappedBy = "followee", fetch = LAZY) + private List followees = new ArrayList<>(); // 나를 팔로우하는 사람들 + + @OneToMany(mappedBy = "profile", fetch = LAZY) + private List socialLinks = new ArrayList<>(); + +} diff --git a/bridge-domain/src/main/java/ccc/user/ProfileLink.java b/bridge-domain/src/main/java/ccc/user/ProfileLink.java new file mode 100644 index 00000000..ca2d089d --- /dev/null +++ b/bridge-domain/src/main/java/ccc/user/ProfileLink.java @@ -0,0 +1,23 @@ +package ccc.user; + +import ccc.common.Link; +import javax.persistence.*; + +import static javax.persistence.FetchType.LAZY; + +@Entity +@Table(name = "profile_link") +public class ProfileLink { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "link_id") + private Long id; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "profile_id") + private Profile profile; + + @Embedded + private Link link; +} diff --git a/bridge-domain/src/main/java/ccc/user/ProfilePhoto.java b/bridge-domain/src/main/java/ccc/user/ProfilePhoto.java new file mode 100644 index 00000000..4678bfa4 --- /dev/null +++ b/bridge-domain/src/main/java/ccc/user/ProfilePhoto.java @@ -0,0 +1,13 @@ +package ccc.user; + +import javax.persistence.*; + +@Entity +@Table(name = "profile_photo") +public class ProfilePhoto { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "profile_photo_id") + private Long id; +} diff --git a/bridge-domain/src/main/java/ccc/user/User.java b/bridge-domain/src/main/java/ccc/user/User.java new file mode 100644 index 00000000..67375be2 --- /dev/null +++ b/bridge-domain/src/main/java/ccc/user/User.java @@ -0,0 +1,41 @@ +package ccc.user; + +import ccc.user.enums.UserStatus; + +import javax.persistence.*; +import java.util.List; + +import static javax.persistence.FetchType.LAZY; + +@Entity +@Table(name = "user") +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_id") + private Long id; + + @Column(name = "email", unique = true) + private String email; // 아이디 + + @Column(name = "password") + private String password; // 비밀번호 + + @Column(name = "phone_number", unique = true) + private String phoneNumber; // 휴대전화 번호 + + //FIXME +// @Column(name = "role") +// @ElementCollection +// @Enumerated(EnumType.STRING) +// private List role; // ~~~/profile/{닉네임} + + @OneToMany(mappedBy = "user", fetch = LAZY) + private List profiles; + + @Enumerated(EnumType.STRING) + @Column(name = "status") + private UserStatus status; +} + diff --git a/bridge-domain/src/main/java/ccc/user/enums/Privacy.java b/bridge-domain/src/main/java/ccc/user/enums/Privacy.java new file mode 100644 index 00000000..c7ee8c1d --- /dev/null +++ b/bridge-domain/src/main/java/ccc/user/enums/Privacy.java @@ -0,0 +1,6 @@ +package ccc.user.enums; + +public enum Privacy { + PUBLIC, + PRIVATE +} diff --git a/bridge-domain/src/main/java/ccc/user/enums/UserStatus.java b/bridge-domain/src/main/java/ccc/user/enums/UserStatus.java new file mode 100644 index 00000000..2ee0e499 --- /dev/null +++ b/bridge-domain/src/main/java/ccc/user/enums/UserStatus.java @@ -0,0 +1,7 @@ +package ccc.user.enums; + +public enum UserStatus { + ACTIVE, + INACTIVE, + BLOCKED +} diff --git a/bridge-domain/src/main/resources/application-domain.yml b/bridge-domain/src/main/resources/application-domain.yml new file mode 100644 index 00000000..620ff848 --- /dev/null +++ b/bridge-domain/src/main/resources/application-domain.yml @@ -0,0 +1,25 @@ +spring: + config: + activate: + on-profile: local + + datasource: + url: jdbc:mysql://localhost:3306/cap2_db + username: cs + password: cs + + jpa: + hibernate: + ddl-auto: none + show-sql: true + open-in-view: false + properties: + hibernate.default_batch_fetch_size: 1000 + + +--- + +spring: + config: + activate: + on-profile: dev diff --git a/bridge-domain/src/main/resources/application.yml b/bridge-domain/src/main/resources/application.yml deleted file mode 100644 index 8b137891..00000000 --- a/bridge-domain/src/main/resources/application.yml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/build.gradle b/build.gradle index 82c205c3..3fe286c5 100644 --- a/build.gradle +++ b/build.gradle @@ -98,6 +98,8 @@ project(':bridge-domain') { dependencies { implementation project(path: ':bridge-infra', configuration: 'default') + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'mysql:mysql-connector-java' // todo ::jpa, redis import } } @@ -139,7 +141,7 @@ project(':bridge-api') { openapi3 { ext { local = 'http://localhost:8080' - dev = 'http://3.39.100.45:8080' + dev = 'https://api-keewe.com' } def active = System.properties.getOrDefault('spring.profiles.active', 'local')