From 3e6d91f7d87aae054ebb297909424f04febdb2cd Mon Sep 17 00:00:00 2001 From: wonseok Date: Fri, 31 Jan 2025 14:43:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=A8=20Check=20nickname=20conflict?= =?UTF-8?q?=20in=20editProfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/toyProject7/karrot/profile/ProfileException.kt | 6 ++++++ .../toyProject7/karrot/profile/service/ProfileService.kt | 8 +++++--- .../com/toyProject7/karrot/user/service/UserService.kt | 5 +++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/toyProject7/karrot/profile/ProfileException.kt b/src/main/kotlin/com/toyProject7/karrot/profile/ProfileException.kt index c90a8de..03aa70a 100644 --- a/src/main/kotlin/com/toyProject7/karrot/profile/ProfileException.kt +++ b/src/main/kotlin/com/toyProject7/karrot/profile/ProfileException.kt @@ -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", +) diff --git a/src/main/kotlin/com/toyProject7/karrot/profile/service/ProfileService.kt b/src/main/kotlin/com/toyProject7/karrot/profile/service/ProfileService.kt index 657c8b8..c7b12e2 100644 --- a/src/main/kotlin/com/toyProject7/karrot/profile/service/ProfileService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/profile/service/ProfileService.kt @@ -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 @@ -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 { @@ -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) diff --git a/src/main/kotlin/com/toyProject7/karrot/user/service/UserService.kt b/src/main/kotlin/com/toyProject7/karrot/user/service/UserService.kt index bf5a8e5..bd6269f 100644 --- a/src/main/kotlin/com/toyProject7/karrot/user/service/UserService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/user/service/UserService.kt @@ -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) + } } From 3617a62a299e56d3d860582f3e3d4b32f9fd89b6 Mon Sep 17 00:00:00 2001 From: wonseok Date: Fri, 31 Jan 2025 14:50:16 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=A8=20Delete=20decoding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manner/controller/MannerController.kt | 6 +----- .../profile/controller/ProfileController.kt | 21 ++++--------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/com/toyProject7/karrot/manner/controller/MannerController.kt b/src/main/kotlin/com/toyProject7/karrot/manner/controller/MannerController.kt index 225c1e9..3af6fd2 100644 --- a/src/main/kotlin/com/toyProject7/karrot/manner/controller/MannerController.kt +++ b/src/main/kotlin/com/toyProject7/karrot/manner/controller/MannerController.kt @@ -5,7 +5,6 @@ import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PutMapping import org.springframework.web.bind.annotation.RestController -import java.net.URLDecoder @RestController class MannerController( @@ -16,10 +15,7 @@ class MannerController( @PathVariable nickname: String, @PathVariable mannerType: MannerType, ): ResponseEntity { - // Decode the nickname - val decodedNickname = URLDecoder.decode(nickname, "UTF-8") - - mannerService.increaseMannerCount(decodedNickname, mannerType) + mannerService.increaseMannerCount(nickname, mannerType) return ResponseEntity.noContent().build() } } diff --git a/src/main/kotlin/com/toyProject7/karrot/profile/controller/ProfileController.kt b/src/main/kotlin/com/toyProject7/karrot/profile/controller/ProfileController.kt index 87f90c6..4403a10 100644 --- a/src/main/kotlin/com/toyProject7/karrot/profile/controller/ProfileController.kt +++ b/src/main/kotlin/com/toyProject7/karrot/profile/controller/ProfileController.kt @@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.PutMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController -import java.net.URLDecoder @RestController class ProfileController( @@ -38,10 +37,7 @@ class ProfileController( fun getProfile( @PathVariable nickname: String, ): ResponseEntity { - // Decode nickname - val decodedNickname = URLDecoder.decode(nickname, "UTF-8") - - val profile = profileService.getProfile(decodedNickname) + val profile = profileService.getProfile(nickname) return ResponseEntity.ok(profile) } @@ -50,10 +46,7 @@ class ProfileController( @PathVariable nickname: String, @RequestParam articleId: Long, ): ResponseEntity> { - // Decode nickname - val decodedNickname = URLDecoder.decode(nickname, "UTF-8") - - val itemList: List = profileService.getProfileSells(decodedNickname, articleId) + val itemList: List = profileService.getProfileSells(nickname, articleId) return ResponseEntity.ok(itemList) } @@ -70,10 +63,7 @@ class ProfileController( fun getManners( @PathVariable nickname: String, ): ResponseEntity { - // Decode nickname - val decodedNickname = URLDecoder.decode(nickname, "UTF-8") - - val manners = profileService.getManner(decodedNickname) + val manners = profileService.getManner(nickname) return ResponseEntity.ok(manners) } @@ -82,10 +72,7 @@ class ProfileController( @PathVariable nickname: String, @RequestParam("reviewId") reviewId: Long, ): ResponseEntity { - // Decode nickname - val decodedNickname = URLDecoder.decode(nickname, "UTF-8") - - val reviews = profileService.getPreviousReviews(decodedNickname, reviewId) + val reviews = profileService.getPreviousReviews(nickname, reviewId) return ResponseEntity.ok(reviews) } }