Skip to content

Commit

Permalink
🔨 Check nickname conflict in editProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
wonseok committed Jan 31, 2025
1 parent 6712808 commit 3e6d91f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ class ProfileNotFoundException : ProfileException(
httpStatusCode = HttpStatus.NOT_FOUND,
msg = "Profile not found",
)

class ProfileEditNicknameConflictException : ProfileException(
errorCode = 0,
httpStatusCode = HttpStatus.CONFLICT,
msg = "Nickname conflict",
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import com.toyProject7.karrot.article.service.ArticleService
import com.toyProject7.karrot.image.persistence.ImageUrlEntity
import com.toyProject7.karrot.image.service.ImageService
import com.toyProject7.karrot.manner.controller.Manner
import com.toyProject7.karrot.profile.ProfileEditNicknameConflictException
import com.toyProject7.karrot.profile.ProfileNotFoundException
import com.toyProject7.karrot.profile.controller.EditProfileRequest
import com.toyProject7.karrot.profile.controller.Profile
import com.toyProject7.karrot.profile.persistence.ProfileEntity
import com.toyProject7.karrot.profile.persistence.ProfileRepository
import com.toyProject7.karrot.review.controller.Review
import com.toyProject7.karrot.review.service.ReviewService
import com.toyProject7.karrot.user.controller.User
import com.toyProject7.karrot.user.persistence.UserEntity
import com.toyProject7.karrot.user.service.UserService
import org.springframework.context.annotation.Lazy
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.Instant
Expand All @@ -28,7 +27,6 @@ class ProfileService(
private val userService: UserService,
private val articleService: ArticleService,
private val imageService: ImageService,
@Lazy private val reviewService: ReviewService,
) {
@Transactional
fun getMyProfile(user: User): Profile {
Expand Down Expand Up @@ -71,6 +69,10 @@ class ProfileService(
user: User,
request: EditProfileRequest,
): Profile {
if (userService.existUserEntityByNickname(request.nickname)) {
throw ProfileEditNicknameConflictException()
}

val userEntity = userService.getUserEntityById(user.id)
val profileEntity = profileRepository.findByUserId(user.id) ?: throw ProfileNotFoundException()
val itemCount = getItemCount(user.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,9 @@ class UserService(
fun getUserEntityByNickname(nickname: String): UserEntity {
return userRepository.findByNickname(nickname) ?: throw UserNotFoundException()
}

@Transactional
fun existUserEntityByNickname(nickname: String): Boolean {
return userRepository.existsByNickname(nickname)
}
}

0 comments on commit 3e6d91f

Please sign in to comment.