Skip to content

Commit

Permalink
[KAN-000] 유저 삭제 API
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkyoungdeok committed May 25, 2024
1 parent 7d5882a commit 01accba
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/kotlin/com/restaurant/be/user/domain/entity/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ class User(
this.nickname = request.nickname
this.profileImageUrl = request.profileImageUrl
}

fun delete() {
this.withdrawal = true
this.email = ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.restaurant.be.user.domain.service

import com.restaurant.be.common.exception.NotFoundUserException
import com.restaurant.be.user.repository.UserRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class DeleteUserService(
private val userRepository: UserRepository
) {
@Transactional
fun deleteUser(email: String) {
val user = userRepository.findByEmail(email) ?: throw NotFoundUserException()

user.delete()
userRepository.save(user)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.restaurant.be.user.presentation.controller

import com.restaurant.be.common.response.CommonResponse
import com.restaurant.be.user.domain.service.DeleteUserService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.v3.oas.annotations.responses.ApiResponse
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.security.Principal

@Api(tags = ["01. User Info"], description = "유저 서비스")
@RestController
@RequestMapping("/v1/users")
class DeleteUserController(
private val deleteUserService: DeleteUserService
) {

@DeleteMapping
@PreAuthorize("hasRole('USER')")
@ApiOperation(value = "유저 삭제 API")
@ApiResponse(
responseCode = "200",
description = "성공"
)
fun deleteUser(principal: Principal): CommonResponse<Void> {
deleteUserService.deleteUser(principal.name)
return CommonResponse.success()
}
}

0 comments on commit 01accba

Please sign in to comment.