/
VladIaz
/
UserService
Обзор
Документация
Войти
/
VladIaz
/
UserService
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
main/java/com/example/demo/controller/UserController.java
53 строки
2 KB
VladIaz
upload files
05 авг 2025, 18:56
05 авг 2025, 18:56
4a5edb7
Код
Авторство
О чём код?
package com.example.demo.controller; import com.example.demo.model.User; import com.example.demo.service.UserService; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/api/users") public class UserController { private final UserService userService; public UserController(UserService userService) { this.userService = userService; } @PostMapping public User saveUser(@RequestBody User user) { return userService.saveUser(user); } @GetMapping public Page<User> getUsers( @RequestParam(required = false) String search, Pageable pageable) { return userService.getUsers(search, pageable); } @GetMapping("/{id}") public User getUserById(@PathVariable Long id) { return userService.getUserById(id); } @DeleteMapping("/{id}") public void deleteUser(@PathVariable Long id) { userService.deleteUser(id); } @GetMapping("/search") public Page<User> searchUsers( @RequestParam(required = false) String query, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size ) { return userService.searchUsers( query, PageRequest.of(page, size, Sort.by("fullName")) ); } }