Skip to content

Commit

Permalink
네이밍 일부 수정 (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leafguyk authored Jan 29, 2025
1 parent 6186325 commit 904b294
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TagNotFoundException : CustomException(
httpErrorCode = HttpStatus.NOT_FOUND,
msg = "존재하지 않는 태그입니다."
)
class WrongUserException : CustomException(
class TagNotOwnedByUserException : CustomException(
errorCode = 0,
httpErrorCode = HttpStatus.FORBIDDEN,
msg = "유저가 가지고 있는 태그가 아닙니다."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.wafflestudio.toyproject.memoWithTags.tag.service

import com.wafflestudio.toyproject.memoWithTags.exception.AuthenticationFailedException
import com.wafflestudio.toyproject.memoWithTags.exception.TagNotFoundException
import com.wafflestudio.toyproject.memoWithTags.exception.WrongUserException
import com.wafflestudio.toyproject.memoWithTags.exception.TagNotOwnedByUserException
import com.wafflestudio.toyproject.memoWithTags.tag.controller.Tag
import com.wafflestudio.toyproject.memoWithTags.tag.persistence.TagEntity
import com.wafflestudio.toyproject.memoWithTags.tag.persistence.TagRepository
Expand Down Expand Up @@ -30,7 +30,7 @@ class TagService(
fun updateTag(id: Long, name: String, colorHex: String, user: User): Tag {
val tagEntity = tagRepository.findById(id).orElseThrow { throw TagNotFoundException() }
if (tagEntity.user.email != user.email) {
throw WrongUserException()
throw TagNotOwnedByUserException()
}
tagEntity.name = name
tagEntity.colorHex = colorHex
Expand All @@ -42,7 +42,7 @@ class TagService(
fun deleteTag(tagId: Long, user: User) {
val tagEntity = tagRepository.findById(tagId).orElseThrow { throw TagNotFoundException() }
if (tagEntity.user.email != user.email) {
throw WrongUserException()
throw TagNotOwnedByUserException()
}
tagRepository.delete(tagEntity)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AdminController(
@Operation(summary = "유저 목록 가져오기")
@GetMapping("/admin/user")
fun getUsers(@AuthUser user: User): List<User> {
adminService.isAdmin(user.id)
adminService.assertAdminRole(user.id)
return adminService.getUsers()
}

Expand All @@ -42,15 +42,15 @@ class AdminController(
@Operation(summary = "유저 계정 삭제하기")
@DeleteMapping("/admin/user/{userId}")
fun deleteUser(@AuthUser user: User, @PathVariable userId: UUID): ResponseEntity<Unit> {
adminService.isAdmin(user.id)
adminService.assertAdminRole(user.id)
adminService.deleteUser(userId)
return ResponseEntity.ok().build()
}

@Operation(summary = "유저 계정 업데이트")
@PutMapping("/admin/user")
fun getUsers(@AuthUser user: User, @RequestBody request: UpdateUserRequest): User {
adminService.isAdmin(user.id)
adminService.assertAdminRole(user.id)
return adminService.updateUser(request.id, request.userUpdateInfo)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class AdminService(
private val userRepository: UserRepository
) {
/**
* 관리자 여부를 리턴하는 함수
* 관리자가 아닐경우 예외를 발생시키는 함수
*/
fun isAdmin(userId: UUID) {
fun assertAdminRole(userId: UUID) {
val userEntity = userRepository.findById(userId).orElseThrow { UserNotFoundException() }
if (userEntity.role != RoleType.ROLE_ADMIN) {
throw UserNotAdminException()
Expand Down

0 comments on commit 904b294

Please sign in to comment.