-
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 branch 'feature/DRAW-427' into sandbox
- Loading branch information
Showing
14 changed files
with
175 additions
and
17 deletions.
There are no files selected for viewing
16 changes: 8 additions & 8 deletions
16
adapter/oauth/src/main/kotlin/com/xorker/draw/oauth/google/GoogleApiProperties.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 |
---|---|---|
@@ -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, | ||
) |
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
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 | ||
|
@@ -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)) | ||
|
@@ -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 | ||
) | ||
} |
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
39 changes: 39 additions & 0 deletions
39
app/api/src/main/kotlin/com/xorker/draw/user/UserController.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,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() | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
app/api/src/main/kotlin/com/xorker/draw/user/dto/UpdateUserRequest.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,5 @@ | ||
package com.xorker.draw.user.dto | ||
|
||
data class UpdateUserRequest( | ||
val nickname: String, | ||
) |
22 changes: 22 additions & 0 deletions
22
app/api/src/main/kotlin/com/xorker/draw/user/dto/UserDetailResponse.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 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
14
app/api/src/main/kotlin/com/xorker/draw/user/dto/UserResponse.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,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, | ||
) |
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,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) | ||
} | ||
} |
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 com.xorker.draw.user | ||
|
||
interface UserUseCase { | ||
fun getUserDetail(userId: UserId): UserDetail | ||
|
||
fun updateUser(userId: UserId, nickname: String): User | ||
} |
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,6 @@ | ||
package com.xorker.draw.auth | ||
|
||
data class AuthInfo( | ||
val authPlatform: AuthPlatform, | ||
val email: String, | ||
) |
16 changes: 8 additions & 8 deletions
16
domain/src/main/kotlin/com/xorker/draw/auth/AuthPlatform.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 |
---|---|---|
@@ -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("구글"), | ||
|
||
; | ||
} |
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
5 changes: 5 additions & 0 deletions
5
domain/src/main/kotlin/com/xorker/draw/user/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 |
---|---|---|
@@ -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 | ||
} |