Skip to content

Commit

Permalink
controllers/version: Reuse load_crate() fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Dec 15, 2024
1 parent 1e6f1c0 commit 37ae592
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/controllers/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 37ae592

Please sign in to comment.