From 37ae5920b2c6427f1960e549139dd5cfaf26dad1 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Sun, 15 Dec 2024 14:29:32 +0100 Subject: [PATCH] controllers/version: Reuse `load_crate()` fn --- src/controllers/version.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/controllers/version.rs b/src/controllers/version.rs index e6b3d06b23..78921fb37b 100644 --- a/src/controllers/version.rs +++ b/src/controllers/version.rs @@ -8,8 +8,9 @@ use serde::de::Error; use serde::{Deserialize, Deserializer}; use utoipa::IntoParams; +use crate::controllers::krate::load_crate; use crate::models::{Crate, Version}; -use crate::util::errors::{crate_not_found, AppResult}; +use crate::util::errors::AppResult; #[derive(Deserialize, FromRequestParts, IntoParams)] #[into_params(parameter_in = Path)] @@ -41,15 +42,7 @@ async fn version_and_crate( crate_name: &str, semver: &str, ) -> AppResult<(Version, Crate)> { - use diesel::prelude::*; - use diesel_async::RunQueryDsl; - - let krate: Crate = Crate::by_name(crate_name) - .first(conn) - .await - .optional()? - .ok_or_else(|| crate_not_found(crate_name))?; - + let krate = load_crate(conn, crate_name).await?; let version = krate.find_version(conn, semver).await?; Ok((version, krate))