-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from MEOGO-DSM/3-user
🏄 :: (Meogo-3) user
- Loading branch information
Showing
8 changed files
with
100 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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,29 @@ | ||
package org.meogo.domain.user.domain | ||
|
||
import org.meogo.global.base.BaseUUIDEntity | ||
import java.util.UUID | ||
import javax.persistence.Column | ||
import javax.persistence.Entity | ||
import javax.persistence.EnumType | ||
import javax.persistence.Enumerated | ||
|
||
@Entity | ||
class User( | ||
id: UUID? = null, | ||
|
||
@Column(nullable = false, length = 4) | ||
val name: String, | ||
|
||
@Column(name = "account_id", nullable = false, length = 15, unique = true) | ||
val accountId: String, | ||
|
||
val password: String, | ||
|
||
@Column(name = "enrolled_school", nullable = true) | ||
val enrolledSchool: Int? = 0, | ||
|
||
val profile: String? = null, | ||
|
||
@Enumerated(EnumType.STRING) | ||
val role: UserRole | ||
) : BaseUUIDEntity(id) |
This file contains 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,7 @@ | ||
package org.meogo.domain.user.domain | ||
|
||
enum class UserRole { | ||
MANAGER, | ||
USER, | ||
ADMIN | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/org/meogo/domain/user/exception/UserNotFoundException.kt
This file contains 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 org.meogo.domain.user.exception | ||
|
||
import org.meogo.global.error.exception.ErrorCode | ||
import org.meogo.global.error.exception.MeogoException | ||
|
||
object UserNotFoundException : MeogoException( | ||
ErrorCode.USER_NOT_FOUND | ||
) |
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt
This file contains 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,22 @@ | ||
package org.meogo.domain.user.facade | ||
|
||
import org.meogo.domain.user.domain.User | ||
import org.meogo.domain.user.exception.UserNotFoundException | ||
import org.meogo.domain.user.repository.UserRepository | ||
import org.springframework.security.core.context.SecurityContextHolder | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class UserFacade( | ||
private val userRepository: UserRepository | ||
) { | ||
|
||
fun currentUser(): User? { | ||
val authentication = SecurityContextHolder.getContext().authentication | ||
val accountId = authentication?.name | ||
return accountId?.let { getUserByAccountId(it) } | ||
} | ||
|
||
fun getUserByAccountId(accountId: String): User = | ||
userRepository.findByAccountId(accountId) ?: throw UserNotFoundException | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/org/meogo/domain/user/repository/UserRepository.kt
This file contains 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 @@ | ||
package org.meogo.domain.user.repository | ||
|
||
import org.meogo.domain.user.domain.User | ||
import org.springframework.data.repository.Repository | ||
import java.util.UUID | ||
|
||
interface UserRepository : Repository<User, UUID> { | ||
fun save(entity: User): User | ||
|
||
fun findByAccountId(accountId: String): User? | ||
|
||
fun existsByAccountId(accountId: String): Boolean | ||
} |
This file contains 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 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 was deleted.
Oops, something went wrong.