aurcache/frontend/lib/api/packages.dart

32 lines
944 B
Dart
Raw Normal View History

import '../models/package.dart';
2023-12-29 17:13:51 +00:00
import 'api_client.dart';
extension PackagesAPI on ApiClient {
Future<List<Package>> listPackages() async {
final resp = await getRawClient().get("/packages/list");
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;
}
2023-12-29 17:13:51 +00:00
Future<void> addPackage({bool force = false, required String name}) async {
final resp = await getRawClient()
.post("/packages/add", data: {'force_build': force, 'name': name});
2023-12-29 17:13:51 +00:00
print(resp.data);
}
Future<bool> deletePackage(int id) async {
final resp = await getRawClient().post("/package/delete/$id");
return resp.statusCode == 200;
}
2023-12-29 17:13:51 +00:00
}