From b405e9028b2d193b10a97a77d1a38be3b435d1d7 Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 00:02:51 +0900 Subject: [PATCH 01/36] add: Profile Entity (#8) --- .../kotlin/com/mashup/dojo/profile/Profile.kt | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt diff --git a/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt b/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt new file mode 100644 index 00000000..06bc9fd0 --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt @@ -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 + private set + + fun updateImageUrl(newImageUrl: String) { + this.imageUrl = newImageUrl + } +} From b4a09d0371467b305c3b3ece0f7a3e672b80aeea Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 00:03:08 +0900 Subject: [PATCH 02/36] add: Member Entity (#8) --- .../kotlin/com/mashup/dojo/member/Gender.kt | 6 +++ .../kotlin/com/mashup/dojo/member/Member.kt | 47 +++++++++++++++++++ .../kotlin/com/mashup/dojo/member/Part.kt | 9 ++++ 3 files changed, 62 insertions(+) create mode 100644 entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt create mode 100644 entity/src/main/kotlin/com/mashup/dojo/member/Member.kt create mode 100644 entity/src/main/kotlin/com/mashup/dojo/member/Part.kt diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt new file mode 100644 index 00000000..184c90fe --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt @@ -0,0 +1,6 @@ +package com.mashup.dojo.member + +enum class Gender { + MALE, + FEMALE, +} diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt new file mode 100644 index 00000000..04d6f7d6 --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt @@ -0,0 +1,47 @@ +package com.mashup.dojo.member + +import com.mashup.dojo.base.BaseTimeEntity +import com.mashup.dojo.profile.Profile +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.OneToOne +import jakarta.persistence.Table + +@Entity +@Table(name = "member") +open class Member protected constructor( + @Column(name = "name", nullable = false) + val name: String, + @Enumerated(EnumType.STRING) + @Column(name = "part", nullable = false) + val part: Part, + @Enumerated(EnumType.STRING) + @Column(name = "gender", nullable = false) + val gender: Gender, + point: Int = 200, + @Column(name = "generation", nullable = false) + val generation: Int, + @OneToOne(mappedBy = "member") + val profile: Profile? = null, +) : BaseTimeEntity() { + @Column(name = "point", nullable = false) + var point: Int = point + private set + + fun updatePoint(newPoint: Int) { + this.point = newPoint + } + + companion object { + fun createMember( + name: String, + part: Part, + gender: Gender, + generation: Int, + ): Member { + return Member(name, part, gender, 200, generation) + } + } +} diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Part.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Part.kt new file mode 100644 index 00000000..ff1f890d --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Part.kt @@ -0,0 +1,9 @@ +package com.mashup.dojo.member + +enum class Part { + PRODUCT_DESIGN, + WEB, + IOS, + ANDROID, + SPRING, +} From 2a4c51110f18e62ea717444f571de349db9f759a Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 00:09:11 +0900 Subject: [PATCH 03/36] add: Profile Entity init constructor (#8) --- entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt b/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt index 06bc9fd0..aa5f6872 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt @@ -11,7 +11,7 @@ import jakarta.persistence.Table @Entity @Table(name = "profile") -class Profile( +open class Profile protected constructor( imageUrl: String, @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") From dd7c8f6be260a1d5cd7789414f7c56eb66e74ded Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 00:09:37 +0900 Subject: [PATCH 04/36] add: Question Entity (#8) --- .../com/mashup/dojo/question/Question.kt | 28 +++++++++++++++++++ .../kotlin/com/mashup/dojo/question/Target.kt | 7 +++++ 2 files changed, 35 insertions(+) create mode 100644 entity/src/main/kotlin/com/mashup/dojo/question/Question.kt create mode 100644 entity/src/main/kotlin/com/mashup/dojo/question/Target.kt diff --git a/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt b/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt new file mode 100644 index 00000000..42f2fa23 --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt @@ -0,0 +1,28 @@ +package com.mashup.dojo.question + +import com.mashup.dojo.base.BaseTimeEntity +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.Table + +@Entity +@Table(name = "question") +open class Question protected constructor( + + @Column(name = "content", nullable = false) + var content: String, + + @Enumerated(EnumType.STRING) + @Column(name = "target", nullable = false) + var target: Target + +) : BaseTimeEntity() { + + companion object { + fun createQuestion(content: String, target: Target): Question { + return Question(content, target) + } + } +} diff --git a/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt b/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt new file mode 100644 index 00000000..8799f125 --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt @@ -0,0 +1,7 @@ +package com.mashup.dojo.question + +enum class Target { + FRIEND, // 지인 + STRANGER, // 낯선 사람 + EITHER +} From 080fcd982d29a56d9e0daf1d12404171c12453ee Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 00:25:43 +0900 Subject: [PATCH 05/36] add: Pick Entity (#8) --- .../main/kotlin/com/mashup/dojo/pick/Pick.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt diff --git a/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt b/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt new file mode 100644 index 00000000..38d1d81b --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt @@ -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") +open class Pick protected constructor( + @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() From 639d350f195c41d4b561e483534cbf72e87ec58b Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 00:28:19 +0900 Subject: [PATCH 06/36] add: bidirectional mapping between Member, Question, and Pick entities (#8) --- .../main/kotlin/com/mashup/dojo/member/Member.kt | 7 +++++++ .../kotlin/com/mashup/dojo/question/Question.kt | 16 ++++++++++------ .../kotlin/com/mashup/dojo/question/Target.kt | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt index 04d6f7d6..3aee1727 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt @@ -1,11 +1,14 @@ 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 @@ -25,6 +28,10 @@ open class Member protected constructor( val generation: Int, @OneToOne(mappedBy = "member") val profile: Profile? = null, + @OneToMany(mappedBy = "fromMember", cascade = [CascadeType.ALL], orphanRemoval = true) + val fromPicks: MutableList = mutableListOf(), + @OneToMany(mappedBy = "toMember", cascade = [CascadeType.ALL], orphanRemoval = true) + val toPicks: MutableList = mutableListOf(), ) : BaseTimeEntity() { @Column(name = "point", nullable = false) var point: Int = point diff --git a/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt b/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt index 42f2fa23..abde1f6f 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt @@ -1,27 +1,31 @@ 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") open class Question protected constructor( - @Column(name = "content", nullable = false) var content: String, - @Enumerated(EnumType.STRING) @Column(name = "target", nullable = false) - var target: Target - + var target: Target, + @OneToMany(mappedBy = "question", cascade = [CascadeType.ALL], orphanRemoval = true) + var picks: MutableList = mutableListOf(), ) : BaseTimeEntity() { - companion object { - fun createQuestion(content: String, target: Target): Question { + fun createQuestion( + content: String, + target: Target, + ): Question { return Question(content, target) } } diff --git a/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt b/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt index 8799f125..19b0c96e 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt @@ -3,5 +3,5 @@ package com.mashup.dojo.question enum class Target { FRIEND, // 지인 STRANGER, // 낯선 사람 - EITHER + EITHER, } From 6a6e0e86bbfda9b25e39a15a5957a1e9406e3eed Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 00:31:56 +0900 Subject: [PATCH 07/36] add: Notification Entity (#8) --- .../mashup/dojo/notification/Notification.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt diff --git a/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt b/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt new file mode 100644 index 00000000..6582e7ee --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt @@ -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") +open class Notification protected constructor( + @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() From ab8cd95086d6351491f55d5e504e74f4eb95ad7c Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 03:08:04 +0900 Subject: [PATCH 08/36] fix: Change BaseEntity field access from private to protected (#8) --- .../src/main/kotlin/com/mashup/dojo/base/BaseEntity.kt | 10 +++++----- .../main/kotlin/com/mashup/dojo/base/BaseTimeEntity.kt | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/entity/src/main/kotlin/com/mashup/dojo/base/BaseEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/base/BaseEntity.kt index 83f015a2..46a15649 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/base/BaseEntity.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/base/BaseEntity.kt @@ -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() { diff --git a/entity/src/main/kotlin/com/mashup/dojo/base/BaseTimeEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/base/BaseTimeEntity.kt index b5392aed..649668ac 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/base/BaseTimeEntity.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/base/BaseTimeEntity.kt @@ -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 } From d397fb0b910bcb5d63d8112932a447eddfd14781 Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 03:11:13 +0900 Subject: [PATCH 09/36] refactor: Simplify entities with allOpen and noArg dependencies (#8) --- build.gradle.kts | 14 ++++++++++++-- .../main/kotlin/com/mashup/dojo/member/Member.kt | 4 ++-- .../com/mashup/dojo/notification/Notification.kt | 2 +- .../src/main/kotlin/com/mashup/dojo/pick/Pick.kt | 2 +- .../main/kotlin/com/mashup/dojo/profile/Profile.kt | 4 ++-- .../kotlin/com/mashup/dojo/question/Question.kt | 2 +- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index bf942ace..ddc592a6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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"]}") @@ -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") { diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt index 3aee1727..5f379e98 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt @@ -14,7 +14,7 @@ import jakarta.persistence.Table @Entity @Table(name = "member") -open class Member protected constructor( +class Member( @Column(name = "name", nullable = false) val name: String, @Enumerated(EnumType.STRING) @@ -35,7 +35,7 @@ open class Member protected constructor( ) : BaseTimeEntity() { @Column(name = "point", nullable = false) var point: Int = point - private set + protected set fun updatePoint(newPoint: Int) { this.point = newPoint diff --git a/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt b/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt index 6582e7ee..8beb840a 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt @@ -7,7 +7,7 @@ import jakarta.persistence.Table @Entity @Table(name = "notification") -open class Notification protected constructor( +class Notification( @Column(name = "title", nullable = false) val title: String, @Column(name = "content", nullable = false) diff --git a/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt b/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt index 38d1d81b..7b8a3db5 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt @@ -11,7 +11,7 @@ import jakarta.persistence.Table @Entity @Table(name = "pick") -open class Pick protected constructor( +class Pick( @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "question_id") val question: Question, diff --git a/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt b/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt index aa5f6872..0eb1edc6 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt @@ -11,7 +11,7 @@ import jakarta.persistence.Table @Entity @Table(name = "profile") -open class Profile protected constructor( +class Profile( imageUrl: String, @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") @@ -19,7 +19,7 @@ open class Profile protected constructor( ) : BaseEntity() { @Column(name = "image_url", nullable = false) var imageUrl: String = imageUrl - private set + protected set fun updateImageUrl(newImageUrl: String) { this.imageUrl = newImageUrl diff --git a/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt b/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt index abde1f6f..5409d3be 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt @@ -12,7 +12,7 @@ import jakarta.persistence.Table @Entity @Table(name = "question") -open class Question protected constructor( +class Question( @Column(name = "content", nullable = false) var content: String, @Enumerated(EnumType.STRING) From 01d461ce12dac1b747387974d40bd8236fee1b0e Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 03:12:29 +0900 Subject: [PATCH 10/36] refactor: Split application-entity.yml into local and prod configurations (#8) --- .../resources/application-entity-local.yml | 19 +++++++++++++++++++ .../resources/application-entity-prod.yml | 19 +++++++++++++++++++ .../main/resources/application-entity.yaml | 16 ---------------- 3 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 entity/src/main/resources/application-entity-local.yml create mode 100644 entity/src/main/resources/application-entity-prod.yml delete mode 100644 entity/src/main/resources/application-entity.yaml diff --git a/entity/src/main/resources/application-entity-local.yml b/entity/src/main/resources/application-entity-local.yml new file mode 100644 index 00000000..9c3b02a7 --- /dev/null +++ b/entity/src/main/resources/application-entity-local.yml @@ -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: create + properties: + hibernate: + default_batch_fetch_size: 200 + dialect: org.hibernate.dialect.MySQL8Dialect + format_sql: true + +jasypt: + encryptor: + password: ${JASYPT_ENCRYPTOR_PASSWORD} diff --git a/entity/src/main/resources/application-entity-prod.yml b/entity/src/main/resources/application-entity-prod.yml new file mode 100644 index 00000000..bc9a5451 --- /dev/null +++ b/entity/src/main/resources/application-entity-prod.yml @@ -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: create + properties: + hibernate: + default_batch_fetch_size: 200 + dialect: org.hibernate.dialect.MySQL8Dialect + format_sql: true + +jasypt: + encryptor: + password: ${JASYPT_ENCRYPTOR_PASSWORD} diff --git a/entity/src/main/resources/application-entity.yaml b/entity/src/main/resources/application-entity.yaml deleted file mode 100644 index 507cea7b..00000000 --- a/entity/src/main/resources/application-entity.yaml +++ /dev/null @@ -1,16 +0,0 @@ -spring: - datasource: # todo mysql - url: ENC(GPT8CR78IymrQCJ/ui4FKpW3y+eOb99E9Neh0AqVsGe4wR4+llYdbISGgFUaJB1RKBc99SK1pJ/Y2yE3MpOVH/30rdTmQ4qD+VNoC6B42wBzr2aiqlYE4x8hF8XvtdmT) - username: ENC(WS0DuwNzN19hZCDcpeK0ptXS6Gv3CowQNfwGQ4A3byU=) - password: ENC(ozxs8iZBHjljszbq6/y3cVt5Xt1Z8Nj6qh6gPobhs9A=) - driver-class-name: com.mysql.cj.jdbc.Driver - jpa: - properties: - hibernate: - ddl-auto: none - dialect: org.hibernate.dialect.MySQLDialect - show_sql: true - -jasypt: - encryptor: - password: ${JASYPT_ENCRYPTOR_PASSWORD} From 5beaf90c1d79350fa16e8b8d958f88f34a407bc1 Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 03:46:10 +0900 Subject: [PATCH 11/36] feat: V1 dev, prod ddl (#8) --- .../resources/application-entity-local.yml | 2 +- .../resources/application-entity-prod.yml | 2 +- entity/src/main/resources/ddl/V1ddl-dev.sql | 58 +++++++++++++++++++ entity/src/main/resources/ddl/V1ddl-prod.sql | 58 +++++++++++++++++++ 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 entity/src/main/resources/ddl/V1ddl-dev.sql create mode 100644 entity/src/main/resources/ddl/V1ddl-prod.sql diff --git a/entity/src/main/resources/application-entity-local.yml b/entity/src/main/resources/application-entity-local.yml index 9c3b02a7..3242e2a9 100644 --- a/entity/src/main/resources/application-entity-local.yml +++ b/entity/src/main/resources/application-entity-local.yml @@ -7,7 +7,7 @@ spring: jpa: show-sql: true hibernate: - ddl-auto: create + ddl-auto: validate properties: hibernate: default_batch_fetch_size: 200 diff --git a/entity/src/main/resources/application-entity-prod.yml b/entity/src/main/resources/application-entity-prod.yml index bc9a5451..b56e0c92 100644 --- a/entity/src/main/resources/application-entity-prod.yml +++ b/entity/src/main/resources/application-entity-prod.yml @@ -7,7 +7,7 @@ spring: jpa: show-sql: true hibernate: - ddl-auto: create + ddl-auto: validate properties: hibernate: default_batch_fetch_size: 200 diff --git a/entity/src/main/resources/ddl/V1ddl-dev.sql b/entity/src/main/resources/ddl/V1ddl-dev.sql new file mode 100644 index 00000000..16795723 --- /dev/null +++ b/entity/src/main/resources/ddl/V1ddl-dev.sql @@ -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, + part ENUM('ANDROID','IOS','PRODUCT_DESIGN','SPRING','WEB') NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB; diff --git a/entity/src/main/resources/ddl/V1ddl-prod.sql b/entity/src/main/resources/ddl/V1ddl-prod.sql new file mode 100644 index 00000000..a49abb4c --- /dev/null +++ b/entity/src/main/resources/ddl/V1ddl-prod.sql @@ -0,0 +1,58 @@ +CREATE TABLE dojo_prod.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_prod.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_prod.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_prod.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_prod.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, + part ENUM('ANDROID','IOS','PRODUCT_DESIGN','SPRING','WEB') NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB; From 205cf7d754a20092f8c91e3bea8f536e74d62c72 Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 03:53:13 +0900 Subject: [PATCH 12/36] refactor: Rename part field to platform (#8) --- entity/src/main/kotlin/com/mashup/dojo/member/Member.kt | 8 ++++---- .../com/mashup/dojo/member/{Part.kt => Platform.kt} | 2 +- entity/src/main/resources/ddl/V1ddl-dev.sql | 2 +- entity/src/main/resources/ddl/V1ddl-prod.sql | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename entity/src/main/kotlin/com/mashup/dojo/member/{Part.kt => Platform.kt} (81%) diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt index 5f379e98..adff17a4 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt @@ -18,8 +18,8 @@ class Member( @Column(name = "name", nullable = false) val name: String, @Enumerated(EnumType.STRING) - @Column(name = "part", nullable = false) - val part: Part, + @Column(name = "platform", nullable = false) + val platform: Platform, @Enumerated(EnumType.STRING) @Column(name = "gender", nullable = false) val gender: Gender, @@ -44,11 +44,11 @@ class Member( companion object { fun createMember( name: String, - part: Part, + platform: Platform, gender: Gender, generation: Int, ): Member { - return Member(name, part, gender, 200, generation) + return Member(name, platform, gender, 200, generation) } } } diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Part.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt similarity index 81% rename from entity/src/main/kotlin/com/mashup/dojo/member/Part.kt rename to entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt index ff1f890d..1b33c134 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Part.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt @@ -1,6 +1,6 @@ package com.mashup.dojo.member -enum class Part { +enum class Platform { PRODUCT_DESIGN, WEB, IOS, diff --git a/entity/src/main/resources/ddl/V1ddl-dev.sql b/entity/src/main/resources/ddl/V1ddl-dev.sql index 16795723..f1fc7076 100644 --- a/entity/src/main/resources/ddl/V1ddl-dev.sql +++ b/entity/src/main/resources/ddl/V1ddl-dev.sql @@ -53,6 +53,6 @@ CREATE TABLE dojo_dev.member updated_at DATETIME(6) NOT NULL, name VARCHAR(255) NOT NULL, gender ENUM('FEMALE','MALE') NOT NULL, - part ENUM('ANDROID','IOS','PRODUCT_DESIGN','SPRING','WEB') NOT NULL, + platform ENUM('ANDROID','IOS','PRODUCT_DESIGN','SPRING','WEB') NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB; diff --git a/entity/src/main/resources/ddl/V1ddl-prod.sql b/entity/src/main/resources/ddl/V1ddl-prod.sql index a49abb4c..f8655a25 100644 --- a/entity/src/main/resources/ddl/V1ddl-prod.sql +++ b/entity/src/main/resources/ddl/V1ddl-prod.sql @@ -53,6 +53,6 @@ CREATE TABLE dojo_prod.member updated_at DATETIME(6) NOT NULL, name VARCHAR(255) NOT NULL, gender ENUM('FEMALE','MALE') NOT NULL, - part ENUM('ANDROID','IOS','PRODUCT_DESIGN','SPRING','WEB') NOT NULL, + platform ENUM('ANDROID','IOS','PRODUCT_DESIGN','SPRING','WEB') NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB; From 6a66114550513f219e9ef49b6c29b0ff8f91d2f3 Mon Sep 17 00:00:00 2001 From: toychip Date: Fri, 21 Jun 2024 19:44:16 +0900 Subject: [PATCH 13/36] refactor: Change default point value in Member class to constant (#8) --- entity/src/main/kotlin/com/mashup/dojo/member/Member.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt index adff17a4..f8fe3f26 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt @@ -12,6 +12,8 @@ import jakarta.persistence.OneToMany import jakarta.persistence.OneToOne import jakarta.persistence.Table +private const val DEFAULT_POINT = 200 + @Entity @Table(name = "member") class Member( @@ -23,7 +25,7 @@ class Member( @Enumerated(EnumType.STRING) @Column(name = "gender", nullable = false) val gender: Gender, - point: Int = 200, + point: Int = DEFAULT_POINT, @Column(name = "generation", nullable = false) val generation: Int, @OneToOne(mappedBy = "member") @@ -48,7 +50,7 @@ class Member( gender: Gender, generation: Int, ): Member { - return Member(name, platform, gender, 200, generation) + return Member(name, platform, gender, DEFAULT_POINT, generation) } } } From b1b93fe07123d15e2f40a5f2dc5738307f860db1 Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 00:02:51 +0900 Subject: [PATCH 14/36] add: Profile Entity (#8) --- .../kotlin/com/mashup/dojo/profile/Profile.kt | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt diff --git a/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt b/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt new file mode 100644 index 00000000..06bc9fd0 --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt @@ -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 + private set + + fun updateImageUrl(newImageUrl: String) { + this.imageUrl = newImageUrl + } +} From ab7dd36f462a20b933761ad692b9cf79ebc46fb1 Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 00:03:08 +0900 Subject: [PATCH 15/36] add: Member Entity (#8) --- .../kotlin/com/mashup/dojo/member/Gender.kt | 6 +++ .../kotlin/com/mashup/dojo/member/Member.kt | 47 +++++++++++++++++++ .../kotlin/com/mashup/dojo/member/Part.kt | 9 ++++ 3 files changed, 62 insertions(+) create mode 100644 entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt create mode 100644 entity/src/main/kotlin/com/mashup/dojo/member/Member.kt create mode 100644 entity/src/main/kotlin/com/mashup/dojo/member/Part.kt diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt new file mode 100644 index 00000000..184c90fe --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt @@ -0,0 +1,6 @@ +package com.mashup.dojo.member + +enum class Gender { + MALE, + FEMALE, +} diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt new file mode 100644 index 00000000..04d6f7d6 --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt @@ -0,0 +1,47 @@ +package com.mashup.dojo.member + +import com.mashup.dojo.base.BaseTimeEntity +import com.mashup.dojo.profile.Profile +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.OneToOne +import jakarta.persistence.Table + +@Entity +@Table(name = "member") +open class Member protected constructor( + @Column(name = "name", nullable = false) + val name: String, + @Enumerated(EnumType.STRING) + @Column(name = "part", nullable = false) + val part: Part, + @Enumerated(EnumType.STRING) + @Column(name = "gender", nullable = false) + val gender: Gender, + point: Int = 200, + @Column(name = "generation", nullable = false) + val generation: Int, + @OneToOne(mappedBy = "member") + val profile: Profile? = null, +) : BaseTimeEntity() { + @Column(name = "point", nullable = false) + var point: Int = point + private set + + fun updatePoint(newPoint: Int) { + this.point = newPoint + } + + companion object { + fun createMember( + name: String, + part: Part, + gender: Gender, + generation: Int, + ): Member { + return Member(name, part, gender, 200, generation) + } + } +} diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Part.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Part.kt new file mode 100644 index 00000000..ff1f890d --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Part.kt @@ -0,0 +1,9 @@ +package com.mashup.dojo.member + +enum class Part { + PRODUCT_DESIGN, + WEB, + IOS, + ANDROID, + SPRING, +} From 01bfff2c9d9d3cd7f9e71867d8476e4908d268c7 Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 00:09:11 +0900 Subject: [PATCH 16/36] add: Profile Entity init constructor (#8) --- entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt b/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt index 06bc9fd0..aa5f6872 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt @@ -11,7 +11,7 @@ import jakarta.persistence.Table @Entity @Table(name = "profile") -class Profile( +open class Profile protected constructor( imageUrl: String, @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") From 25bac786f48b61e9cefa673fd0925d52b3de19b9 Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 00:09:37 +0900 Subject: [PATCH 17/36] add: Question Entity (#8) --- .../com/mashup/dojo/question/Question.kt | 28 +++++++++++++++++++ .../kotlin/com/mashup/dojo/question/Target.kt | 7 +++++ 2 files changed, 35 insertions(+) create mode 100644 entity/src/main/kotlin/com/mashup/dojo/question/Question.kt create mode 100644 entity/src/main/kotlin/com/mashup/dojo/question/Target.kt diff --git a/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt b/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt new file mode 100644 index 00000000..42f2fa23 --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt @@ -0,0 +1,28 @@ +package com.mashup.dojo.question + +import com.mashup.dojo.base.BaseTimeEntity +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.Table + +@Entity +@Table(name = "question") +open class Question protected constructor( + + @Column(name = "content", nullable = false) + var content: String, + + @Enumerated(EnumType.STRING) + @Column(name = "target", nullable = false) + var target: Target + +) : BaseTimeEntity() { + + companion object { + fun createQuestion(content: String, target: Target): Question { + return Question(content, target) + } + } +} diff --git a/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt b/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt new file mode 100644 index 00000000..8799f125 --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt @@ -0,0 +1,7 @@ +package com.mashup.dojo.question + +enum class Target { + FRIEND, // 지인 + STRANGER, // 낯선 사람 + EITHER +} From e50f3a3f4f13d6fce09cd4eb6abef62ccde38507 Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 00:25:43 +0900 Subject: [PATCH 18/36] add: Pick Entity (#8) --- .../main/kotlin/com/mashup/dojo/pick/Pick.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt diff --git a/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt b/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt new file mode 100644 index 00000000..38d1d81b --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt @@ -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") +open class Pick protected constructor( + @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() From 8b44143879c1c980247cd8eb98751959ba88356e Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 00:28:19 +0900 Subject: [PATCH 19/36] add: bidirectional mapping between Member, Question, and Pick entities (#8) --- .../main/kotlin/com/mashup/dojo/member/Member.kt | 7 +++++++ .../kotlin/com/mashup/dojo/question/Question.kt | 16 ++++++++++------ .../kotlin/com/mashup/dojo/question/Target.kt | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt index 04d6f7d6..3aee1727 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt @@ -1,11 +1,14 @@ 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 @@ -25,6 +28,10 @@ open class Member protected constructor( val generation: Int, @OneToOne(mappedBy = "member") val profile: Profile? = null, + @OneToMany(mappedBy = "fromMember", cascade = [CascadeType.ALL], orphanRemoval = true) + val fromPicks: MutableList = mutableListOf(), + @OneToMany(mappedBy = "toMember", cascade = [CascadeType.ALL], orphanRemoval = true) + val toPicks: MutableList = mutableListOf(), ) : BaseTimeEntity() { @Column(name = "point", nullable = false) var point: Int = point diff --git a/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt b/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt index 42f2fa23..abde1f6f 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt @@ -1,27 +1,31 @@ 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") open class Question protected constructor( - @Column(name = "content", nullable = false) var content: String, - @Enumerated(EnumType.STRING) @Column(name = "target", nullable = false) - var target: Target - + var target: Target, + @OneToMany(mappedBy = "question", cascade = [CascadeType.ALL], orphanRemoval = true) + var picks: MutableList = mutableListOf(), ) : BaseTimeEntity() { - companion object { - fun createQuestion(content: String, target: Target): Question { + fun createQuestion( + content: String, + target: Target, + ): Question { return Question(content, target) } } diff --git a/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt b/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt index 8799f125..19b0c96e 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt @@ -3,5 +3,5 @@ package com.mashup.dojo.question enum class Target { FRIEND, // 지인 STRANGER, // 낯선 사람 - EITHER + EITHER, } From 38578e41155cd0e38f50fc78f00b6956cf58a2ad Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 00:31:56 +0900 Subject: [PATCH 20/36] add: Notification Entity (#8) --- .../mashup/dojo/notification/Notification.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt diff --git a/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt b/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt new file mode 100644 index 00000000..6582e7ee --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt @@ -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") +open class Notification protected constructor( + @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() From 8d7627e1e70d5f633b8dfe916647215da79ff53f Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 03:08:04 +0900 Subject: [PATCH 21/36] fix: Change BaseEntity field access from private to protected (#8) --- .../src/main/kotlin/com/mashup/dojo/base/BaseEntity.kt | 10 +++++----- .../main/kotlin/com/mashup/dojo/base/BaseTimeEntity.kt | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/entity/src/main/kotlin/com/mashup/dojo/base/BaseEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/base/BaseEntity.kt index 83f015a2..46a15649 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/base/BaseEntity.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/base/BaseEntity.kt @@ -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() { diff --git a/entity/src/main/kotlin/com/mashup/dojo/base/BaseTimeEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/base/BaseTimeEntity.kt index fb8ef6cc..71d0f884 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/base/BaseTimeEntity.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/base/BaseTimeEntity.kt @@ -14,10 +14,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 } From 738ed5ee66c13b83859b8283d647c8165260752f Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 03:11:13 +0900 Subject: [PATCH 22/36] refactor: Simplify entities with allOpen and noArg dependencies (#8) --- build.gradle.kts | 14 ++++++++++++-- .../main/kotlin/com/mashup/dojo/member/Member.kt | 4 ++-- .../com/mashup/dojo/notification/Notification.kt | 2 +- .../src/main/kotlin/com/mashup/dojo/pick/Pick.kt | 2 +- .../main/kotlin/com/mashup/dojo/profile/Profile.kt | 4 ++-- .../kotlin/com/mashup/dojo/question/Question.kt | 2 +- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5ce78d0c..a544683b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -90,8 +90,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"]}") @@ -106,6 +106,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") { diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt index 3aee1727..5f379e98 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt @@ -14,7 +14,7 @@ import jakarta.persistence.Table @Entity @Table(name = "member") -open class Member protected constructor( +class Member( @Column(name = "name", nullable = false) val name: String, @Enumerated(EnumType.STRING) @@ -35,7 +35,7 @@ open class Member protected constructor( ) : BaseTimeEntity() { @Column(name = "point", nullable = false) var point: Int = point - private set + protected set fun updatePoint(newPoint: Int) { this.point = newPoint diff --git a/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt b/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt index 6582e7ee..8beb840a 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt @@ -7,7 +7,7 @@ import jakarta.persistence.Table @Entity @Table(name = "notification") -open class Notification protected constructor( +class Notification( @Column(name = "title", nullable = false) val title: String, @Column(name = "content", nullable = false) diff --git a/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt b/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt index 38d1d81b..7b8a3db5 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt @@ -11,7 +11,7 @@ import jakarta.persistence.Table @Entity @Table(name = "pick") -open class Pick protected constructor( +class Pick( @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "question_id") val question: Question, diff --git a/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt b/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt index aa5f6872..0eb1edc6 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt @@ -11,7 +11,7 @@ import jakarta.persistence.Table @Entity @Table(name = "profile") -open class Profile protected constructor( +class Profile( imageUrl: String, @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") @@ -19,7 +19,7 @@ open class Profile protected constructor( ) : BaseEntity() { @Column(name = "image_url", nullable = false) var imageUrl: String = imageUrl - private set + protected set fun updateImageUrl(newImageUrl: String) { this.imageUrl = newImageUrl diff --git a/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt b/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt index abde1f6f..5409d3be 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt @@ -12,7 +12,7 @@ import jakarta.persistence.Table @Entity @Table(name = "question") -open class Question protected constructor( +class Question( @Column(name = "content", nullable = false) var content: String, @Enumerated(EnumType.STRING) From 450e8ad25a596872bd32d6270bac336be98ac553 Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 03:12:29 +0900 Subject: [PATCH 23/36] refactor: Split application-entity.yml into local and prod configurations (#8) --- .../resources/application-entity-local.yml | 19 +++++++++++++++++++ .../resources/application-entity-prod.yml | 19 +++++++++++++++++++ .../main/resources/application-entity.yaml | 16 ---------------- 3 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 entity/src/main/resources/application-entity-local.yml create mode 100644 entity/src/main/resources/application-entity-prod.yml delete mode 100644 entity/src/main/resources/application-entity.yaml diff --git a/entity/src/main/resources/application-entity-local.yml b/entity/src/main/resources/application-entity-local.yml new file mode 100644 index 00000000..9c3b02a7 --- /dev/null +++ b/entity/src/main/resources/application-entity-local.yml @@ -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: create + properties: + hibernate: + default_batch_fetch_size: 200 + dialect: org.hibernate.dialect.MySQL8Dialect + format_sql: true + +jasypt: + encryptor: + password: ${JASYPT_ENCRYPTOR_PASSWORD} diff --git a/entity/src/main/resources/application-entity-prod.yml b/entity/src/main/resources/application-entity-prod.yml new file mode 100644 index 00000000..bc9a5451 --- /dev/null +++ b/entity/src/main/resources/application-entity-prod.yml @@ -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: create + properties: + hibernate: + default_batch_fetch_size: 200 + dialect: org.hibernate.dialect.MySQL8Dialect + format_sql: true + +jasypt: + encryptor: + password: ${JASYPT_ENCRYPTOR_PASSWORD} diff --git a/entity/src/main/resources/application-entity.yaml b/entity/src/main/resources/application-entity.yaml deleted file mode 100644 index 507cea7b..00000000 --- a/entity/src/main/resources/application-entity.yaml +++ /dev/null @@ -1,16 +0,0 @@ -spring: - datasource: # todo mysql - url: ENC(GPT8CR78IymrQCJ/ui4FKpW3y+eOb99E9Neh0AqVsGe4wR4+llYdbISGgFUaJB1RKBc99SK1pJ/Y2yE3MpOVH/30rdTmQ4qD+VNoC6B42wBzr2aiqlYE4x8hF8XvtdmT) - username: ENC(WS0DuwNzN19hZCDcpeK0ptXS6Gv3CowQNfwGQ4A3byU=) - password: ENC(ozxs8iZBHjljszbq6/y3cVt5Xt1Z8Nj6qh6gPobhs9A=) - driver-class-name: com.mysql.cj.jdbc.Driver - jpa: - properties: - hibernate: - ddl-auto: none - dialect: org.hibernate.dialect.MySQLDialect - show_sql: true - -jasypt: - encryptor: - password: ${JASYPT_ENCRYPTOR_PASSWORD} From 5f9a4a4539b6cecbff6f02ae00ff3a8797f880a8 Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 03:46:10 +0900 Subject: [PATCH 24/36] feat: V1 dev, prod ddl (#8) --- .../resources/application-entity-local.yml | 2 +- .../resources/application-entity-prod.yml | 2 +- entity/src/main/resources/ddl/V1ddl-dev.sql | 58 +++++++++++++++++++ entity/src/main/resources/ddl/V1ddl-prod.sql | 58 +++++++++++++++++++ 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 entity/src/main/resources/ddl/V1ddl-dev.sql create mode 100644 entity/src/main/resources/ddl/V1ddl-prod.sql diff --git a/entity/src/main/resources/application-entity-local.yml b/entity/src/main/resources/application-entity-local.yml index 9c3b02a7..3242e2a9 100644 --- a/entity/src/main/resources/application-entity-local.yml +++ b/entity/src/main/resources/application-entity-local.yml @@ -7,7 +7,7 @@ spring: jpa: show-sql: true hibernate: - ddl-auto: create + ddl-auto: validate properties: hibernate: default_batch_fetch_size: 200 diff --git a/entity/src/main/resources/application-entity-prod.yml b/entity/src/main/resources/application-entity-prod.yml index bc9a5451..b56e0c92 100644 --- a/entity/src/main/resources/application-entity-prod.yml +++ b/entity/src/main/resources/application-entity-prod.yml @@ -7,7 +7,7 @@ spring: jpa: show-sql: true hibernate: - ddl-auto: create + ddl-auto: validate properties: hibernate: default_batch_fetch_size: 200 diff --git a/entity/src/main/resources/ddl/V1ddl-dev.sql b/entity/src/main/resources/ddl/V1ddl-dev.sql new file mode 100644 index 00000000..16795723 --- /dev/null +++ b/entity/src/main/resources/ddl/V1ddl-dev.sql @@ -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, + part ENUM('ANDROID','IOS','PRODUCT_DESIGN','SPRING','WEB') NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB; diff --git a/entity/src/main/resources/ddl/V1ddl-prod.sql b/entity/src/main/resources/ddl/V1ddl-prod.sql new file mode 100644 index 00000000..a49abb4c --- /dev/null +++ b/entity/src/main/resources/ddl/V1ddl-prod.sql @@ -0,0 +1,58 @@ +CREATE TABLE dojo_prod.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_prod.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_prod.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_prod.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_prod.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, + part ENUM('ANDROID','IOS','PRODUCT_DESIGN','SPRING','WEB') NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB; From 02cb04375c343f0cbdd421872a019459f269f44c Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 20 Jun 2024 03:53:13 +0900 Subject: [PATCH 25/36] refactor: Rename part field to platform (#8) --- entity/src/main/kotlin/com/mashup/dojo/member/Member.kt | 8 ++++---- .../com/mashup/dojo/member/{Part.kt => Platform.kt} | 2 +- entity/src/main/resources/ddl/V1ddl-dev.sql | 2 +- entity/src/main/resources/ddl/V1ddl-prod.sql | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename entity/src/main/kotlin/com/mashup/dojo/member/{Part.kt => Platform.kt} (81%) diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt index 5f379e98..adff17a4 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt @@ -18,8 +18,8 @@ class Member( @Column(name = "name", nullable = false) val name: String, @Enumerated(EnumType.STRING) - @Column(name = "part", nullable = false) - val part: Part, + @Column(name = "platform", nullable = false) + val platform: Platform, @Enumerated(EnumType.STRING) @Column(name = "gender", nullable = false) val gender: Gender, @@ -44,11 +44,11 @@ class Member( companion object { fun createMember( name: String, - part: Part, + platform: Platform, gender: Gender, generation: Int, ): Member { - return Member(name, part, gender, 200, generation) + return Member(name, platform, gender, 200, generation) } } } diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Part.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt similarity index 81% rename from entity/src/main/kotlin/com/mashup/dojo/member/Part.kt rename to entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt index ff1f890d..1b33c134 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Part.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt @@ -1,6 +1,6 @@ package com.mashup.dojo.member -enum class Part { +enum class Platform { PRODUCT_DESIGN, WEB, IOS, diff --git a/entity/src/main/resources/ddl/V1ddl-dev.sql b/entity/src/main/resources/ddl/V1ddl-dev.sql index 16795723..f1fc7076 100644 --- a/entity/src/main/resources/ddl/V1ddl-dev.sql +++ b/entity/src/main/resources/ddl/V1ddl-dev.sql @@ -53,6 +53,6 @@ CREATE TABLE dojo_dev.member updated_at DATETIME(6) NOT NULL, name VARCHAR(255) NOT NULL, gender ENUM('FEMALE','MALE') NOT NULL, - part ENUM('ANDROID','IOS','PRODUCT_DESIGN','SPRING','WEB') NOT NULL, + platform ENUM('ANDROID','IOS','PRODUCT_DESIGN','SPRING','WEB') NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB; diff --git a/entity/src/main/resources/ddl/V1ddl-prod.sql b/entity/src/main/resources/ddl/V1ddl-prod.sql index a49abb4c..f8655a25 100644 --- a/entity/src/main/resources/ddl/V1ddl-prod.sql +++ b/entity/src/main/resources/ddl/V1ddl-prod.sql @@ -53,6 +53,6 @@ CREATE TABLE dojo_prod.member updated_at DATETIME(6) NOT NULL, name VARCHAR(255) NOT NULL, gender ENUM('FEMALE','MALE') NOT NULL, - part ENUM('ANDROID','IOS','PRODUCT_DESIGN','SPRING','WEB') NOT NULL, + platform ENUM('ANDROID','IOS','PRODUCT_DESIGN','SPRING','WEB') NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB; From 9673d14da3a0ab7048e9ee388a02e46bf73d69ea Mon Sep 17 00:00:00 2001 From: toychip Date: Fri, 21 Jun 2024 19:44:16 +0900 Subject: [PATCH 26/36] refactor: Change default point value in Member class to constant (#8) --- entity/src/main/kotlin/com/mashup/dojo/member/Member.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt index adff17a4..f8fe3f26 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt @@ -12,6 +12,8 @@ import jakarta.persistence.OneToMany import jakarta.persistence.OneToOne import jakarta.persistence.Table +private const val DEFAULT_POINT = 200 + @Entity @Table(name = "member") class Member( @@ -23,7 +25,7 @@ class Member( @Enumerated(EnumType.STRING) @Column(name = "gender", nullable = false) val gender: Gender, - point: Int = 200, + point: Int = DEFAULT_POINT, @Column(name = "generation", nullable = false) val generation: Int, @OneToOne(mappedBy = "member") @@ -48,7 +50,7 @@ class Member( gender: Gender, generation: Int, ): Member { - return Member(name, platform, gender, 200, generation) + return Member(name, platform, gender, DEFAULT_POINT, generation) } } } From e76d28dc2775e0fa8efe0051c516c16e8a23c75d Mon Sep 17 00:00:00 2001 From: toychip Date: Sat, 6 Jul 2024 04:24:19 +0900 Subject: [PATCH 27/36] feat: add findByValue method to Platform and Gender enums --- .../src/main/kotlin/com/mashup/dojo/member/Gender.kt | 12 ++++++++++++ .../main/kotlin/com/mashup/dojo/member/Platform.kt | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt index 184c90fe..504f451a 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt @@ -1,6 +1,18 @@ package com.mashup.dojo.member +import java.lang.RuntimeException + enum class Gender { MALE, FEMALE, + ; + + companion object { + fun findByValue(value: String): Gender { + return Gender.entries.find { it.name.equals(value, ignoreCase = true) } + ?: throw RuntimeException("ToDo change to DoJoException") + // ToDo + // DojoException.of(DojoExceptionType.INVALID_MEMBER_PLATFORM) + } + } } diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt index 1b33c134..5d100c4d 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt @@ -1,9 +1,21 @@ package com.mashup.dojo.member +import java.lang.RuntimeException + enum class Platform { PRODUCT_DESIGN, WEB, IOS, ANDROID, SPRING, + ; + + companion object { + fun findByValue(value: String): Platform { + return entries.find { it.name.equals(value, ignoreCase = true) } + ?: throw RuntimeException("ToDo change to DoJoException") + // ToDo + // DojoException.of(DojoExceptionType.INVALID_MEMBER_PLATFORM) + } + } } From d1254607f41d3a8af3c49bebe0fb3d3d6728ffb7 Mon Sep 17 00:00:00 2001 From: toychip Date: Sat, 6 Jul 2024 04:25:37 +0900 Subject: [PATCH 28/36] refactor: remove unused entities and enums --- .../kotlin/com/mashup/dojo/profile/Profile.kt | 27 ------------------- .../kotlin/com/mashup/dojo/question/Target.kt | 7 ----- 2 files changed, 34 deletions(-) delete mode 100644 entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt delete mode 100644 entity/src/main/kotlin/com/mashup/dojo/question/Target.kt diff --git a/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt b/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt deleted file mode 100644 index 0eb1edc6..00000000 --- a/entity/src/main/kotlin/com/mashup/dojo/profile/Profile.kt +++ /dev/null @@ -1,27 +0,0 @@ -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 - } -} diff --git a/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt b/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt deleted file mode 100644 index 19b0c96e..00000000 --- a/entity/src/main/kotlin/com/mashup/dojo/question/Target.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.mashup.dojo.question - -enum class Target { - FRIEND, // 지인 - STRANGER, // 낯선 사람 - EITHER, -} From d5fc2dd2bc64ddc69913ae086e830747b03c0e4d Mon Sep 17 00:00:00 2001 From: toychip Date: Sat, 6 Jul 2024 04:26:51 +0900 Subject: [PATCH 29/36] refactor: add 'Entity' suffix to Member, Pick, and Question entities --- .../com/mashup/dojo/MemberRepository.kt | 17 +--- .../kotlin/com/mashup/dojo/member/Member.kt | 56 ------------- .../com/mashup/dojo/member/MemberEntity.kt | 71 ++++++++++++++++ .../main/kotlin/com/mashup/dojo/pick/Pick.kt | 24 ------ .../kotlin/com/mashup/dojo/pick/PickEntity.kt | 36 +++++++++ .../com/mashup/dojo/question/Question.kt | 32 -------- .../mashup/dojo/question/QuestionEntity.kt | 81 +++++++++++++++++++ 7 files changed, 189 insertions(+), 128 deletions(-) delete mode 100644 entity/src/main/kotlin/com/mashup/dojo/member/Member.kt create mode 100644 entity/src/main/kotlin/com/mashup/dojo/member/MemberEntity.kt delete mode 100644 entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt create mode 100644 entity/src/main/kotlin/com/mashup/dojo/pick/PickEntity.kt delete mode 100644 entity/src/main/kotlin/com/mashup/dojo/question/Question.kt create mode 100644 entity/src/main/kotlin/com/mashup/dojo/question/QuestionEntity.kt diff --git a/entity/src/main/kotlin/com/mashup/dojo/MemberRepository.kt b/entity/src/main/kotlin/com/mashup/dojo/MemberRepository.kt index 4be4c775..736ebf36 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/MemberRepository.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/MemberRepository.kt @@ -1,21 +1,6 @@ package com.mashup.dojo -import com.mashup.dojo.base.BaseEntity -import jakarta.persistence.Entity -import jakarta.persistence.Id +import com.mashup.dojo.member.MemberEntity import org.springframework.data.jpa.repository.JpaRepository interface MemberRepository : JpaRepository - -@Entity -class MemberEntity( - @Id - val id: String, - val fullName: String, - val secondInitialName: String, - val profileImageId: String?, - val platform: String, - val ordinal: Int, - val gender: String, - val point: Int, -) : BaseEntity() diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt deleted file mode 100644 index f8fe3f26..00000000 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Member.kt +++ /dev/null @@ -1,56 +0,0 @@ -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 - -private const val DEFAULT_POINT = 200 - -@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 = DEFAULT_POINT, - @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 = mutableListOf(), - @OneToMany(mappedBy = "toMember", cascade = [CascadeType.ALL], orphanRemoval = true) - val toPicks: MutableList = 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, DEFAULT_POINT, generation) - } - } -} diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/MemberEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/member/MemberEntity.kt new file mode 100644 index 00000000..35f5795c --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/member/MemberEntity.kt @@ -0,0 +1,71 @@ +package com.mashup.dojo.member + +import com.mashup.dojo.base.BaseTimeEntity +import com.mashup.dojo.pick.PickEntity +import jakarta.persistence.CascadeType +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.Id +import jakarta.persistence.OneToMany +import jakarta.persistence.Table + +private const val DEFAULT_POINT = 200 + +@Entity +@Table(name = "member") +class MemberEntity( + @Id + val id: String, + @Column(name = "full_name", nullable = false) + val fullName: String, + @Column(name = "second_initial_name", nullable = false) + val secondInitialName: String, + val profileImageId: String?, + @Column(name = "platform", nullable = false) + @Enumerated(EnumType.STRING) + val platform: Platform, + val ordinal: Int, + @Column(name = "gender", nullable = false) + @Enumerated(EnumType.STRING) + val gender: Gender, + point: Int = DEFAULT_POINT, + @OneToMany(mappedBy = "fromMemberEntity", cascade = [CascadeType.ALL], orphanRemoval = true) + val fromPickEntities: MutableList = mutableListOf(), + @OneToMany(mappedBy = "toMemberEntity", cascade = [CascadeType.ALL], orphanRemoval = true) + val toPickEntities: MutableList = mutableListOf(), +) : BaseTimeEntity() { + @Column(name = "point", nullable = false) + var point: Int = point + protected set + + fun updatePoint(newPoint: Int) { + this.point = newPoint + } + + companion object { + fun createMemberEntity( + id: String, + fullName: String, + secondInitialName: String, + profileImageId: String?, + platformString: String, + genderString: String, + ordinal: Int, + ): MemberEntity { + val platform = Platform.findByValue(platformString) + val gender = Gender.findByValue(genderString) + return MemberEntity( + id = id, + fullName = fullName, + secondInitialName = secondInitialName, + profileImageId = profileImageId, + platform = platform, + ordinal = ordinal, + gender = gender, + DEFAULT_POINT + ) + } + } +} diff --git a/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt b/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt deleted file mode 100644 index 7b8a3db5..00000000 --- a/entity/src/main/kotlin/com/mashup/dojo/pick/Pick.kt +++ /dev/null @@ -1,24 +0,0 @@ -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() diff --git a/entity/src/main/kotlin/com/mashup/dojo/pick/PickEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/pick/PickEntity.kt new file mode 100644 index 00000000..9d1b0d1e --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/pick/PickEntity.kt @@ -0,0 +1,36 @@ +package com.mashup.dojo.pick + +import com.mashup.dojo.base.BaseTimeEntity +import com.mashup.dojo.member.MemberEntity +import com.mashup.dojo.question.QuestionEntity +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.FetchType +import jakarta.persistence.Id +import jakarta.persistence.JoinColumn +import jakarta.persistence.ManyToOne +import jakarta.persistence.Table + +@Entity +@Table(name = "pick") +class PickEntity( + @Id + val id: String, + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "question_id") + val questionEntity: QuestionEntity, + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "from_member_id") + val picker: MemberEntity, + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "to_member_id") + val picked: MemberEntity, + @Column(name = "is_gender_open") + val isGenderOpen: Boolean, + @Column(name = "is_platform_open") + val isPlatformOpen: Boolean, + @Column(name = "is_mid_initial_name_open") + val isMidInitialNameOpen: Boolean, + @Column(name = "is_full_name_open") + val isFullNameOpen: Boolean, +) : BaseTimeEntity() diff --git a/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt b/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt deleted file mode 100644 index 5409d3be..00000000 --- a/entity/src/main/kotlin/com/mashup/dojo/question/Question.kt +++ /dev/null @@ -1,32 +0,0 @@ -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 = mutableListOf(), -) : BaseTimeEntity() { - companion object { - fun createQuestion( - content: String, - target: Target, - ): Question { - return Question(content, target) - } - } -} diff --git a/entity/src/main/kotlin/com/mashup/dojo/question/QuestionEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/question/QuestionEntity.kt new file mode 100644 index 00000000..3ccac33d --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/question/QuestionEntity.kt @@ -0,0 +1,81 @@ +package com.mashup.dojo.question + +import com.mashup.dojo.base.BaseTimeEntity +import com.mashup.dojo.pick.PickEntity +import jakarta.persistence.CascadeType +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.Id +import jakarta.persistence.OneToMany +import jakarta.persistence.Table +import java.lang.RuntimeException + +@Entity +@Table(name = "question") +class QuestionEntity( + @Id + val id: String, + @Column(name = "content", nullable = false) + var content: String, + @Enumerated(EnumType.STRING) + val type: QuestionType, + @Enumerated(EnumType.STRING) + val category: QuestionCategory, + val emojiImageId: String, + @OneToMany(mappedBy = "questionEntity", cascade = [CascadeType.ALL], orphanRemoval = true) + var pickEntities: MutableList = mutableListOf(), +) : BaseTimeEntity() { + companion object { + fun createQuestion( + id: String, + content: String, + questionTypeString: String, + categoryString: String, + emojiImageId: String, + ): QuestionEntity { + val questionType = QuestionType.findByValue(questionTypeString) + val category = QuestionCategory.findByValue(categoryString) + + return QuestionEntity(id, content, questionType, category, emojiImageId) + } + } +} + +enum class QuestionType { + FRIEND, + ACCOMPANY, + ; + + companion object { + fun findByValue(value: String): QuestionType { + return entries.find { it.name.equals(value, ignoreCase = true) } + ?: throw RuntimeException("ToDo change to DoJoException") + // ToDo + // DojoException.of(DojoExceptionType.INVALID_MEMBER_PLATFORM) + } + } +} + +enum class QuestionCategory { + LOVE, + ENTERTAINMENT, // 유흥 + APPEARANCE, + FLIRTING, // 작업 + PERSONALITY, + GET_TO_KNOW, + JOKE, + STRENGTH, + OTHER, + ; + + companion object { + fun findByValue(value: String): QuestionCategory { + return entries.find { it.name.equals(value, ignoreCase = true) } + ?: throw RuntimeException("ToDo change to DoJoException") + // ToDo + // DojoException.of(DojoExceptionType.INVALID_MEMBER_PLATFORM) + } + } +} From db9b472647df3e94106648093fe6be4b7ddafbf8 Mon Sep 17 00:00:00 2001 From: toychip Date: Sat, 6 Jul 2024 04:34:32 +0900 Subject: [PATCH 30/36] refactor: replace constructor with factory method in MemberEntity --- .../kotlin/com/mashup/dojo/service/MemberService.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/service/src/main/kotlin/com/mashup/dojo/service/MemberService.kt b/service/src/main/kotlin/com/mashup/dojo/service/MemberService.kt index df6b8a03..ba1fde50 100644 --- a/service/src/main/kotlin/com/mashup/dojo/service/MemberService.kt +++ b/service/src/main/kotlin/com/mashup/dojo/service/MemberService.kt @@ -1,6 +1,5 @@ package com.mashup.dojo.service -import com.mashup.dojo.MemberEntity import com.mashup.dojo.MemberRepository import com.mashup.dojo.domain.Candidate import com.mashup.dojo.domain.ImageId @@ -10,6 +9,7 @@ import com.mashup.dojo.domain.MemberId import com.mashup.dojo.domain.MemberPlatform import com.mashup.dojo.domain.MemberRelation import com.mashup.dojo.domain.RelationType +import com.mashup.dojo.member.MemberEntity import org.springframework.stereotype.Service import java.time.LocalDateTime @@ -97,14 +97,13 @@ class DefaultMemberService( } private fun Member.toEntity(): MemberEntity { - return MemberEntity( + return MemberEntity.createMemberEntity( id = id.value, fullName = fullName, secondInitialName = secondInitialName, profileImageId = profileImageId?.value, - platform = platform.name, - ordinal = ordinal, - gender = gender.name, - point = point + platformString = platform.name, + genderString = gender.name, + ordinal = ordinal ) } From d64789fb02c51a010b511d86bd354550f4714138 Mon Sep 17 00:00:00 2001 From: toychip Date: Sun, 7 Jul 2024 10:41:49 +0900 Subject: [PATCH 31/36] refactor: Move enum validation to domain layer and update MemberEntity --- .../kotlin/com/mashup/dojo/member/Gender.kt | 12 ---------- .../com/mashup/dojo/member/MemberEntity.kt | 6 ++--- .../kotlin/com/mashup/dojo/member/Platform.kt | 12 ---------- .../kotlin/com/mashup/dojo/domain/Member.kt | 23 +++++++++++++++++++ 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt index 504f451a..184c90fe 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt @@ -1,18 +1,6 @@ package com.mashup.dojo.member -import java.lang.RuntimeException - enum class Gender { MALE, FEMALE, - ; - - companion object { - fun findByValue(value: String): Gender { - return Gender.entries.find { it.name.equals(value, ignoreCase = true) } - ?: throw RuntimeException("ToDo change to DoJoException") - // ToDo - // DojoException.of(DojoExceptionType.INVALID_MEMBER_PLATFORM) - } - } } diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/MemberEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/member/MemberEntity.kt index 35f5795c..3cdf6d8f 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/MemberEntity.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/MemberEntity.kt @@ -50,12 +50,10 @@ class MemberEntity( fullName: String, secondInitialName: String, profileImageId: String?, - platformString: String, - genderString: String, + platform: Platform, + gender: Gender, ordinal: Int, ): MemberEntity { - val platform = Platform.findByValue(platformString) - val gender = Gender.findByValue(genderString) return MemberEntity( id = id, fullName = fullName, diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt index 5d100c4d..1b33c134 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt @@ -1,21 +1,9 @@ package com.mashup.dojo.member -import java.lang.RuntimeException - enum class Platform { PRODUCT_DESIGN, WEB, IOS, ANDROID, SPRING, - ; - - companion object { - fun findByValue(value: String): Platform { - return entries.find { it.name.equals(value, ignoreCase = true) } - ?: throw RuntimeException("ToDo change to DoJoException") - // ToDo - // DojoException.of(DojoExceptionType.INVALID_MEMBER_PLATFORM) - } - } } diff --git a/service/src/main/kotlin/com/mashup/dojo/domain/Member.kt b/service/src/main/kotlin/com/mashup/dojo/domain/Member.kt index 3630093d..3228dd8a 100644 --- a/service/src/main/kotlin/com/mashup/dojo/domain/Member.kt +++ b/service/src/main/kotlin/com/mashup/dojo/domain/Member.kt @@ -1,6 +1,9 @@ package com.mashup.dojo.domain import com.mashup.dojo.UUIDGenerator +import com.mashup.dojo.member.Gender +import com.mashup.dojo.member.Platform +import java.lang.RuntimeException import java.time.LocalDateTime /** @@ -72,6 +75,16 @@ data class Member( enum class MemberGender { MALE, FEMALE, + ; + + companion object { + fun findByValue(value: String): Gender { + return Gender.entries.find { it.name.equals(value, ignoreCase = true) } + ?: throw RuntimeException("ToDo change to DoJoException") + // ToDo + // DojoException.of(DojoExceptionType.INVALID_MEMBER_PLATFORM) + } + } } enum class MemberPlatform { @@ -81,4 +94,14 @@ enum class MemberPlatform { ANDROID, IOS, DESIGN, + ; + + companion object { + fun findByValue(value: String): Platform { + return Platform.entries.find { it.name.equals(value, ignoreCase = true) } + ?: throw RuntimeException("ToDo change to DoJoException") + // ToDo + // DojoException.of(DojoExceptionType.INVALID_MEMBER_PLATFORM) + } + } } From 2d117929ec86f19f06b2d4b66174cac20dcd3ff1 Mon Sep 17 00:00:00 2001 From: toychip Date: Sun, 7 Jul 2024 10:44:30 +0900 Subject: [PATCH 32/36] refactor: Embed enums into MemberEntity and remove external enum classes --- .../com/mashup/dojo/{member => }/MemberEntity.kt | 16 ++++++++++++++-- .../kotlin/com/mashup/dojo/MemberRepository.kt | 1 - .../com/mashup/dojo/{pick => }/PickEntity.kt | 3 +-- .../main/kotlin/com/mashup/dojo/member/Gender.kt | 6 ------ .../kotlin/com/mashup/dojo/member/Platform.kt | 9 --------- .../com/mashup/dojo/question/QuestionEntity.kt | 2 +- .../main/kotlin/com/mashup/dojo/domain/Member.kt | 4 ++-- .../com/mashup/dojo/service/MemberService.kt | 2 +- 8 files changed, 19 insertions(+), 24 deletions(-) rename entity/src/main/kotlin/com/mashup/dojo/{member => }/MemberEntity.kt (93%) rename entity/src/main/kotlin/com/mashup/dojo/{pick => }/PickEntity.kt (93%) delete mode 100644 entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt delete mode 100644 entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/MemberEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt similarity index 93% rename from entity/src/main/kotlin/com/mashup/dojo/member/MemberEntity.kt rename to entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt index 3cdf6d8f..7d01660b 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/member/MemberEntity.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt @@ -1,7 +1,6 @@ -package com.mashup.dojo.member +package com.mashup.dojo import com.mashup.dojo.base.BaseTimeEntity -import com.mashup.dojo.pick.PickEntity import jakarta.persistence.CascadeType import jakarta.persistence.Column import jakarta.persistence.Entity @@ -67,3 +66,16 @@ class MemberEntity( } } } + +enum class Platform { + PRODUCT_DESIGN, + WEB, + IOS, + ANDROID, + SPRING, +} + +enum class Gender { + MALE, + FEMALE, +} diff --git a/entity/src/main/kotlin/com/mashup/dojo/MemberRepository.kt b/entity/src/main/kotlin/com/mashup/dojo/MemberRepository.kt index 736ebf36..9e77bee0 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/MemberRepository.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/MemberRepository.kt @@ -1,6 +1,5 @@ package com.mashup.dojo -import com.mashup.dojo.member.MemberEntity import org.springframework.data.jpa.repository.JpaRepository interface MemberRepository : JpaRepository diff --git a/entity/src/main/kotlin/com/mashup/dojo/pick/PickEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/PickEntity.kt similarity index 93% rename from entity/src/main/kotlin/com/mashup/dojo/pick/PickEntity.kt rename to entity/src/main/kotlin/com/mashup/dojo/PickEntity.kt index 9d1b0d1e..e57a5114 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/pick/PickEntity.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/PickEntity.kt @@ -1,7 +1,6 @@ -package com.mashup.dojo.pick +package com.mashup.dojo import com.mashup.dojo.base.BaseTimeEntity -import com.mashup.dojo.member.MemberEntity import com.mashup.dojo.question.QuestionEntity import jakarta.persistence.Column import jakarta.persistence.Entity diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt deleted file mode 100644 index 184c90fe..00000000 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Gender.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.mashup.dojo.member - -enum class Gender { - MALE, - FEMALE, -} diff --git a/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt b/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt deleted file mode 100644 index 1b33c134..00000000 --- a/entity/src/main/kotlin/com/mashup/dojo/member/Platform.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.mashup.dojo.member - -enum class Platform { - PRODUCT_DESIGN, - WEB, - IOS, - ANDROID, - SPRING, -} diff --git a/entity/src/main/kotlin/com/mashup/dojo/question/QuestionEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/question/QuestionEntity.kt index 3ccac33d..90294a7a 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/question/QuestionEntity.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/question/QuestionEntity.kt @@ -1,7 +1,7 @@ package com.mashup.dojo.question +import com.mashup.dojo.PickEntity import com.mashup.dojo.base.BaseTimeEntity -import com.mashup.dojo.pick.PickEntity import jakarta.persistence.CascadeType import jakarta.persistence.Column import jakarta.persistence.Entity diff --git a/service/src/main/kotlin/com/mashup/dojo/domain/Member.kt b/service/src/main/kotlin/com/mashup/dojo/domain/Member.kt index 3228dd8a..feff1355 100644 --- a/service/src/main/kotlin/com/mashup/dojo/domain/Member.kt +++ b/service/src/main/kotlin/com/mashup/dojo/domain/Member.kt @@ -1,8 +1,8 @@ package com.mashup.dojo.domain +import com.mashup.dojo.Gender +import com.mashup.dojo.Platform import com.mashup.dojo.UUIDGenerator -import com.mashup.dojo.member.Gender -import com.mashup.dojo.member.Platform import java.lang.RuntimeException import java.time.LocalDateTime diff --git a/service/src/main/kotlin/com/mashup/dojo/service/MemberService.kt b/service/src/main/kotlin/com/mashup/dojo/service/MemberService.kt index ba1fde50..1258c1f2 100644 --- a/service/src/main/kotlin/com/mashup/dojo/service/MemberService.kt +++ b/service/src/main/kotlin/com/mashup/dojo/service/MemberService.kt @@ -1,5 +1,6 @@ package com.mashup.dojo.service +import com.mashup.dojo.MemberEntity import com.mashup.dojo.MemberRepository import com.mashup.dojo.domain.Candidate import com.mashup.dojo.domain.ImageId @@ -9,7 +10,6 @@ import com.mashup.dojo.domain.MemberId import com.mashup.dojo.domain.MemberPlatform import com.mashup.dojo.domain.MemberRelation import com.mashup.dojo.domain.RelationType -import com.mashup.dojo.member.MemberEntity import org.springframework.stereotype.Service import java.time.LocalDateTime From a0760a4dc063a10e1b660969ab14c00cfad7a67e Mon Sep 17 00:00:00 2001 From: toychip Date: Sun, 7 Jul 2024 10:53:44 +0900 Subject: [PATCH 33/36] refactor: Update MemberEntity to directly use enums and adjust service layer --- .../main/kotlin/com/mashup/dojo/service/MemberService.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/service/src/main/kotlin/com/mashup/dojo/service/MemberService.kt b/service/src/main/kotlin/com/mashup/dojo/service/MemberService.kt index 1258c1f2..62131284 100644 --- a/service/src/main/kotlin/com/mashup/dojo/service/MemberService.kt +++ b/service/src/main/kotlin/com/mashup/dojo/service/MemberService.kt @@ -97,13 +97,16 @@ class DefaultMemberService( } private fun Member.toEntity(): MemberEntity { + val platform = MemberPlatform.findByValue(platform.name) + val gender = MemberGender.findByValue(gender.name) + return MemberEntity.createMemberEntity( id = id.value, fullName = fullName, secondInitialName = secondInitialName, profileImageId = profileImageId?.value, - platformString = platform.name, - genderString = gender.name, + platform = platform, + gender = gender, ordinal = ordinal ) } From b51d59b0199cf40c847fa3416594b8ac39a8a3c2 Mon Sep 17 00:00:00 2001 From: toychip Date: Sun, 7 Jul 2024 20:38:56 +0900 Subject: [PATCH 34/36] fix: Update foreign key references and database schema --- .../main/kotlin/com/mashup/dojo/ImageRepository.kt | 2 ++ .../src/main/kotlin/com/mashup/dojo/MemberEntity.kt | 11 ++++++----- entity/src/main/kotlin/com/mashup/dojo/PickEntity.kt | 4 ++-- .../com/mashup/dojo/notification/Notification.kt | 3 +++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/entity/src/main/kotlin/com/mashup/dojo/ImageRepository.kt b/entity/src/main/kotlin/com/mashup/dojo/ImageRepository.kt index 55f4869b..68fc1d36 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/ImageRepository.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/ImageRepository.kt @@ -3,12 +3,14 @@ package com.mashup.dojo import com.mashup.dojo.base.BaseEntity import jakarta.persistence.Entity import jakarta.persistence.Id +import jakarta.persistence.Table import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository @Repository interface ImageRepository : JpaRepository +@Table(name = "image") @Entity class ImageEntity( @Id diff --git a/entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt index 7d01660b..46c62365 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt @@ -30,11 +30,12 @@ class MemberEntity( @Enumerated(EnumType.STRING) val gender: Gender, point: Int = DEFAULT_POINT, - @OneToMany(mappedBy = "fromMemberEntity", cascade = [CascadeType.ALL], orphanRemoval = true) - val fromPickEntities: MutableList = mutableListOf(), - @OneToMany(mappedBy = "toMemberEntity", cascade = [CascadeType.ALL], orphanRemoval = true) - val toPickEntities: MutableList = mutableListOf(), -) : BaseTimeEntity() { + @OneToMany(mappedBy = "picker", cascade = [CascadeType.ALL], orphanRemoval = true) + val pickers: MutableList = mutableListOf(), + @OneToMany(mappedBy = "picked", cascade = [CascadeType.ALL], orphanRemoval = true) + val picked: MutableList = mutableListOf(), + + ) : BaseTimeEntity() { @Column(name = "point", nullable = false) var point: Int = point protected set diff --git a/entity/src/main/kotlin/com/mashup/dojo/PickEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/PickEntity.kt index e57a5114..47bee7cb 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/PickEntity.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/PickEntity.kt @@ -19,10 +19,10 @@ class PickEntity( @JoinColumn(name = "question_id") val questionEntity: QuestionEntity, @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "from_member_id") + @JoinColumn(name = "picker_id", referencedColumnName = "id") val picker: MemberEntity, @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "to_member_id") + @JoinColumn(name = "picked_id", referencedColumnName = "id") val picked: MemberEntity, @Column(name = "is_gender_open") val isGenderOpen: Boolean, diff --git a/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt b/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt index 8beb840a..77fdc33e 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/notification/Notification.kt @@ -3,11 +3,14 @@ package com.mashup.dojo.notification import com.mashup.dojo.base.BaseTimeEntity import jakarta.persistence.Column import jakarta.persistence.Entity +import jakarta.persistence.Id import jakarta.persistence.Table @Entity @Table(name = "notification") class Notification( + @Id + val id: String, @Column(name = "title", nullable = false) val title: String, @Column(name = "content", nullable = false) From 1b246da34fd7ccbfb4fa548005415015abe04cb8 Mon Sep 17 00:00:00 2001 From: toychip Date: Sun, 7 Jul 2024 20:44:13 +0900 Subject: [PATCH 35/36] refactor: ktlint format --- entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt index 46c62365..77d5a031 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt @@ -34,8 +34,7 @@ class MemberEntity( val pickers: MutableList = mutableListOf(), @OneToMany(mappedBy = "picked", cascade = [CascadeType.ALL], orphanRemoval = true) val picked: MutableList = mutableListOf(), - - ) : BaseTimeEntity() { +) : BaseTimeEntity() { @Column(name = "point", nullable = false) var point: Int = point protected set From 6b18811a54c9684df2ad0a64787761ed6a2f8257 Mon Sep 17 00:00:00 2001 From: toychip Date: Sat, 27 Jul 2024 11:42:04 +0900 Subject: [PATCH 36/36] feat: MemberRelationEntity * MemberEntity mapping --- .../kotlin/com/mashup/dojo/MemberEntity.kt | 7 +++++- .../com/mashup/dojo/MemberRelationEntity.kt | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 entity/src/main/kotlin/com/mashup/dojo/MemberRelationEntity.kt diff --git a/entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt index 77d5a031..a483348c 100644 --- a/entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt +++ b/entity/src/main/kotlin/com/mashup/dojo/MemberEntity.kt @@ -34,7 +34,12 @@ class MemberEntity( val pickers: MutableList = mutableListOf(), @OneToMany(mappedBy = "picked", cascade = [CascadeType.ALL], orphanRemoval = true) val picked: MutableList = mutableListOf(), -) : BaseTimeEntity() { + @OneToMany(mappedBy = "from", cascade = [CascadeType.ALL], orphanRemoval = true) + val fromRelations: MutableList = mutableListOf(), + @OneToMany(mappedBy = "to", cascade = [CascadeType.ALL], orphanRemoval = true) + val toRelations: MutableList = mutableListOf(), + + ) : BaseTimeEntity() { @Column(name = "point", nullable = false) var point: Int = point protected set diff --git a/entity/src/main/kotlin/com/mashup/dojo/MemberRelationEntity.kt b/entity/src/main/kotlin/com/mashup/dojo/MemberRelationEntity.kt new file mode 100644 index 00000000..7de96a96 --- /dev/null +++ b/entity/src/main/kotlin/com/mashup/dojo/MemberRelationEntity.kt @@ -0,0 +1,25 @@ +package com.mashup.dojo + +import com.mashup.dojo.base.BaseTimeEntity +import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated +import jakarta.persistence.Id +import jakarta.persistence.ManyToOne + +@Entity +class MemberRelationEntity( + @Id + val id: String, + @ManyToOne + val from: MemberEntity, + @ManyToOne + val to: MemberEntity, + @Enumerated(EnumType.STRING) + val relationType: RelationType, +) : BaseTimeEntity() + +enum class RelationType { + FRIEND, + ACCOMPANY, +}