Skip to content

Commit

Permalink
Merge branch 'feature/DRAW-427' into sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
comforest committed Oct 24, 2024
2 parents 17c4d19 + aced893 commit f029334
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.xorker.draw.oauth.google

import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties("oauth.google")
data class GoogleApiProperties(
val clientId: String,
)
package com.xorker.draw.oauth.google

import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties("oauth.google")
data class GoogleApiProperties(
val clientId: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ internal interface AuthUserJpaRepository : JpaRepository<AuthUserJpaEntity, Long
"and au.platform=:platform ",
)
fun find(platform: AuthPlatform, platformUserId: String): AuthUserJpaEntity?

fun findByUserId(userId: Long): AuthUserJpaEntity?
}
18 changes: 18 additions & 0 deletions adapter/rdb/src/main/kotlin/com/xorker/draw/user/UserAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xorker.draw.user

import com.xorker.draw.auth.AuthInfo
import com.xorker.draw.auth.AuthPlatform
import com.xorker.draw.auth.AuthUserJpaEntity
import com.xorker.draw.auth.AuthUserJpaRepository
Expand All @@ -19,6 +20,10 @@ internal class UserAdapter(
override fun getUser(userId: UserId): UserInfo? =
userJpaRepository.findByIdOrNull(userId.value)?.toDomain()

override fun getAuthInfo(userId: UserId): AuthInfo? {
return authUserJpaRepository.findByUserId(userId.value)?.toDomain()
}

override fun createUser(platform: AuthPlatform, platformUserId: String, userName: String): UserInfo {
val user = UserJpaEntity()
val authUser = authUserJpaRepository.save(AuthUserJpaEntity.of(platform, platformUserId, user))
Expand All @@ -37,4 +42,17 @@ internal class UserAdapter(
user.withdrawal()
userJpaRepository.save(user)
}

@Transactional
override fun updateNickname(userId: UserId, nickname: String): User {
val user = userJpaRepository.findByIdOrNull(userId.value) ?: throw NotFoundUserException

user.name = nickname
return userJpaRepository.save(user).toUser()
}

private fun AuthUserJpaEntity.toDomain(): AuthInfo = AuthInfo(
this.platform,
"[email protected]", // TODO
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.xorker.draw.user

import com.xorker.draw.BaseJpaEntity
import com.xorker.draw.exception.InvalidUserStatusException
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
Expand All @@ -19,7 +20,6 @@ internal class UserJpaEntity : BaseJpaEntity() {

@Column(name = "name")
var name: String? = null
protected set

@Column(name = "deleted")
var deleted: Boolean = false
Expand Down Expand Up @@ -53,6 +53,11 @@ internal class UserJpaEntity : BaseJpaEntity() {
}
}

internal fun UserJpaEntity.toUser(): User = User(
id = UserId(this.id),
name = this.name ?: throw InvalidUserStatusException,
)

internal fun UserJpaEntity.toDomain(): UserInfo = UserInfo(
id = UserId(this.id),
name = this.name,
Expand Down
39 changes: 39 additions & 0 deletions app/api/src/main/kotlin/com/xorker/draw/user/UserController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.xorker.draw.user

import com.xorker.draw.support.auth.NeedLogin
import com.xorker.draw.support.auth.PrincipalUser
import com.xorker.draw.user.dto.UpdateUserRequest
import com.xorker.draw.user.dto.UserDetailResponse
import com.xorker.draw.user.dto.UserResponse
import com.xorker.draw.user.dto.toResponse
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController

@Tag(name = "유저 관련 API")
@RestController
class UserController(
private val userUseCase: UserUseCase,
) {
@Operation(summary = "유저 상세 정보 조회")
@GetMapping("/api/v1/user")
@NeedLogin
fun getUserDetail(
user: PrincipalUser,
): UserDetailResponse {
return userUseCase.getUserDetail(user.userId).toResponse()
}

@Operation(summary = "유저 정보 수정")
@PatchMapping("/api/v1/user")
@NeedLogin
fun updateNickname(
user: PrincipalUser,
@RequestBody request: UpdateUserRequest,
): UserResponse {
return userUseCase.updateUser(user.userId, request.nickname).toResponse()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.xorker.draw.user.dto

data class UpdateUserRequest(
val nickname: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.xorker.draw.user.dto

import com.xorker.draw.auth.AuthPlatform
import com.xorker.draw.user.UserDetail
import com.xorker.draw.user.UserId
import io.swagger.v3.oas.annotations.media.Schema

data class UserDetailResponse(
val id: UserId,
val nickname: String?,

@Schema(description = "null 일 경우 게스트")
val authPlatform: AuthPlatform?,
val email: String?,
)

fun UserDetail.toResponse(): UserDetailResponse = UserDetailResponse(
id = this.id,
nickname = this.name,
authPlatform = this.authPlatform,
email = this.email,
)
14 changes: 14 additions & 0 deletions app/api/src/main/kotlin/com/xorker/draw/user/dto/UserResponse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.xorker.draw.user.dto

import com.xorker.draw.user.User
import com.xorker.draw.user.UserId

data class UserResponse(
val id: UserId,
val nickname: String,
)

fun User.toResponse(): UserResponse = UserResponse(
id = this.id,
nickname = this.name,
)
26 changes: 26 additions & 0 deletions core/src/main/kotlin/com/xorker/draw/user/UserService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.xorker.draw.user

import com.xorker.draw.exception.NotFoundUserException
import org.springframework.stereotype.Service

@Service
internal class UserService(
private val userRepository: UserRepository,
) : UserUseCase {
override fun getUserDetail(userId: UserId): UserDetail {
val userInfo = userRepository.getUser(userId) ?: throw NotFoundUserException

val authInfo = userRepository.getAuthInfo(userId)

return UserDetail(
userId,
userInfo.name,
authInfo?.email,
authInfo?.authPlatform,
)
}

override fun updateUser(userId: UserId, nickname: String): User {
return userRepository.updateNickname(userId, nickname)
}
}
7 changes: 7 additions & 0 deletions core/src/main/kotlin/com/xorker/draw/user/UserUseCase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.xorker.draw.user

interface UserUseCase {
fun getUserDetail(userId: UserId): UserDetail

fun updateUser(userId: UserId, nickname: String): User
}
6 changes: 6 additions & 0 deletions domain/src/main/kotlin/com/xorker/draw/auth/AuthInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.xorker.draw.auth

data class AuthInfo(
val authPlatform: AuthPlatform,
val email: String,
)
16 changes: 8 additions & 8 deletions domain/src/main/kotlin/com/xorker/draw/auth/AuthPlatform.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.xorker.draw.auth

enum class AuthPlatform(description: String) {
APPLE("애플"),
GOOGLE("구글"),

;
}
package com.xorker.draw.auth

enum class AuthPlatform(description: String) {
APPLE("애플"),
GOOGLE("구글"),

;
}
9 changes: 9 additions & 0 deletions domain/src/main/kotlin/com/xorker/draw/user/User.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.xorker.draw.user

import com.xorker.draw.auth.AuthPlatform

@JvmInline
value class UserId(val value: Long)

Expand All @@ -12,3 +14,10 @@ data class UserInfo(
val id: UserId,
val name: String?,
)

data class UserDetail(
val id: UserId,
val name: String?,
val email: String?,
val authPlatform: AuthPlatform?,
)
5 changes: 5 additions & 0 deletions domain/src/main/kotlin/com/xorker/draw/user/UserRepository.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.xorker.draw.user

import com.xorker.draw.auth.AuthInfo
import com.xorker.draw.auth.AuthPlatform

interface UserRepository {
fun getUser(platform: AuthPlatform, platformUserId: String): UserInfo?

fun getUser(userId: UserId): UserInfo?

fun getAuthInfo(userId: UserId): AuthInfo?

fun createUser(platform: AuthPlatform, platformUserId: String, userName: String): UserInfo

fun createUser(userName: String?): UserInfo

fun withdrawal(userId: UserId)

fun updateNickname(userId: UserId, nickname: String): User
}

0 comments on commit f029334

Please sign in to comment.