-
Notifications
You must be signed in to change notification settings - Fork 1
feature: 회원 도메인 엔티티와 저장소 추가 #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
1 change: 1 addition & 0 deletions
1
src/main/kotlin/com/mogumogu/momogo/group/presentation/.gitkeep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
1 change: 1 addition & 0 deletions
1
src/main/kotlin/com/mogumogu/momogo/photo/presentation/.gitkeep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
70 changes: 70 additions & 0 deletions
70
src/main/kotlin/com/mogumogu/momogo/user/domain/LoginAccount.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package com.mogumogu.momogo.user.domain | ||
|
|
||
| import com.mogumogu.momogo.global.entity.BaseEntity | ||
| import jakarta.persistence.Column | ||
| import jakarta.persistence.Entity | ||
| import jakarta.persistence.EnumType | ||
| import jakarta.persistence.Enumerated | ||
| import jakarta.persistence.FetchType | ||
| import jakarta.persistence.ForeignKey | ||
| import jakarta.persistence.GeneratedValue | ||
| import jakarta.persistence.GenerationType | ||
| import jakarta.persistence.Id | ||
| import jakarta.persistence.JoinColumn | ||
| import jakarta.persistence.ManyToOne | ||
| import jakarta.persistence.Table | ||
|
|
||
| @Entity | ||
| @Table(name = "login_account") | ||
| class LoginAccount( | ||
| @field:Id | ||
| @field:GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @field:Column(name = "id") | ||
| private var _id: Long? = null, | ||
|
|
||
| @field:ManyToOne(fetch = FetchType.LAZY, optional = false) | ||
| @field:JoinColumn( | ||
| name = "user_id", | ||
| nullable = false, | ||
| updatable = false, | ||
| foreignKey = ForeignKey(name = "fk_login_account_user"), | ||
| ) | ||
| private var _user: User, | ||
|
|
||
| @field:Enumerated(EnumType.STRING) | ||
| @field:Column( | ||
| name = "provider", | ||
| nullable = false, | ||
| updatable = false, | ||
| length = 255, | ||
| columnDefinition = "VARCHAR(255)", | ||
| ) | ||
| private var _provider: LoginProvider, | ||
|
|
||
| @field:Column(name = "provider_id", nullable = false, updatable = false, length = 255) | ||
| private var _providerId: String, | ||
| ) : BaseEntity() { | ||
|
|
||
| val id: Long? | ||
| get() = _id | ||
|
|
||
| val user: User | ||
| get() = _user | ||
|
|
||
| val provider: LoginProvider | ||
| get() = _provider | ||
|
|
||
| val providerId: String | ||
| get() = _providerId | ||
|
|
||
| init { | ||
| validateProviderId(_providerId) | ||
| } | ||
|
|
||
| private companion object { | ||
| fun validateProviderId(providerId: String) { | ||
| require(providerId.isNotBlank()) { "로그인 제공자 회원 ID는 비어 있을 수 없습니다." } | ||
| require(providerId.length <= 255) { "로그인 제공자 회원 ID는 255자를 초과할 수 없습니다." } | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/mogumogu/momogo/user/domain/LoginProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.mogumogu.momogo.user.domain | ||
|
|
||
| enum class LoginProvider { | ||
| GUEST, | ||
| KAKAO, | ||
| NAVER, | ||
| APPLE, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # User Domain | ||
|
|
||
| 회원, 로그인 계정, 리프레시 토큰과 관련된 도메인 규칙을 관리하는 패키지다. | ||
| 도메인 모델과 JPA 엔티티는 하나의 클래스로 구성하며, 엔티티가 자신의 상태와 비즈니스 규칙을 직접 관리한다. | ||
|
|
||
| ## 구성 | ||
|
|
||
| - `User`: 회원 정보와 닉네임 변경 규칙 | ||
| - `LoginAccount`: 회원과 로그인 제공자 계정의 연결 | ||
| - `LoginProvider`: 지원하는 로그인 제공자 | ||
| - `RefreshToken`: 리프레시 토큰의 만료 및 폐기 상태 | ||
|
|
||
| 외부에서는 읽기 전용 getter로 상태를 조회하고, 상태 변경은 엔티티가 제공하는 도메인 함수를 통해서만 수행한다. |
85 changes: 85 additions & 0 deletions
85
src/main/kotlin/com/mogumogu/momogo/user/domain/RefreshToken.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package com.mogumogu.momogo.user.domain | ||
|
|
||
| import com.mogumogu.momogo.global.entity.BaseEntity | ||
| import jakarta.persistence.* | ||
| import java.time.Instant | ||
|
|
||
| @Entity | ||
| @Table( | ||
| name = "refresh_token", | ||
| uniqueConstraints = [ | ||
| UniqueConstraint( | ||
| name = "uq_refresh_token_token_hash", | ||
| columnNames = ["token_hash"], | ||
| ), | ||
| ], | ||
| ) | ||
| class RefreshToken( | ||
| @field:Id | ||
| @field:GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @field:Column(name = "id") | ||
| private var _id: Long? = null, | ||
|
|
||
| @field:ManyToOne(fetch = FetchType.LAZY, optional = false) | ||
| @field:JoinColumn( | ||
| name = "user_id", | ||
| nullable = false, | ||
| updatable = false, | ||
| foreignKey = ForeignKey(name = "fk_refresh_token_user"), | ||
| ) | ||
| private var _user: User, | ||
|
|
||
| @field:Column( | ||
| name = "token_hash", | ||
| nullable = false, | ||
| updatable = false, | ||
| length = 64, | ||
| columnDefinition = "CHAR(64)", | ||
| ) | ||
| private var _tokenHash: String, | ||
|
|
||
| @field:Column(name = "expires_at", nullable = false, updatable = false) | ||
| private var _expiresAt: Instant, | ||
|
|
||
| @field:Column(name = "revoked_at") | ||
| private var _revokedAt: Instant? = null, | ||
| ) : BaseEntity() { | ||
|
|
||
| val id: Long? | ||
| get() = _id | ||
|
|
||
| val user: User | ||
| get() = _user | ||
|
|
||
| val tokenHash: String | ||
| get() = _tokenHash | ||
|
|
||
| val expiresAt: Instant | ||
| get() = _expiresAt | ||
|
|
||
| val revokedAt: Instant? | ||
| get() = _revokedAt | ||
|
|
||
| init { | ||
| validateTokenHash(_tokenHash) | ||
| } | ||
|
|
||
| fun revoke(at: Instant) { | ||
| if (_revokedAt == null) { | ||
| _revokedAt = at | ||
| } | ||
| } | ||
|
|
||
| fun isActive(at: Instant): Boolean = | ||
| _revokedAt == null && _expiresAt.isAfter(at) | ||
|
|
||
| private companion object { | ||
| private val SHA_256_PATTERN = Regex("^[0-9a-fA-F]{64}$") | ||
|
|
||
| fun validateTokenHash(tokenHash: String) { | ||
| require(SHA_256_PATTERN.matches(tokenHash)) { | ||
| "리프레시 토큰 해시는 64자리 16진수여야 합니다." | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.mogumogu.momogo.user.domain | ||
|
|
||
| import com.mogumogu.momogo.global.entity.BaseEntity | ||
| import jakarta.persistence.Column | ||
| import jakarta.persistence.Entity | ||
| import jakarta.persistence.GeneratedValue | ||
| import jakarta.persistence.GenerationType | ||
| import jakarta.persistence.Id | ||
| import jakarta.persistence.Table | ||
|
|
||
| @Entity | ||
| @Table(name = "\"user\"") | ||
| class User( | ||
| @field:Id | ||
| @field:GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @field:Column(name = "id") | ||
| private var _id: Long? = null, | ||
|
|
||
| @field:Column(name = "nickname", nullable = false, length = 255) | ||
| private var _nickname: String, | ||
| ) : BaseEntity() { | ||
|
|
||
| val id: Long? | ||
| get() = _id | ||
|
|
||
| val nickname: String | ||
| get() = _nickname | ||
|
|
||
| init { | ||
| validateNickname(_nickname) | ||
| } | ||
|
|
||
| fun updateNickname(nickname: String) { | ||
| validateNickname(nickname) | ||
| _nickname = nickname | ||
| } | ||
|
|
||
| private companion object { | ||
| fun validateNickname(nickname: String) { | ||
| require(nickname.isNotBlank()) { "닉네임은 비어 있을 수 없습니다." } | ||
| require(nickname.length <= 255) { "닉네임은 255자를 초과할 수 없습니다." } | ||
| } | ||
| } | ||
| } | ||
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/mogumogu/momogo/user/infra/LoginAccountRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.mogumogu.momogo.user.infra | ||
|
|
||
| import com.mogumogu.momogo.user.domain.LoginAccount | ||
| import org.springframework.data.jpa.repository.JpaRepository | ||
|
|
||
| interface LoginAccountRepository : JpaRepository<LoginAccount, Long> |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/mogumogu/momogo/user/infra/RefreshTokenRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.mogumogu.momogo.user.infra | ||
|
|
||
| import com.mogumogu.momogo.user.domain.RefreshToken | ||
| import org.springframework.data.jpa.repository.JpaRepository | ||
|
|
||
| interface RefreshTokenRepository : JpaRepository<RefreshToken, Long> |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/mogumogu/momogo/user/infra/UserRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.mogumogu.momogo.user.infra | ||
|
|
||
| import com.mogumogu.momogo.user.domain.User | ||
| import org.springframework.data.jpa.repository.JpaRepository | ||
|
|
||
| interface UserRepository : JpaRepository<User, Long> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
57 changes: 57 additions & 0 deletions
57
src/test/kotlin/com/mogumogu/momogo/user/domain/LoginAccountTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package com.mogumogu.momogo.user.domain | ||
|
|
||
| import io.kotest.assertions.throwables.shouldThrow | ||
| import io.kotest.core.spec.style.BehaviorSpec | ||
| import io.kotest.matchers.shouldBe | ||
|
|
||
| class LoginAccountTest : BehaviorSpec({ | ||
|
|
||
| given("유효한 로그인 계정 정보가 있으면") { | ||
| `when`("로그인 계정을 생성할 때") { | ||
| then("회원과 로그인 제공자 정보를 조회할 수 있다") { | ||
| val user = User(_nickname = "모고") | ||
| val loginAccount = LoginAccount( | ||
| _id = 1L, | ||
| _user = user, | ||
| _provider = LoginProvider.APPLE, | ||
| _providerId = "apple-user-1", | ||
| ) | ||
|
|
||
| loginAccount.id shouldBe 1L | ||
| loginAccount.user shouldBe user | ||
| loginAccount.provider shouldBe LoginProvider.APPLE | ||
| loginAccount.providerId shouldBe "apple-user-1" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| given("유효하지 않은 로그인 제공자 회원 ID가 있으면") { | ||
| val user = User(_nickname = "모고") | ||
|
|
||
| `when`("빈 값으로 로그인 계정을 생성할 때") { | ||
| then("생성을 거부한다") { | ||
| listOf("", " ", "\t").forEach { providerId -> | ||
| shouldThrow<IllegalArgumentException> { | ||
| LoginAccount( | ||
| _user = user, | ||
| _provider = LoginProvider.GUEST, | ||
| _providerId = providerId, | ||
| ) | ||
| }.message shouldBe "로그인 제공자 회원 ID는 비어 있을 수 없습니다." | ||
| } | ||
| } | ||
| } | ||
|
|
||
| `when`("255자를 초과한 값으로 로그인 계정을 생성할 때") { | ||
| then("생성을 거부한다") { | ||
| shouldThrow<IllegalArgumentException> { | ||
| LoginAccount( | ||
| _user = user, | ||
| _provider = LoginProvider.KAKAO, | ||
| _providerId = "a".repeat(256), | ||
| ) | ||
| }.message shouldBe "로그인 제공자 회원 ID는 255자를 초과할 수 없습니다." | ||
| } | ||
| } | ||
| } | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dev와prod프로필은ddl-auto: validate를 사용하지만, 저장소 전체를 확인해도user,login_account,refresh_token테이블을 만드는 SQL 또는 마이그레이션 도구 설정이 없습니다. 따라서 이전 커밋의 데이터베이스로 이 버전을 시작하면 Hibernate 스키마 검증에서 필수 테이블이 없다는 오류가 발생해 애플리케이션이 기동되지 않으므로, 엔티티와 함께 운영 스키마 마이그레이션을 제공해야 합니다.AGENTS.md reference: AGENTS.md:L88-L88
Useful? React with 👍 / 👎.