schema fix

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Sven laptop
2026-05-05 19:55:51 +02:00
parent c847d32743
commit 8d4e8b3075
7 changed files with 99 additions and 44 deletions
+14 -7
View File
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:ffi';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
import '../models/user.dart';
@@ -6,7 +7,7 @@ import '../models/user.dart';
/// Authentication Service
class AuthService {
// TODO: Implement API connector - configure base URL from env/config
static const String _apiBaseUrl = 'http://localhost:5000';
static const String _apiBaseUrl = 'http://192.168.2.66:5000';
static const String _tokenKey = 'auth_token';
late SharedPreferences _prefs;
@@ -17,7 +18,7 @@ class AuthService {
/// Login with userCode and password
Future<AuthResponse> login({
required String userCode,
required int userCode,
required String password,
}) async {
await _initPrefs();
@@ -33,13 +34,19 @@ class AuthService {
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body) as Map<String, dynamic>;
final authResponse = AuthResponse.fromJson(data);
final body = response.body;
try {
final data = jsonDecode(body) as Map<String, dynamic>;
final authResponse = AuthResponse.fromJson(data);
// Store token
await _prefs.setString(_tokenKey, authResponse.token);
// Store token
await _prefs.setString(_tokenKey, authResponse.token);
return authResponse;
return authResponse;
} catch (e) {
// Surface the response body to help debug backend field names / formats
throw Exception('Login parse error: $e -- response body: $body');
}
} else if (response.statusCode == 401) {
throw Exception('Invalid credentials');
} else {
@@ -6,7 +6,8 @@ import 'auth_service.dart';
/// Schedule/Route Service
class ScheduleService {
// TODO: Implement API connector - configure base URL from env/config
static const String _apiBaseUrl = 'http://localhost:5000';
// Transit API runs on port 5001
static const String _apiBaseUrl = 'http://192.168.2.66:5001';
final _authService = AuthService();
/// Get daily schedule for a specific date
@@ -43,8 +44,9 @@ class ScheduleService {
try {
final headers = await _authService.getAuthHeaders();
// Transit API exposes route details at /routes/:routeId
final response = await http.get(
Uri.parse('$_apiBaseUrl/schedule/route/$routeId'),
Uri.parse('$_apiBaseUrl/routes/$routeId'),
headers: headers,
);
@@ -66,8 +68,9 @@ class ScheduleService {
try {
final headers = await _authService.getAuthHeaders();
// Transit API updates status at /routes/:routeId/status
final response = await http.patch(
Uri.parse('$_apiBaseUrl/schedule/route/$routeId/status'),
Uri.parse('$_apiBaseUrl/routes/$routeId/status'),
headers: headers,
body: jsonEncode({'status': status}),
);