Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

닉네임 디코딩 제거 / 프로필 수정 닉네임 제한 #77

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -16,10 +15,7 @@ class MannerController(
@PathVariable nickname: String,
@PathVariable mannerType: MannerType,
): ResponseEntity<String> {
// Decode the nickname
val decodedNickname = URLDecoder.decode(nickname, "UTF-8")

mannerService.increaseMannerCount(decodedNickname, mannerType)
mannerService.increaseMannerCount(nickname, mannerType)
return ResponseEntity.noContent().build()
}
}
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 @@ -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(
Expand All @@ -38,10 +37,7 @@ class ProfileController(
fun getProfile(
@PathVariable nickname: String,
): ResponseEntity<ProfileResponse> {
// Decode nickname
val decodedNickname = URLDecoder.decode(nickname, "UTF-8")

val profile = profileService.getProfile(decodedNickname)
val profile = profileService.getProfile(nickname)
return ResponseEntity.ok(profile)
}

Expand All @@ -50,10 +46,7 @@ class ProfileController(
@PathVariable nickname: String,
@RequestParam articleId: Long,
): ResponseEntity<List<Item>> {
// Decode nickname
val decodedNickname = URLDecoder.decode(nickname, "UTF-8")

val itemList: List<Item> = profileService.getProfileSells(decodedNickname, articleId)
val itemList: List<Item> = profileService.getProfileSells(nickname, articleId)
return ResponseEntity.ok(itemList)
}

Expand All @@ -70,10 +63,7 @@ class ProfileController(
fun getManners(
@PathVariable nickname: String,
): ResponseEntity<MannersResponse> {
// Decode nickname
val decodedNickname = URLDecoder.decode(nickname, "UTF-8")

val manners = profileService.getManner(decodedNickname)
val manners = profileService.getManner(nickname)
return ResponseEntity.ok(manners)
}

Expand All @@ -82,10 +72,7 @@ class ProfileController(
@PathVariable nickname: String,
@RequestParam("reviewId") reviewId: Long,
): ResponseEntity<ReviewsResponse> {
// 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)
}
}
Expand Down
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 @@ -179,4 +179,9 @@ class UserService(
fun getUserEntityByNickname(nickname: String): UserEntity {
return userRepository.findByNickname(nickname) ?: throw UserNotFoundException()
}

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