generated from pricelees/issue-pr-template
feat: 회원, 관리자 및 상태 / 로그인 변경 이력 Entity 정의
This commit is contained in:
parent
75acdc2c2f
commit
c15e0f456e
@ -0,0 +1,55 @@
|
|||||||
|
package roomescape.admin.infrastructure.persistence
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity
|
||||||
|
import jakarta.persistence.EntityListeners
|
||||||
|
import jakarta.persistence.EnumType
|
||||||
|
import jakarta.persistence.Enumerated
|
||||||
|
import jakarta.persistence.Table
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener
|
||||||
|
import roomescape.common.entity.AuditingBaseEntity
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "admin")
|
||||||
|
@EntityListeners(AuditingEntityListener::class)
|
||||||
|
class AdminEntity(
|
||||||
|
id: Long,
|
||||||
|
|
||||||
|
val account: String,
|
||||||
|
var password: String,
|
||||||
|
val name: String,
|
||||||
|
var phone: String,
|
||||||
|
|
||||||
|
@Enumerated(value = EnumType.STRING)
|
||||||
|
var permissionLevel: AdminPermissionLevel
|
||||||
|
|
||||||
|
) : AuditingBaseEntity(id)
|
||||||
|
|
||||||
|
enum class AdminPermissionLevel(
|
||||||
|
val privileges: Set<Privilege>
|
||||||
|
) {
|
||||||
|
FULL_ACCESS(
|
||||||
|
privileges = setOf(Privilege.MANAGE)
|
||||||
|
),
|
||||||
|
WRITABLE(
|
||||||
|
privileges = (Privilege.entries.toSet() - Privilege.MANAGE)
|
||||||
|
),
|
||||||
|
READ_ALL(
|
||||||
|
privileges = setOf(Privilege.READ_DETAIL, Privilege.READ_SUMMARY)
|
||||||
|
),
|
||||||
|
READ_SUMMARY(
|
||||||
|
privileges = setOf(Privilege.READ_SUMMARY)
|
||||||
|
);
|
||||||
|
|
||||||
|
fun hasPrivilege(privilege: Privilege): Boolean {
|
||||||
|
return this == FULL_ACCESS || this.privileges.contains(privilege)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Privilege {
|
||||||
|
MANAGE,
|
||||||
|
CREATE,
|
||||||
|
UPDATE,
|
||||||
|
DELETE,
|
||||||
|
READ_DETAIL,
|
||||||
|
READ_SUMMARY,
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
package roomescape.admin.infrastructure.persistence
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
|
||||||
|
interface AdminRepository : JpaRepository<AdminEntity, Long>
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package roomescape.auth.infrastructure.persistence
|
||||||
|
|
||||||
|
import jakarta.persistence.*
|
||||||
|
import org.springframework.data.annotation.CreatedDate
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener
|
||||||
|
import roomescape.common.dto.PrincipalType
|
||||||
|
import roomescape.common.entity.PersistableBaseEntity
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "login_history")
|
||||||
|
@EntityListeners(AuditingEntityListener::class)
|
||||||
|
class LoginHistoryEntity(
|
||||||
|
id: Long,
|
||||||
|
|
||||||
|
val principalId: Long,
|
||||||
|
|
||||||
|
@Enumerated(value = EnumType.STRING)
|
||||||
|
val principalType: PrincipalType,
|
||||||
|
|
||||||
|
val success: Boolean,
|
||||||
|
val ipAddress: String,
|
||||||
|
val userAgent: String,
|
||||||
|
|
||||||
|
@Column(updatable = false)
|
||||||
|
@CreatedDate
|
||||||
|
var createdAt: LocalDateTime? = null,
|
||||||
|
) : PersistableBaseEntity(id)
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
package roomescape.auth.infrastructure.persistence
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
|
||||||
|
interface LoginHistoryRepository : JpaRepository<LoginHistoryEntity, Long>
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
package roomescape.member.infrastructure.persistence
|
||||||
|
|
||||||
|
import jakarta.persistence.*
|
||||||
|
import roomescape.common.entity.AuditingBaseEntity
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "users")
|
||||||
|
class UserEntity(
|
||||||
|
id: Long,
|
||||||
|
|
||||||
|
val name: String,
|
||||||
|
|
||||||
|
@Column(unique = true)
|
||||||
|
val email: String,
|
||||||
|
|
||||||
|
var password: String,
|
||||||
|
|
||||||
|
@Column(unique = true)
|
||||||
|
var phone: String,
|
||||||
|
|
||||||
|
var regionCode: String?,
|
||||||
|
|
||||||
|
@Enumerated(value = EnumType.STRING)
|
||||||
|
var status: UserStatus
|
||||||
|
): AuditingBaseEntity(id) {
|
||||||
|
|
||||||
|
fun updateStatus(status: UserStatus) {
|
||||||
|
this.status = status
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "user_status_history")
|
||||||
|
class UserStatusHistoryEntity(
|
||||||
|
id: Long,
|
||||||
|
|
||||||
|
val userId: Long,
|
||||||
|
val reason: String,
|
||||||
|
|
||||||
|
@Enumerated(value = EnumType.STRING)
|
||||||
|
val status: UserStatus,
|
||||||
|
) : AuditingBaseEntity(id)
|
||||||
|
|
||||||
|
enum class UserStatus {
|
||||||
|
ACTIVE, DORMANT, WITHDRAWN, SUSPENDED
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package roomescape.member.infrastructure.persistence
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
|
||||||
|
interface UserRepository : JpaRepository<UserEntity, Long>
|
||||||
|
|
||||||
|
interface UserStatusHistoryRepository : JpaRepository<UserStatusHistoryEntity, Long>
|
||||||
Loading…
x
Reference in New Issue
Block a user