-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathUserController.java
More file actions
47 lines (39 loc) · 1.31 KB
/
UserController.java
File metadata and controls
47 lines (39 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package ru.practicum.shareit.user;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import ru.practicum.shareit.user.dto.UserDto;
import ru.practicum.shareit.user.service.UserService;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/users")
@RequiredArgsConstructor
public class UserController {
private final UserService userService;
@GetMapping
public List<UserDto> findAll() {
log.info("GET /users");
return userService.findAll();
}
@GetMapping("/{id}")
public UserDto findById(@PathVariable Long id) {
log.info("GET /users/{}", id);
return userService.findById(id);
}
@PostMapping
public UserDto create(@RequestBody UserDto userDto) {
log.info("POST /users - создание пользователя");
return userService.create(userDto);
}
@PatchMapping("/{id}")
public UserDto update(@PathVariable Long id, @RequestBody UserDto userDto) {
log.info("PATCH /users/{} - обновление пользователя", id);
return userService.update(id, userDto);
}
@DeleteMapping("/{id}")
public void delete(@PathVariable Long id) {
log.info("DELETE /users/{}", id);
userService.delete(id);
}
}