Skip to content

Commit

Permalink
refact: update domain structures for refactoring
Browse files Browse the repository at this point in the history
- `AuditingEntityListener` 추가
- 기존: 리스트 순차 탐색 ➡️  Map의 key값으로 탐색 개선
- 패키지명 `enums` ➡️  `enum` 으로 변경
  • Loading branch information
chock-cho committed Dec 30, 2024
1 parent d328163 commit b628066
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.dobby.backend.infrastructure.database.entity

import com.dobby.backend.infrastructure.database.entity.common.AuditingEntity
import com.dobby.backend.infrastructure.database.entity.enums.RoleType
import com.dobby.backend.infrastructure.database.entity.enums.ProviderType
import com.dobby.backend.infrastructure.database.entity.enum.MemberStatus
import com.dobby.backend.infrastructure.database.entity.enum.RoleType
import com.dobby.backend.infrastructure.database.entity.enum.ProviderType
import jakarta.persistence.*
import java.time.LocalDate

@Entity(name = "members")
@Entity(name = "member")
@Inheritance(strategy = InheritanceType.JOINED)
abstract class MemberEntity (
@DiscriminatorColumn(name = "role_type")
open class Member (
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
Expand All @@ -21,6 +23,10 @@ abstract class MemberEntity (
@Enumerated(EnumType.STRING)
val provider : ProviderType,

@Column(nullable = false)
@Enumerated(EnumType.STRING)
var status: MemberStatus = MemberStatus.HOLD,

@Column(name = "role", nullable = false)
@Enumerated(EnumType.STRING)
val role: RoleType,
Expand All @@ -32,5 +38,5 @@ abstract class MemberEntity (
val name : String,

@Column(name = "birth_date", nullable = false)
val birthDate : LocalDate
val birthDate : LocalDate,
) : AuditingEntity()
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.dobby.backend.infrastructure.database.entity

import com.dobby.backend.infrastructure.database.entity.enum.GenderType
import com.dobby.backend.infrastructure.database.entity.enum.MatchType
import com.dobby.backend.infrastructure.database.entity.enum.ProviderType
import com.dobby.backend.infrastructure.database.entity.enum.RoleType
import com.dobby.backend.infrastructure.database.entity.enum.areaInfo.Area
import com.dobby.backend.infrastructure.database.entity.enum.areaInfo.Region
import jakarta.persistence.Column
import jakarta.persistence.DiscriminatorValue
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import java.time.LocalDate

@Entity(name = "participant")
@DiscriminatorValue("PARTICIPANT")
class Participant (
@Column(name = "gender", nullable = false)
@Enumerated(EnumType.STRING)
val gender: GenderType,

@Column(name = "basic_region", nullable = false)
@Enumerated(EnumType.STRING)
var basicRegion: Region,

@Column(name = "basic_area", nullable = false)
@Enumerated(EnumType.STRING)
var basicArea : Area,

@Column(name = "optional_region", nullable = true)
@Enumerated(EnumType.STRING)
var optionalRegion: Region,

@Column(name = "optional_area", nullable = true)
@Enumerated(EnumType.STRING)
var optionalArea: Area,

@Column(name = "prefer_type", nullable = true)
@Enumerated(EnumType.STRING)
var preferType: MatchType,

id: Long,
oauthEmail: String,
provider: ProviderType,
contactEmail: String,
name: String,
birthDate: LocalDate
) : Member(
id= id,
oauthEmail = oauthEmail,
provider = provider,
contactEmail= contactEmail,
role = RoleType.PARTICIPANT,
name = name,
birthDate = birthDate
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.dobby.backend.infrastructure.database.entity

import com.dobby.backend.infrastructure.database.entity.enums.ProviderType
import com.dobby.backend.infrastructure.database.entity.enums.RoleType
import com.dobby.backend.infrastructure.database.entity.enum.ProviderType
import com.dobby.backend.infrastructure.database.entity.enum.RoleType
import jakarta.persistence.Column
import jakarta.persistence.DiscriminatorValue
import jakarta.persistence.Entity
import java.time.LocalDate

@Entity(name = "researchers")
class ResearcherEntity (
@Entity(name = "researcher")
@DiscriminatorValue("RESEARCHER")
class Researcher (
@Column(name = "univ_email", length = 100, nullable = false)
val univEmail : String,

Expand All @@ -20,15 +22,21 @@ class ResearcherEntity (
@Column(name = "major", length = 10, nullable = false)
val major : String,

@Column(name = "lab_info", length = 100)
val labInfo : String?,
@Column(name = "lab_info", length = 100, nullable = true)
val labInfo : String,

id: Long,
oauthEmail: String,
contactEmail : String,
provider: ProviderType,
role: RoleType,
contactEmail: String,
name: String,
birthDate: LocalDate
) : MemberEntity(id, oauthEmail, provider, role, contactEmail, name, birthDate)

) : Member(
id= id,
oauthEmail = oauthEmail,
provider = provider,
contactEmail= contactEmail,
role = RoleType.RESEARCHER,
name = name,
birthDate = birthDate
)
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package com.dobby.backend.infrastructure.database.entity.common

import jakarta.persistence.Column
import jakarta.persistence.EntityListeners
import jakarta.persistence.MappedSuperclass
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.LocalDateTime

@MappedSuperclass
@EntityListeners(AuditingEntityListener::class)
abstract class AuditingEntity {
@CreatedDate
@Column(name = "created_at", nullable = false, updatable = false)
var createdAt: LocalDateTime? = null

@LastModifiedDate
@Column(name = "updated_at", nullable = false)
var updatedAt: LocalDateTime? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.dobby.backend.infrastructure.database.entity.enum

enum class GenderType {
MALE, FEMALE, SECRET
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.dobby.backend.infrastructure.database.entity.enum

enum class MatchType {
OFFLINE, ONLINE, HYBRID
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.dobby.backend.infrastructure.database.entity.enum

enum class MemberStatus {
HOLD,
ACTIVE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.dobby.backend.infrastructure.database.entity.enum

enum class ProviderType {
NAVER, GOOGLE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.dobby.backend.infrastructure.database.entity.enum

enum class RoleType {
RESEARCHER, PARTICIPANT
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package com.dobby.backend.infrastructure.database.entity.enums.areaInfo

import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region
package com.dobby.backend.infrastructure.database.entity.enum.areaInfo

enum class Area (val region: Region, val displayName: String){
// 서울
Expand Down Expand Up @@ -264,4 +262,4 @@ enum class Area (val region: Region, val displayName: String){
// 제주특별자치도
JEJU_SEOGWIPOSI(Region.JEJU, "서귀포시"),
JEJU_JEJUSI(Region.JEJU, "제주시");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dobby.backend.infrastructure.database.entity.enums.areaInfo
package com.dobby.backend.infrastructure.database.entity.enum.areaInfo

enum class Region(val displayName: String) {
SEOUL("서울"),
Expand All @@ -20,8 +20,9 @@ enum class Region(val displayName: String) {
JEJU("제주");

companion object {
private val displayNameMap = values().associateBy(Region::displayName)
fun fromDisplayName(name : String): Region? {
return entries.find { it.displayName == name }
return displayNameMap[name]
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit b628066

Please sign in to comment.