forked from mtusi2026/mtusi2026lab2
48 lines
1.3 KiB
Java
48 lines
1.3 KiB
Java
package org.example.controller;
|
|
|
|
import jakarta.validation.Valid;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.example.dto.create.CreateUserDto;
|
|
import org.example.dto.update.UpdateUserDto;
|
|
import org.example.model.User;
|
|
import org.example.service.UserService;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.UUID;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/v1/users")
|
|
@RequiredArgsConstructor
|
|
public class UserController {
|
|
|
|
private final UserService userService;
|
|
|
|
@PostMapping
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
public User createUser(@Valid @RequestBody CreateUserDto dto) {
|
|
return userService.createUser(dto);
|
|
}
|
|
|
|
@GetMapping("/me")
|
|
public User getCurrentUser() {
|
|
return userService.getCurrentUser();
|
|
}
|
|
|
|
@GetMapping("/{id}")
|
|
public User getUserById(@PathVariable UUID id) {
|
|
return userService.getUserById(id);
|
|
}
|
|
|
|
@PutMapping("/{id}")
|
|
public User updateUser(@PathVariable String id,
|
|
@Valid @RequestBody UpdateUserDto object) {
|
|
return userService.updateUser(id, object);
|
|
}
|
|
|
|
@DeleteMapping("/{id}")
|
|
@ResponseStatus(HttpStatus.NO_CONTENT)
|
|
public void delete(@PathVariable String id) {
|
|
userService.deleteUser(id);
|
|
}
|
|
} |