aurcache/frontend/lib/api/packages.dart
lukas-heiligenbrunner a4f1179c94 update api to comply with REST
add delete build endpoint
parse some info to new build view
2024-02-18 14:23:04 +01:00

40 lines
1.1 KiB
Dart

import '../models/package.dart';
import 'api_client.dart';
extension PackagesAPI on ApiClient {
Future<List<Package>> listPackages({int? limit}) async {
final resp = await getRawClient()
.get("/packages/list", queryParameters: {'limit': limit});
final responseObject = resp.data as List;
final List<Package> packages =
responseObject.map((e) => Package.fromJson(e)).toList(growable: false);
return packages;
}
Future<Package> getPackage(int id) async {
final resp = await getRawClient().get("/package/$id");
final package = Package.fromJson(resp.data);
return package;
}
Future<void> addPackage({required String name}) async {
final resp = await getRawClient().post("/package", data: {'name': name});
print(resp.data);
}
Future<int> updatePackage({bool force = false, required int id}) async {
final resp = await getRawClient()
.post("/package/$id/update", data: {'force': force});
print(resp.data);
return resp.data as int;
}
Future<bool> deletePackage(int id) async {
final resp = await getRawClient().delete("/package/$id");
return resp.statusCode == 200;
}
}