2023-12-29 23:45:33 +00:00
|
|
|
import '../models/package.dart';
|
2023-12-29 17:13:51 +00:00
|
|
|
import 'api_client.dart';
|
|
|
|
|
|
|
|
extension PackagesAPI on ApiClient {
|
2024-01-19 19:00:10 +00:00
|
|
|
Future<List<Package>> listPackages({int? limit}) async {
|
|
|
|
final resp = await getRawClient()
|
|
|
|
.get("/packages/list", queryParameters: {'limit': limit});
|
2023-12-29 17:13:51 +00:00
|
|
|
|
|
|
|
final responseObject = resp.data as List;
|
|
|
|
final List<Package> packages =
|
|
|
|
responseObject.map((e) => Package.fromJson(e)).toList(growable: false);
|
|
|
|
return packages;
|
|
|
|
}
|
|
|
|
|
2023-12-30 21:23:42 +00:00
|
|
|
Future<Package> getPackage(int id) async {
|
|
|
|
final resp = await getRawClient().get("/package/$id");
|
|
|
|
|
|
|
|
final package = Package.fromJson(resp.data);
|
|
|
|
return package;
|
|
|
|
}
|
|
|
|
|
2024-02-11 21:28:23 +00:00
|
|
|
Future<void> addPackage({required String name}) async {
|
2024-02-17 18:50:15 +00:00
|
|
|
final resp = await getRawClient().post("/package", data: {'name': name});
|
2024-02-11 21:28:23 +00:00
|
|
|
print(resp.data);
|
|
|
|
}
|
|
|
|
|
2024-02-17 18:50:15 +00:00
|
|
|
Future<int> updatePackage({bool force = false, required int id}) async {
|
2023-12-29 23:45:33 +00:00
|
|
|
final resp = await getRawClient()
|
2024-02-17 18:50:15 +00:00
|
|
|
.post("/package/$id/update", data: {'force': force});
|
2023-12-29 17:13:51 +00:00
|
|
|
print(resp.data);
|
2024-02-17 18:50:15 +00:00
|
|
|
|
|
|
|
return resp.data as int;
|
2023-12-29 17:13:51 +00:00
|
|
|
}
|
2023-12-30 21:23:42 +00:00
|
|
|
|
|
|
|
Future<bool> deletePackage(int id) async {
|
2024-02-17 18:50:15 +00:00
|
|
|
final resp = await getRawClient().delete("/package/$id");
|
2023-12-30 21:23:42 +00:00
|
|
|
return resp.statusCode == 200;
|
|
|
|
}
|
2023-12-29 17:13:51 +00:00
|
|
|
}
|