diff --git a/src/main/kotlin/com/restaurant/be/common/exception/ServerException.kt b/src/main/kotlin/com/restaurant/be/common/exception/ServerException.kt index b7f4fb6..cd18d17 100644 --- a/src/main/kotlin/com/restaurant/be/common/exception/ServerException.kt +++ b/src/main/kotlin/com/restaurant/be/common/exception/ServerException.kt @@ -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) diff --git a/src/main/kotlin/com/restaurant/be/user/domain/service/GetUserService.kt b/src/main/kotlin/com/restaurant/be/user/domain/service/GetUserService.kt new file mode 100644 index 0000000..5f1d4bb --- /dev/null +++ b/src/main/kotlin/com/restaurant/be/user/domain/service/GetUserService.kt @@ -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) + } +} diff --git a/src/main/kotlin/com/restaurant/be/user/presentation/controller/GetUserController.kt b/src/main/kotlin/com/restaurant/be/user/presentation/controller/GetUserController.kt index 0bb3d05..a9e2b5c 100644 --- a/src/main/kotlin/com/restaurant/be/user/presentation/controller/GetUserController.kt +++ b/src/main/kotlin/com/restaurant/be/user/presentation/controller/GetUserController.kt @@ -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 @@ -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')") @@ -26,7 +29,8 @@ class GetUserController { description = "성공", content = [Content(schema = Schema(implementation = GetUserResponse::class))] ) - fun getUser(@PathVariable userId: String): CommonResponse { - return CommonResponse.success() + fun getUser(@PathVariable userId: Long): CommonResponse { + val response = getUserService.getUser(userId) + return CommonResponse.success(response) } } diff --git a/src/main/kotlin/com/restaurant/be/user/presentation/dto/GetUserDto.kt b/src/main/kotlin/com/restaurant/be/user/presentation/dto/GetUserDto.kt index 5f5d684..118f76d 100644 --- a/src/main/kotlin/com/restaurant/be/user/presentation/dto/GetUserDto.kt +++ b/src/main/kotlin/com/restaurant/be/user/presentation/dto/GetUserDto.kt @@ -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 + ) + ) +}