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: entity skeleton structure #9

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b405e90
add: Profile Entity (#8)
toychip Jun 19, 2024
b4a09d0
add: Member Entity (#8)
toychip Jun 19, 2024
2a4c511
add: Profile Entity init constructor (#8)
toychip Jun 19, 2024
dd7c8f6
add: Question Entity (#8)
toychip Jun 19, 2024
080fcd9
add: Pick Entity (#8)
toychip Jun 19, 2024
639d350
add: bidirectional mapping between Member, Question, and Pick entitie…
toychip Jun 19, 2024
6a6e0e8
add: Notification Entity (#8)
toychip Jun 19, 2024
ab8cd95
fix: Change BaseEntity field access from private to protected (#8)
toychip Jun 19, 2024
d397fb0
refactor: Simplify entities with allOpen and noArg dependencies (#8)
toychip Jun 19, 2024
01d461c
refactor: Split application-entity.yml into local and prod configurat…
toychip Jun 19, 2024
5beaf90
feat: V1 dev, prod ddl (#8)
toychip Jun 19, 2024
205cf7d
refactor: Rename part field to platform (#8)
toychip Jun 19, 2024
6a66114
refactor: Change default point value in Member class to constant (#8)
toychip Jun 21, 2024
b1b93fe
add: Profile Entity (#8)
toychip Jun 19, 2024
ab7dd36
add: Member Entity (#8)
toychip Jun 19, 2024
01bfff2
add: Profile Entity init constructor (#8)
toychip Jun 19, 2024
25bac78
add: Question Entity (#8)
toychip Jun 19, 2024
e50f3a3
add: Pick Entity (#8)
toychip Jun 19, 2024
8b44143
add: bidirectional mapping between Member, Question, and Pick entitie…
toychip Jun 19, 2024
38578e4
add: Notification Entity (#8)
toychip Jun 19, 2024
8d7627e
fix: Change BaseEntity field access from private to protected (#8)
toychip Jun 19, 2024
738ed5e
refactor: Simplify entities with allOpen and noArg dependencies (#8)
toychip Jun 19, 2024
450e8ad
refactor: Split application-entity.yml into local and prod configurat…
toychip Jun 19, 2024
5f9a4a4
feat: V1 dev, prod ddl (#8)
toychip Jun 19, 2024
02cb043
refactor: Rename part field to platform (#8)
toychip Jun 19, 2024
9673d14
refactor: Change default point value in Member class to constant (#8)
toychip Jun 21, 2024
0b85952
Merge remote-tracking branch 'origin/junhyoung/AddEntity' into junhyo…
toychip Jul 5, 2024
e76d28d
feat: add findByValue method to Platform and Gender enums
toychip Jul 5, 2024
d125460
refactor: remove unused entities and enums
toychip Jul 5, 2024
d5fc2dd
refactor: add 'Entity' suffix to Member, Pick, and Question entities
toychip Jul 5, 2024
db9b472
refactor: replace constructor with factory method in MemberEntity
toychip Jul 5, 2024
d64789f
refactor: Move enum validation to domain layer and update MemberEntity
toychip Jul 7, 2024
2d11792
refactor: Embed enums into MemberEntity and remove external enum classes
toychip Jul 7, 2024
a0760a4
refactor: Update MemberEntity to directly use enums and adjust servic…
toychip Jul 7, 2024
b51d59b
fix: Update foreign key references and database schema
toychip Jul 7, 2024
1b246da
refactor: ktlint format
toychip Jul 7, 2024
6b18811
feat: MemberRelationEntity * MemberEntity mapping
toychip Jul 27, 2024
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
14 changes: 12 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ project(":entity") {

dependencies {
api("org.springframework.boot:spring-boot-starter-data-jpa")
api("com.mysql:mysql-connector-j:${properties["mysqlConnectorVersion"]}")
runtimeOnly("com.h2database:h2:${properties["h2DatabaseVersion"]}") // todo : fade out
runtimeOnly("com.mysql:mysql-connector-j:${properties["mysqlConnectorVersion"]}")
// runtimeOnly("com.h2database:h2:${properties["h2DatabaseVersion"]}") // todo : fade out

// Jasypt
implementation("com.github.ulisesbocchio:jasypt-spring-boot-starter:${properties["jasyptSpringBootStarterVersion"]}")
Expand All @@ -105,6 +105,16 @@ project(":entity") {
// query κ°’ μ •λ ¬
implementation("com.github.gavlyukovskiy:p6spy-spring-boot-starter:${properties["p6spyVersion"]}")
}

allOpen {
annotation("jakarta.persistence.Entity")
annotation("jakarta.persistence.Embeddable")
annotation("jakarta.persistence.MappedSuperclass")
}

noArg {
annotation("jakarta.persistence.Entity")
}
}

project(":common") {
Expand Down
10 changes: 5 additions & 5 deletions entity/src/main/kotlin/com/mashup/dojo/base/BaseEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener
abstract class BaseEntity : BaseTimeEntity() {
@CreatedBy
@Column(updatable = false)
var createdBy: String? = null
private set
lateinit var createdBy: String
protected set

@LastModifiedBy
var lastModifiedBy: String? = null
private set
lateinit var lastModifiedBy: String
protected set

@Column(nullable = false)
var isDeleted: Boolean = false
private set
protected set

// μž¬ν™œμ„±ν™” - soft delete
fun activate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ abstract class BaseTimeEntity {
@CreatedDate
@Column(name = "created_at", nullable = false, updatable = false)
lateinit var createdAt: LocalDateTime
private set
protected set

@LastModifiedDate
@Column(name = "updated_at", nullable = false)
lateinit var updatedAt: LocalDateTime
private set
protected set
}
6 changes: 6 additions & 0 deletions entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.mashup.dojo.member

enum class Gender {
MALE,
FEMALE,
}
54 changes: 54 additions & 0 deletions entity/src/main/kotlin/com/mashup/dojo/member/Member.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.mashup.dojo.member

import com.mashup.dojo.base.BaseTimeEntity
import com.mashup.dojo.pick.Pick
import com.mashup.dojo.profile.Profile
import jakarta.persistence.CascadeType
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.OneToMany
import jakarta.persistence.OneToOne
import jakarta.persistence.Table

@Entity
@Table(name = "member")
class Member(
@Column(name = "name", nullable = false)
val name: String,
@Enumerated(EnumType.STRING)
@Column(name = "platform", nullable = false)
val platform: Platform,
@Enumerated(EnumType.STRING)
@Column(name = "gender", nullable = false)
val gender: Gender,
point: Int = 200,
xonmin marked this conversation as resolved.
Show resolved Hide resolved
@Column(name = "generation", nullable = false)
val generation: Int,
@OneToOne(mappedBy = "member")
val profile: Profile? = null,
@OneToMany(mappedBy = "fromMember", cascade = [CascadeType.ALL], orphanRemoval = true)
val fromPicks: MutableList<Pick> = mutableListOf(),
@OneToMany(mappedBy = "toMember", cascade = [CascadeType.ALL], orphanRemoval = true)
val toPicks: MutableList<Pick> = mutableListOf(),
) : BaseTimeEntity() {
@Column(name = "point", nullable = false)
var point: Int = point
protected set

fun updatePoint(newPoint: Int) {
this.point = newPoint
}

companion object {
fun createMember(
name: String,
platform: Platform,
gender: Gender,
generation: Int,
): Member {
return Member(name, platform, gender, 200, generation)
}
}
}
9 changes: 9 additions & 0 deletions entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mashup.dojo.member

enum class Platform {
PRODUCT_DESIGN,
WEB,
IOS,
ANDROID,
SPRING,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mashup.dojo.notification

import com.mashup.dojo.base.BaseTimeEntity
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Table

@Entity
@Table(name = "notification")
class Notification(
Copy link
Member

Choose a reason for hiding this comment

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

ν•΄λ‹Ή ν΄λž˜μŠ€λŠ” id ν•„λ“œ ν•„μš” μ—†λŠ” κ²ƒμΌκΉŒμš”?!

Copy link
Member Author

Choose a reason for hiding this comment

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

μˆ˜μ •ν•΄μ„œ λ°˜μ˜ν–ˆμŠ΅λ‹ˆλ‹€!

@Column(name = "title", nullable = false)
val title: String,
@Column(name = "content", nullable = false)
val content: String,
@Column(name = "topic", nullable = false)
val topic: String,
@Column(name = "send_status", nullable = false)
var sendStatus: Boolean,
) : BaseTimeEntity()
24 changes: 24 additions & 0 deletions entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mashup.dojo.pick

import com.mashup.dojo.base.BaseTimeEntity
import com.mashup.dojo.member.Member
import com.mashup.dojo.question.Question
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table

@Entity
@Table(name = "pick")
class Pick(
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "question_id")
val question: Question,
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "from_member_id")
val fromMember: Member,
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "to_member_id")
val toMember: Member,
) : BaseTimeEntity()
27 changes: 27 additions & 0 deletions entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.mashup.dojo.profile

import com.mashup.dojo.base.BaseEntity
import com.mashup.dojo.member.Member
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.JoinColumn
import jakarta.persistence.OneToOne
import jakarta.persistence.Table

@Entity
@Table(name = "profile")
class Profile(
imageUrl: String,
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
var member: Member,
) : BaseEntity() {
@Column(name = "image_url", nullable = false)
var imageUrl: String = imageUrl
protected set

fun updateImageUrl(newImageUrl: String) {
this.imageUrl = newImageUrl
}
}
32 changes: 32 additions & 0 deletions entity/src/main/kotlin/com/mashup/dojo/question/Question.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.mashup.dojo.question

import com.mashup.dojo.base.BaseTimeEntity
import com.mashup.dojo.pick.Pick
import jakarta.persistence.CascadeType
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.OneToMany
import jakarta.persistence.Table

@Entity
@Table(name = "question")
class Question(
@Column(name = "content", nullable = false)
var content: String,
@Enumerated(EnumType.STRING)
@Column(name = "target", nullable = false)
var target: Target,
@OneToMany(mappedBy = "question", cascade = [CascadeType.ALL], orphanRemoval = true)
var picks: MutableList<Pick> = mutableListOf(),
) : BaseTimeEntity() {
companion object {
fun createQuestion(
content: String,
target: Target,
): Question {
return Question(content, target)
}
}
}
7 changes: 7 additions & 0 deletions entity/src/main/kotlin/com/mashup/dojo/question/Target.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.mashup.dojo.question

enum class Target {
FRIEND, // 지인
STRANGER, // λ‚―μ„  μ‚¬λžŒ
EITHER,
}
19 changes: 19 additions & 0 deletions entity/src/main/resources/application-entity-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
spring:
datasource:
url: ENC(i+u914ZiotX9OZ2gFuRg+4+CpIK142QN/KuzoMmvPz8wHrvSO9ow1F8hwlD9WY1O29WITufUjEL2zAKZJv0wTNk8+19/cJgYj4F7b0H4bjVlNVuslh7FMMIJ/zgZst5o)
username: ENC(WS0DuwNzN19hZCDcpeK0ptXS6Gv3CowQNfwGQ4A3byU=)
password: ENC(ozxs8iZBHjljszbq6/y3cVt5Xt1Z8Nj6qh6gPobhs9A=)
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
show-sql: true
hibernate:
ddl-auto: validate
properties:
hibernate:
default_batch_fetch_size: 200
dialect: org.hibernate.dialect.MySQL8Dialect
format_sql: true

jasypt:
encryptor:
password: ${JASYPT_ENCRYPTOR_PASSWORD}
19 changes: 19 additions & 0 deletions entity/src/main/resources/application-entity-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
spring:
datasource:
url: ENC(CptY28rV7YQickOOUYd5VOkKCv3ZMixjof2NFt51FtNrW+jmXEnpZDA/wv+f+RxdjmQK4zaN8QEOzkLh0/jloIOCGaTZ76tn+4yt5Tco4IKAtEa1esVaA9je39bWdWyj)
username: ENC(WS0DuwNzN19hZCDcpeK0ptXS6Gv3CowQNfwGQ4A3byU=)
password: ENC(ozxs8iZBHjljszbq6/y3cVt5Xt1Z8Nj6qh6gPobhs9A=)
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
show-sql: true
hibernate:
ddl-auto: validate
properties:
hibernate:
default_batch_fetch_size: 200
dialect: org.hibernate.dialect.MySQL8Dialect
format_sql: true

jasypt:
encryptor:
password: ${JASYPT_ENCRYPTOR_PASSWORD}
16 changes: 0 additions & 16 deletions entity/src/main/resources/application-entity.yaml

This file was deleted.

58 changes: 58 additions & 0 deletions entity/src/main/resources/ddl/V1ddl-dev.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
CREATE TABLE dojo_dev.question
(
created_at DATETIME(6) NOT NULL,
id BIGINT NOT NULL AUTO_INCREMENT,
updated_at DATETIME(6) NOT NULL,
content VARCHAR(255) NOT NULL,
target ENUM('EITHER','FRIEND','STRANGER') NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB;

CREATE TABLE dojo_dev.profile
(
is_deleted BIT NOT NULL,
created_at DATETIME(6) NOT NULL,
id BIGINT NOT NULL AUTO_INCREMENT,
member_id BIGINT,
updated_at DATETIME(6) NOT NULL,
created_by VARCHAR(255),
image_url VARCHAR(255) NOT NULL,
last_modified_by VARCHAR(255),
PRIMARY KEY (id)
) ENGINE=InnoDB;

CREATE TABLE dojo_dev.pick
(
created_at DATETIME(6) NOT NULL,
from_member_id BIGINT,
id BIGINT NOT NULL AUTO_INCREMENT,
question_id BIGINT,
to_member_id BIGINT,
updated_at DATETIME(6) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB;

CREATE TABLE dojo_dev.notification
(
send_status BIT NOT NULL,
created_at DATETIME(6) NOT NULL,
id BIGINT NOT NULL AUTO_INCREMENT,
updated_at DATETIME(6) NOT NULL,
content VARCHAR(255) NOT NULL,
title VARCHAR(255) NOT NULL,
topic VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB;

CREATE TABLE dojo_dev.member
(
generation INT NOT NULL,
point INT NOT NULL,
created_at DATETIME(6) NOT NULL,
id BIGINT NOT NULL AUTO_INCREMENT,
updated_at DATETIME(6) NOT NULL,
name VARCHAR(255) NOT NULL,
gender ENUM('FEMALE','MALE') NOT NULL,
platform ENUM('ANDROID','IOS','PRODUCT_DESIGN','SPRING','WEB') NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB;
Loading
Loading