Add user deleting

This commit is contained in:
Dmitrii Cravcenco
2023-12-10 15:14:30 +02:00
parent ca1c1473a4
commit 8420f15732
5 changed files with 70 additions and 39 deletions

View File

@@ -12,6 +12,7 @@ import com.faf223.expensetrackerfaf.util.exceptions.UserNotCreatedException;
import com.faf223.expensetrackerfaf.util.exceptions.UserNotFoundException;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
@@ -80,5 +81,14 @@ public class UserController {
return ResponseEntity.ok(userMapper.toDto(users));
}
@GetMapping("/delete/{username}")
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<Void> deleteUserByUsername(@PathVariable String username) {
userService.deleteByUsername(username);
return ResponseEntity.status(HttpStatus.OK).build();
}
}