store dto from initial apibuilder
fix existence check of pkg add
This commit is contained in:
parent
a6e226c006
commit
9ecbc8a77a
@ -35,11 +35,7 @@ pub async fn package_add(
|
|||||||
// remove leading and trailing whitespaces
|
// remove leading and trailing whitespaces
|
||||||
let pkg_name = input.name.trim();
|
let pkg_name = input.name.trim();
|
||||||
|
|
||||||
let pkg = get_info_by_name(pkg_name)
|
if let Some(..) = Packages::find()
|
||||||
.await
|
|
||||||
.map_err(|_| BadRequest(Some("couldn't download package metadata".to_string())))?;
|
|
||||||
|
|
||||||
if let None = Packages::find()
|
|
||||||
.filter(packages::Column::Name.eq(pkg_name))
|
.filter(packages::Column::Name.eq(pkg_name))
|
||||||
.one(db)
|
.one(db)
|
||||||
.await
|
.await
|
||||||
@ -48,6 +44,10 @@ pub async fn package_add(
|
|||||||
return Err(BadRequest(Some("Package already exists".to_string())));
|
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 {
|
let mut new_package = packages::ActiveModel {
|
||||||
name: Set(pkg_name.to_string()),
|
name: Set(pkg_name.to_string()),
|
||||||
status: Set(3),
|
status: Set(3),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::repo::repo::{remove_pkg, remove_version};
|
use crate::repo::repo::{remove_version};
|
||||||
use rocket::{post, State};
|
use rocket::{post, State};
|
||||||
use rocket_okapi::openapi;
|
use rocket_okapi::openapi;
|
||||||
use sea_orm::DatabaseConnection;
|
use sea_orm::DatabaseConnection;
|
||||||
|
@ -3,7 +3,7 @@ import 'package:flutter/foundation.dart';
|
|||||||
|
|
||||||
class ApiClient {
|
class ApiClient {
|
||||||
static const String _apiBase =
|
static const String _apiBase =
|
||||||
kDebugMode ? "http://localhost:8081/api" : "api";
|
kDebugMode ? "https://aurcache.heili.eu/api" : "api";
|
||||||
final Dio _dio = Dio(BaseOptions(baseUrl: _apiBase));
|
final Dio _dio = Dio(BaseOptions(baseUrl: _apiBase));
|
||||||
|
|
||||||
String? token;
|
String? token;
|
||||||
|
@ -43,7 +43,7 @@ class _APIBuilderState<T extends BaseProvider, K, DTO>
|
|||||||
if (widget.interval != null) {
|
if (widget.interval != null) {
|
||||||
timer = Timer.periodic(widget.interval!, (Timer t) {
|
timer = Timer.periodic(widget.interval!, (Timer t) {
|
||||||
Provider.of<T>(context, listen: false)
|
Provider.of<T>(context, listen: false)
|
||||||
.refresh(context, dto: widget.dto);
|
.refresh(context);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,12 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
abstract class BaseProvider<T, DTO> with ChangeNotifier {
|
abstract class BaseProvider<T, DTO> with ChangeNotifier {
|
||||||
late Future<T> data;
|
late Future<T> data;
|
||||||
|
DTO? dto;
|
||||||
|
|
||||||
loadFuture(context, {DTO? dto});
|
loadFuture(context, {DTO? dto});
|
||||||
|
|
||||||
refresh(context, {DTO? dto}) {
|
refresh(context) {
|
||||||
loadFuture(context, dto: dto);
|
loadFuture(context, dto: this.dto);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,5 +14,6 @@ class AURSearchProvider extends BaseProvider<List<AurPackage>, AurSearchDTO> {
|
|||||||
@override
|
@override
|
||||||
loadFuture(context, {dto}) {
|
loadFuture(context, {dto}) {
|
||||||
data = API.getAurPackages(dto!.query);
|
data = API.getAurPackages(dto!.query);
|
||||||
|
this.dto = dto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,5 +15,6 @@ class BuildProvider extends BaseProvider<Build, BuildDTO> {
|
|||||||
loadFuture(context, {dto}) {
|
loadFuture(context, {dto}) {
|
||||||
// todo search solution to force an exising dto
|
// todo search solution to force an exising dto
|
||||||
data = API.getBuild(dto!.buildID);
|
data = API.getBuild(dto!.buildID);
|
||||||
|
this.dto = dto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ class BuildsProvider extends BaseProvider<List<Build>, BuildsDTO> {
|
|||||||
loadFuture(context, {dto}) {
|
loadFuture(context, {dto}) {
|
||||||
if (dto != null) {
|
if (dto != null) {
|
||||||
data = API.listAllBuilds(pkgID: dto.pkgID, limit: dto.limit);
|
data = API.listAllBuilds(pkgID: dto.pkgID, limit: dto.limit);
|
||||||
|
this.dto = dto;
|
||||||
} else {
|
} else {
|
||||||
data = API.listAllBuilds();
|
data = API.listAllBuilds();
|
||||||
}
|
}
|
||||||
|
@ -15,5 +15,6 @@ class PackageProvider extends BaseProvider<Package, PackageDTO> {
|
|||||||
loadFuture(context, {dto}) {
|
loadFuture(context, {dto}) {
|
||||||
// todo search solution to force an exising dto
|
// todo search solution to force an exising dto
|
||||||
data = API.getPackage(dto!.pkgID);
|
data = API.getPackage(dto!.pkgID);
|
||||||
|
this.dto = dto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,5 +14,6 @@ class PackagesProvider extends BaseProvider<List<Package>, PackagesDTO> {
|
|||||||
@override
|
@override
|
||||||
loadFuture(context, {dto}) {
|
loadFuture(context, {dto}) {
|
||||||
data = API.listPackages(limit: dto?.limit);
|
data = API.listPackages(limit: dto?.limit);
|
||||||
|
this.dto = dto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,6 @@ class StatsProvider extends BaseProvider {
|
|||||||
@override
|
@override
|
||||||
loadFuture(context, {dto}) {
|
loadFuture(context, {dto}) {
|
||||||
data = API.listStats();
|
data = API.listStats();
|
||||||
|
this.dto = dto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user