TDMS/server/src/main/java/ru/tubryansk/tdms/controller/UserController.java
Maksim Skobaro c4973aa7fb refactoring
2025-02-02 03:48:18 +03:00

35 lines
1.0 KiB
Java

package ru.tubryansk.tdms.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ru.tubryansk.tdms.dto.UserDTO;
import ru.tubryansk.tdms.service.AuthenticationService;
import ru.tubryansk.tdms.service.CallerService;
import ru.tubryansk.tdms.service.UserService;
@RestController
@RequestMapping("/api/v1/user")
@Slf4j
public class UserController {
@Autowired
private AuthenticationService authenticationService;
@Autowired
private CallerService callerService;
@GetMapping("/current")
public UserDTO getCurrentUser() {
return callerService.getCallerUser().map(user -> UserDTO.from(user, true)).orElse(UserDTO.unauthenticated());
}
@PostMapping("/logout")
public void logout() {
authenticationService.logout();
}
@PostMapping("/login")
public void login(@RequestParam String username, @RequestParam String password) {
authenticationService.login(username, password);
}
}