This commit is contained in:
2026-01-24 19:22:03 +01:00
parent 5c948d2010
commit 11140a748a
4 changed files with 47 additions and 40 deletions

View File

@@ -17,15 +17,16 @@ class ApiClient {
Future<void> login(String username, String password) async {
log.info("Logging in...");
final url = '$baseUrl/login';
final url = '$baseUrl/auth/login';
final response = await http.post(
Uri.parse(url),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({'email': username, 'password': password}),
body: jsonEncode({'username': username, 'password': password}),
);
if (response.statusCode == 200) {
token = jsonDecode(response.body);
final responseData = jsonDecode(response.body);
token = responseData['token'];
log.info('Login successful');
} else {
throw Exception(
@@ -55,6 +56,9 @@ class ApiClient {
if (!throwExceptionIfStatusCodeNot200 || response.statusCode == 200) {
return response;
} else {
log.warning(
"Failed get request to '$url'! StatusCode: ${response.statusCode}\nResponseBody: ${response.body}",
);
throw Exception(
'GET request failed: ${response.statusCode} ${response.body}',
);
@@ -120,19 +124,19 @@ class ApiClient {
Future<List<Sheet>> fetchSheets() async {
final response = await get(
"/list/sheets",
"/api/sheets/list",
throwExceptionIfStatusCodeNot200: true,
);
final data = jsonDecode(response.body);
return (data as List<dynamic>)
return (data['sheets'] as List<dynamic>)
.map((sheet) => Sheet.fromJson(sheet as Map<String, dynamic>))
.toList();
}
Future<Uint8List> fetchPdfFileData(String sheetUuid) async {
final response = await get(
'/sheet/pdf/$sheetUuid',
'/api/sheets/get/$sheetUuid',
isBinary: true,
throwExceptionIfStatusCodeNot200: true,
);