Skip to content
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

[Feat] User 테이블 작성 #18

Merged
merged 7 commits into from
Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions bridge-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
spring:
profiles:
include: domain

server:
tomcat:
basedir: .
Expand Down
19 changes: 19 additions & 0 deletions bridge-domain/src/main/java/ccc/common/Link.java
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 5 additions & 0 deletions bridge-domain/src/main/java/ccc/common/Photo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ccc.common;


public class Photo {
}
13 changes: 13 additions & 0 deletions bridge-domain/src/main/java/ccc/common/enums/Activity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ccc.common.enums;

import lombok.AllArgsConstructor;

@AllArgsConstructor
public enum Activity {

KPOP(MainActivity.음악),
축구(MainActivity.운동);

MainActivity mainActivity;
}

7 changes: 7 additions & 0 deletions bridge-domain/src/main/java/ccc/common/enums/LinkType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ccc.common.enums;

public enum LinkType {
YOUTUBE,
INSTAGRAM,
FACEBOOK
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ccc.common.enums;

public enum MainActivity {
음악,
운동
}
19 changes: 19 additions & 0 deletions bridge-domain/src/main/java/ccc/user/Buddy.java
Original file line number Diff line number Diff line change
@@ -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;
}
52 changes: 52 additions & 0 deletions bridge-domain/src/main/java/ccc/user/Profile.java
Original file line number Diff line number Diff line change
@@ -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<Activity> keywords = new ArrayList<>(); // 나를 나타내는 키워드 목록

@OneToMany(mappedBy = "follower", fetch = LAZY)
private List<Buddy> followers = new ArrayList<>(); // 내가 팔로우하는 사람들

@OneToMany(mappedBy = "followee", fetch = LAZY)
private List<Buddy> followees = new ArrayList<>(); // 나를 팔로우하는 사람들

@OneToMany(mappedBy = "profile", fetch = LAZY)
private List<ProfileLink> socialLinks = new ArrayList<>();

}
23 changes: 23 additions & 0 deletions bridge-domain/src/main/java/ccc/user/ProfileLink.java
Original file line number Diff line number Diff line change
@@ -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;
}
13 changes: 13 additions & 0 deletions bridge-domain/src/main/java/ccc/user/ProfilePhoto.java
Original file line number Diff line number Diff line change
@@ -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;
}
41 changes: 41 additions & 0 deletions bridge-domain/src/main/java/ccc/user/User.java
Original file line number Diff line number Diff line change
@@ -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<UserRole> role; // ~~~/profile/{닉네임}

@OneToMany(mappedBy = "user", fetch = LAZY)
private List<Profile> profiles;

@Enumerated(EnumType.STRING)
@Column(name = "status")
private UserStatus status;
}

6 changes: 6 additions & 0 deletions bridge-domain/src/main/java/ccc/user/enums/Privacy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ccc.user.enums;

public enum Privacy {
PUBLIC,
PRIVATE
}
7 changes: 7 additions & 0 deletions bridge-domain/src/main/java/ccc/user/enums/UserStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ccc.user.enums;

public enum UserStatus {
ACTIVE,
INACTIVE,
BLOCKED
}
25 changes: 25 additions & 0 deletions bridge-domain/src/main/resources/application-domain.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion bridge-domain/src/main/resources/application.yml

This file was deleted.

4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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')
Expand Down