Version slugs (#533)

* Version slugs

* Get rid of new field, finish it up
This commit is contained in:
Geometrically
2023-02-15 13:38:37 -07:00
committed by GitHub
parent 8eb9fb1834
commit b056610eaa
6 changed files with 124 additions and 35 deletions

View File

@@ -75,7 +75,8 @@ pub fn projects_config(cfg: &mut web::ServiceConfig) {
.service(
web::scope("{project_id}")
.service(versions::version_list)
.service(projects::dependency_list),
.service(projects::dependency_list)
.service(versions::version_project_get),
),
);
}

View File

@@ -308,7 +308,7 @@ pub async fn get_update_from_hash(
)
.await?;
if let Some(version_id) = version_ids.last() {
if let Some(version_id) = version_ids.first() {
let version_data =
database::models::Version::get_full(*version_id, &**pool)
.await?;
@@ -503,7 +503,7 @@ pub async fn update_files(
)
.await?;
if let Some(latest_version) = updated_versions.last() {
if let Some(latest_version) = updated_versions.first() {
let mut version_ids = version_ids.write().await;
version_ids.insert(*latest_version, row.hash);

View File

@@ -144,6 +144,31 @@ pub async fn version_list(
}
}
// Given a project ID/slug and a version slug
#[get("version/{slug}")]
pub async fn version_project_get(
req: HttpRequest,
info: web::Path<(String, String)>,
pool: web::Data<PgPool>,
) -> Result<HttpResponse, ApiError> {
let id = info.into_inner();
let version_data =
database::models::Version::get_full_from_id_slug(&id.0, &id.1, &**pool)
.await?;
let user_option = get_user_from_headers(req.headers(), &**pool).await.ok();
if let Some(data) = version_data {
if is_authorized_version(&data.inner, &user_option, &pool).await? {
return Ok(
HttpResponse::Ok().json(models::projects::Version::from(data))
);
}
}
Ok(HttpResponse::NotFound().body(""))
}
#[derive(Serialize, Deserialize)]
pub struct VersionIds {
pub ids: String,