forked from yandex-praktikum/java-shareit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserController.java
More file actions
47 lines (39 loc) · 1.29 KB
/
UserController.java
File metadata and controls
47 lines (39 loc) · 1.29 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 jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import ru.practicum.shareit.user.dto.UserDto;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/users")
@RequiredArgsConstructor
public class UserController {
private final UserService userService;
@DeleteMapping("/{id}")
public void removeUser(@PathVariable Long id) {
log.info("DELETE request for user ID: {}", id);
userService.delete(id);
}
@GetMapping
public List<UserDto> getAllUsers() {
log.info("GET request for all users");
return userService.findAll();
}
@PatchMapping("/{id}")
public UserDto patchUser(@PathVariable Long id, @RequestBody UserDto dto) {
log.info("PATCH request for user ID: {}", id);
return userService.update(id, dto);
}
@GetMapping("/{id}")
public UserDto getUser(@PathVariable Long id) {
log.info("GET request for user ID: {}", id);
return userService.getById(id);
}
@PostMapping
public UserDto saveUser(@Valid @RequestBody UserDto dto) {
log.info("POST request to create user: {}", dto.getEmail());
return userService.create(dto);
}
}