-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d5882a
commit 01accba
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/restaurant/be/user/domain/service/DeleteUserService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/com/restaurant/be/user/presentation/controller/DeleteUserController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |