init latest_aur_version and make it non option
This commit is contained in:
parent
80e2299dc8
commit
5a356e65a7
@ -28,6 +28,10 @@ pub async fn package_add(
|
||||
) -> Result<(), BadRequest<String>> {
|
||||
let db = db as &DatabaseConnection;
|
||||
|
||||
let pkg = get_info_by_name(input.name.clone().as_str())
|
||||
.await
|
||||
.map_err(|_| BadRequest(Some("couldn't download package metadata".to_string())))?;
|
||||
|
||||
let mut pkg_model = match Packages::find()
|
||||
.filter(packages::Column::Name.eq(input.name.clone()))
|
||||
.one(db)
|
||||
@ -38,6 +42,7 @@ pub async fn package_add(
|
||||
let new_package = packages::ActiveModel {
|
||||
name: Set(input.name.clone()),
|
||||
status: Set(0),
|
||||
latest_aur_version: Set(pkg.version.clone()),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
@ -46,10 +51,6 @@ pub async fn package_add(
|
||||
Some(p) => p.into(),
|
||||
};
|
||||
|
||||
let pkg = get_info_by_name(input.name.clone().as_str())
|
||||
.await
|
||||
.map_err(|_| BadRequest(Some("couldn't download package metadata".to_string())))?;
|
||||
|
||||
let version_model = match Versions::find()
|
||||
.filter(versions::Column::Version.eq(pkg.version.clone()))
|
||||
.one(db)
|
||||
|
@ -54,7 +54,7 @@ pub struct ListPackageModel {
|
||||
#[get("/packages/list")]
|
||||
pub async fn package_list(
|
||||
db: &State<DatabaseConnection>,
|
||||
) -> Result<Json<Vec<ListPackageModel>>, String> {
|
||||
) -> Result<Json<Vec<ListPackageModel>>, NotFound<String>> {
|
||||
let db = db as &DatabaseConnection;
|
||||
|
||||
let all: Vec<ListPackageModel> = Packages::find()
|
||||
@ -70,7 +70,7 @@ pub async fn package_list(
|
||||
.into_model::<ListPackageModel>()
|
||||
.all(db)
|
||||
.await
|
||||
.unwrap();
|
||||
.map_err(|e| NotFound(e.to_string()))?;
|
||||
|
||||
Ok(Json(all))
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ pub struct Model {
|
||||
pub status: i32,
|
||||
pub out_of_date: i32,
|
||||
pub latest_version_id: Option<i32>,
|
||||
pub latest_aur_version: Option<String>,
|
||||
pub latest_aur_version: String,
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
@ -46,7 +46,7 @@ async fn aur_check_versions(db: DatabaseConnection) -> anyhow::Result<()> {
|
||||
Some(result) => {
|
||||
let mut package: packages::ActiveModel = package.into();
|
||||
|
||||
package.latest_aur_version = Set(Some(result.version.clone()));
|
||||
package.latest_aur_version = Set(result.version.clone());
|
||||
let _ = package.update(&db).await;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user