Skip to content

Commit

Permalink
[KAN-38] 유저 조회 API 개발
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkyoungdeok committed May 7, 2024
1 parent 0811673 commit 0a83b2b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ data class InvalidUserResetPasswordStateException(
data class NotEqualTokenException(
override val message: String = "토큰이 일치 하지 않습니다."
) : ServerException(400, message)

data class NotFoundUserException(
override val message: String = "존재 하지 않는 유저 입니다."
) : ServerException(400, message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.restaurant.be.user.domain.service

import com.restaurant.be.common.exception.NotFoundUserException
import com.restaurant.be.user.presentation.dto.GetUserResponse
import com.restaurant.be.user.repository.UserRepository
import org.springframework.stereotype.Service

@Service
class GetUserService(
private val userRepository: UserRepository
) {

fun getUser(userId: Long): GetUserResponse {
val user = userRepository.findById(userId).orElseThrow {
NotFoundUserException()
}

return GetUserResponse(user = user)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.restaurant.be.user.presentation.controller

import com.restaurant.be.common.response.CommonResponse
import com.restaurant.be.user.domain.service.GetUserService
import com.restaurant.be.user.presentation.dto.GetUserResponse
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
Expand All @@ -16,7 +17,9 @@ import org.springframework.web.bind.annotation.RestController
@Api(tags = ["01. User Info"], description = "유저 서비스")
@RestController
@RequestMapping("/api/v1/users")
class GetUserController {
class GetUserController(
private val getUserService: GetUserService
) {

@GetMapping("/{userId}")
@PreAuthorize("hasRole('USER')")
Expand All @@ -26,7 +29,8 @@ class GetUserController {
description = "성공",
content = [Content(schema = Schema(implementation = GetUserResponse::class))]
)
fun getUser(@PathVariable userId: String): CommonResponse<GetUserResponse> {
return CommonResponse.success()
fun getUser(@PathVariable userId: Long): CommonResponse<GetUserResponse> {
val response = getUserService.getUser(userId)
return CommonResponse.success(response)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

package com.restaurant.be.user.presentation.dto

import com.restaurant.be.user.domain.entity.User
import com.restaurant.be.user.presentation.dto.common.UserDto
import io.swagger.v3.oas.annotations.media.Schema

data class GetUserResponse(
@Schema(description = "유저 정보")
val userDto: UserDto
)
) {
constructor(user: User) : this(
userDto = UserDto(
id = user.id ?: 0,
email = user.email,
nickname = user.nickname,
profileImageUrl = user.profileImageUrl
)
)
}

0 comments on commit 0a83b2b

Please sign in to comment.