feat: UserController

This commit is contained in:
Piotr Dec 2024-05-24 19:36:58 +02:00
parent 56162ad895
commit a78ecaeadb
Signed by: stawros
GPG key ID: F89F27AD8F881A91

View file

@ -0,0 +1,36 @@
package eu.ztsh.wymiana.web.controller;
import eu.ztsh.wymiana.model.User;
import eu.ztsh.wymiana.service.UserService;
import eu.ztsh.wymiana.web.model.UserCreateRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/api/user")
public class UserController {
private final UserService userService;
@GetMapping("{pesel}")
public ResponseEntity<User> get(@PathVariable("pesel") String pesel) {
return ResponseEntity.of(userService.get(pesel));
}
@PostMapping
public ResponseEntity<Void> create(@Valid @RequestBody UserCreateRequest request) {
userService.create(request);
return ResponseEntity.status(204).build();
}
}