store dto from initial apibuilder

fix existence check of pkg add
This commit is contained in:
lukas-heiligenbrunner 2024-02-11 23:05:39 +01:00
parent a6e226c006
commit 9ecbc8a77a
11 changed files with 17 additions and 10 deletions

View File

@ -35,11 +35,7 @@ pub async fn package_add(
// remove leading and trailing whitespaces
let pkg_name = input.name.trim();
let pkg = get_info_by_name(pkg_name)
.await
.map_err(|_| BadRequest(Some("couldn't download package metadata".to_string())))?;
if let None = Packages::find()
if let Some(..) = Packages::find()
.filter(packages::Column::Name.eq(pkg_name))
.one(db)
.await
@ -48,6 +44,10 @@ pub async fn package_add(
return Err(BadRequest(Some("Package already exists".to_string())));
}
let pkg = get_info_by_name(pkg_name)
.await
.map_err(|_| BadRequest(Some("couldn't download package metadata".to_string())))?;
let mut new_package = packages::ActiveModel {
name: Set(pkg_name.to_string()),
status: Set(3),

View File

@ -1,4 +1,4 @@
use crate::repo::repo::{remove_pkg, remove_version};
use crate::repo::repo::{remove_version};
use rocket::{post, State};
use rocket_okapi::openapi;
use sea_orm::DatabaseConnection;

View File

@ -3,7 +3,7 @@ import 'package:flutter/foundation.dart';
class ApiClient {
static const String _apiBase =
kDebugMode ? "http://localhost:8081/api" : "api";
kDebugMode ? "https://aurcache.heili.eu/api" : "api";
final Dio _dio = Dio(BaseOptions(baseUrl: _apiBase));
String? token;

View File

@ -43,7 +43,7 @@ class _APIBuilderState<T extends BaseProvider, K, DTO>
if (widget.interval != null) {
timer = Timer.periodic(widget.interval!, (Timer t) {
Provider.of<T>(context, listen: false)
.refresh(context, dto: widget.dto);
.refresh(context);
});
}
}

View File

@ -2,11 +2,12 @@ import 'package:flutter/material.dart';
abstract class BaseProvider<T, DTO> with ChangeNotifier {
late Future<T> data;
DTO? dto;
loadFuture(context, {DTO? dto});
refresh(context, {DTO? dto}) {
loadFuture(context, dto: dto);
refresh(context) {
loadFuture(context, dto: this.dto);
notifyListeners();
}
}

View File

@ -14,5 +14,6 @@ class AURSearchProvider extends BaseProvider<List<AurPackage>, AurSearchDTO> {
@override
loadFuture(context, {dto}) {
data = API.getAurPackages(dto!.query);
this.dto = dto;
}
}

View File

@ -15,5 +15,6 @@ class BuildProvider extends BaseProvider<Build, BuildDTO> {
loadFuture(context, {dto}) {
// todo search solution to force an exising dto
data = API.getBuild(dto!.buildID);
this.dto = dto;
}
}

View File

@ -16,6 +16,7 @@ class BuildsProvider extends BaseProvider<List<Build>, BuildsDTO> {
loadFuture(context, {dto}) {
if (dto != null) {
data = API.listAllBuilds(pkgID: dto.pkgID, limit: dto.limit);
this.dto = dto;
} else {
data = API.listAllBuilds();
}

View File

@ -15,5 +15,6 @@ class PackageProvider extends BaseProvider<Package, PackageDTO> {
loadFuture(context, {dto}) {
// todo search solution to force an exising dto
data = API.getPackage(dto!.pkgID);
this.dto = dto;
}
}

View File

@ -14,5 +14,6 @@ class PackagesProvider extends BaseProvider<List<Package>, PackagesDTO> {
@override
loadFuture(context, {dto}) {
data = API.listPackages(limit: dto?.limit);
this.dto = dto;
}
}

View File

@ -7,5 +7,6 @@ class StatsProvider extends BaseProvider {
@override
loadFuture(context, {dto}) {
data = API.listStats();
this.dto = dto;
}
}