package com.walkguide.controller; import org.springframework.http.ResponseEntity; 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; import com.walkguide.dto.AuthRequest; import com.walkguide.dto.AuthResponse; import com.walkguide.service.AuthService; import lombok.RequiredArgsConstructor; @RestController @RequestMapping("/api/auth") // Ini URL awalnya @RequiredArgsConstructor public class AuthController { private final AuthService authService; // Ini URL lengkapnya jadi POST http://localhost:8080/api/auth/login @PostMapping("/login") public ResponseEntity login(@RequestBody AuthRequest request) { try { // Lempar kardus AuthRequest ke Service AuthResponse response = authService.login(request); // Kalau sukses, kirim status 200 OK + isinya return ResponseEntity.ok(response); } catch (RuntimeException e) { // Kalau gagal (password salah/email gak ada), kirim status 401 Unauthorized return ResponseEntity.status(401).body(e.getMessage()); } } }