44 lines
1.3 KiB
Java
44 lines
1.3 KiB
Java
package com.vnp.demo.controllers;
|
|
|
|
import java.util.UUID;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
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.ResponseStatus;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import com.vnp.demo.dto.UserCreateRequest;
|
|
import com.vnp.demo.dto.UserResponse;
|
|
import com.vnp.demo.service.UserService;
|
|
|
|
import jakarta.validation.Valid;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/v1/users")
|
|
public class UserController {
|
|
|
|
private final UserService userService;
|
|
|
|
public UserController(UserService userService) {
|
|
this.userService = userService;
|
|
}
|
|
|
|
@PostMapping
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
public UserResponse register(
|
|
@Valid @RequestBody UserCreateRequest request
|
|
) {
|
|
return userService.register(request);
|
|
}
|
|
|
|
@GetMapping("/me")
|
|
public UserResponse getCurrent(
|
|
@AuthenticationPrincipal UUID userId
|
|
) {
|
|
return userService.getCurrent(userId);
|
|
}
|
|
} |