Fix api
This commit is contained in:
16
lib/api.dart
16
lib/api.dart
@@ -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,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user