Skip to content

Commit

Permalink
add :: userNotFoundException
Browse files Browse the repository at this point in the history
  • Loading branch information
meltapplee committed Oct 8, 2024
1 parent 04ad08f commit c342b3c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.meogo.domain.review.service
import org.meogo.domain.review.domain.ReviewRepository
import org.meogo.domain.review.presentation.dto.response.ReviewListResponse
import org.meogo.domain.review.presentation.dto.response.ReviewResponse
import org.meogo.domain.user.exception.UserNotFoundException
import org.meogo.domain.user.facade.UserFacade
import org.meogo.global.s3.FileUtil
import org.meogo.global.s3.Path
Expand All @@ -23,7 +24,7 @@ class QueryAllBySchoolIdService(
return ReviewListResponse(
count = reviews.size,
reviews = reviews.map { review ->
val user = userFacade.getUserById(review.userId)
val user = userFacade.getUserById(review.userId) ?: throw UserNotFoundException
val profile = fileUtil.generateObjectUrl(user.profile, Path.USER)
val image = review.picture?.split(",")?.map { pic ->
fileUtil.generateObjectUrl(pic.trim(), Path.REVIEW)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class UserFacade(
return accountId?.let { getUserByAccountId(it) }
}

fun getUserByAccountId(accountId: String): User =
fun getUserByAccountId(accountId: String): User? =
userRepository.findByAccountId(accountId)

fun getUserById(id: UUID): User =
fun getUserById(id: UUID): User? =
userRepository.findById(id)
}
3 changes: 2 additions & 1 deletion src/main/kotlin/org/meogo/global/auth/AuthDetailsService.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.meogo.global.auth

import org.meogo.domain.user.exception.UserNotFoundException
import org.meogo.domain.user.facade.UserFacade
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.security.core.userdetails.UserDetailsService
Expand All @@ -10,7 +11,7 @@ class AuthDetailsService(
private val userFacade: UserFacade
) : UserDetailsService {
override fun loadUserByUsername(username: String): UserDetails {
val user = userFacade.getUserByAccountId(username)
val user = userFacade.getUserByAccountId(username) ?: throw UserNotFoundException
return AuthDetails(user.accountId, user.role)
}
}

0 comments on commit c342b3c

Please sign in to comment.