91.2. Refactored delete method to use userId instead of id (#10)
This commit is contained in:
@ -96,10 +96,10 @@ public class UserResource {
|
||||
.build();
|
||||
}
|
||||
|
||||
@DeleteMapping("{id}")
|
||||
@DeleteMapping("{userId}")
|
||||
@PreAuthorize("hasAuthority('user:delete')")
|
||||
public HttpResponse deleteUser(@PathVariable long id) {
|
||||
userService.deleteUser(id);
|
||||
public HttpResponse deleteUser(@PathVariable String userId) {
|
||||
userService.deleteUser(userId);
|
||||
return HttpResponse.builder()
|
||||
.httpStatusCode(OK.value())
|
||||
.httpStatus(OK)
|
||||
|
||||
@ -15,4 +15,6 @@ public interface UserRepository extends JpaRepository<User, Long> {
|
||||
|
||||
Boolean existsByEmail(String email);
|
||||
|
||||
Optional<User> findByUserId(String userId);
|
||||
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ public interface UserService extends UserDetailsService {
|
||||
|
||||
User updateUser(String username, UserDto userDto);
|
||||
|
||||
void deleteUser(long id);
|
||||
void deleteUser(String userId);
|
||||
|
||||
void resetPassword(String email);
|
||||
|
||||
|
||||
@ -218,8 +218,11 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUser(long id) {
|
||||
userRepository.deleteById(id);
|
||||
public void deleteUser(String userId) {
|
||||
User userToBeDeleted = userRepository
|
||||
.findByUserId(userId)
|
||||
.orElseThrow(() -> new UserNotFoundException("User was not found"));
|
||||
userRepository.delete(userToBeDeleted);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user