guardia-fa/backend/src/main/java/com/zioinfo/fa/controller/AuthController.java

28 lines
840 B
Java

package com.zioinfo.fa.controller;
import com.zioinfo.fa.service.AuthService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
@RequestMapping("/api/fa/auth")
public class AuthController {
private final AuthService authService;
public AuthController(AuthService authService) {
this.authService = authService;
}
@PostMapping("/login")
public ResponseEntity<Map<String, Object>> login(@RequestBody Map<String, String> req) {
try {
Map<String, Object> result = authService.login(req.get("username"), req.get("password"));
return ResponseEntity.ok(result);
} catch (Exception e) {
return ResponseEntity.status(401).body(Map.of("error", e.getMessage()));
}
}
}