Skip to content

Commit 594c7cb

Browse files
committed
controllers/krate/metadata: Expose the default_version field
1 parent eb5e759 commit 594c7cb

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/controllers/krate/metadata.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,19 @@ pub async fn show(app: AppState, Path(name): Path<String>, req: Parts) -> AppRes
4545
.transpose()?
4646
.unwrap_or_default();
4747

48-
let (krate, downloads): (Crate, i64) = Crate::by_name(&name)
49-
.inner_join(crate_downloads::table)
50-
.select((Crate::as_select(), crate_downloads::downloads))
51-
.first(conn)
52-
.optional()?
53-
.ok_or_else(|| crate_not_found(&name))?;
48+
let (krate, downloads, default_version): (Crate, i64, Option<String>) =
49+
Crate::by_name(&name)
50+
.inner_join(crate_downloads::table)
51+
.left_join(default_versions::table)
52+
.left_join(versions::table.on(default_versions::version_id.eq(versions::id)))
53+
.select((
54+
Crate::as_select(),
55+
crate_downloads::downloads,
56+
versions::num.nullable(),
57+
))
58+
.first(conn)
59+
.optional()?
60+
.ok_or_else(|| crate_not_found(&name))?;
5461

5562
let versions_publishers_and_audit_actions = if include.versions {
5663
let mut versions_and_publishers: Vec<(Version, Option<User>)> = krate
@@ -120,7 +127,7 @@ pub async fn show(app: AppState, Path(name): Path<String>, req: Parts) -> AppRes
120127

121128
let encodable_crate = EncodableCrate::from(
122129
krate.clone(),
123-
None,
130+
default_version.as_deref(),
124131
top_versions.as_ref(),
125132
ids,
126133
kws.as_deref(),

src/tests/routes/crates/snapshots/crates_io__tests__routes__crates__read__new_name.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ expression: response.json()
88
"badges": null,
99
"categories": null,
1010
"created_at": "[datetime]",
11+
"default_version": "0.99.0",
1112
"description": null,
1213
"documentation": null,
1314
"downloads": 0,

src/tests/routes/crates/snapshots/crates_io__tests__routes__crates__read__show.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ expression: response.json()
88
"badges": [],
99
"categories": [],
1010
"created_at": "[datetime]",
11+
"default_version": "1.0.0",
1112
"description": "description",
1213
"documentation": "https://example.com",
1314
"downloads": 20,

src/tests/routes/crates/snapshots/crates_io__tests__routes__crates__read__show_minimal.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ expression: response.json()
88
"badges": null,
99
"categories": null,
1010
"created_at": "[datetime]",
11+
"default_version": "1.0.0",
1112
"description": "description",
1213
"documentation": "https://example.com",
1314
"downloads": 20,

0 commit comments

Comments
 (0)