Skip to content

Commit b1e96f8

Browse files
committed
views: Prepare to expose the default_version field on the API
1 parent f4c2cb9 commit b1e96f8

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

src/controllers/krate/metadata.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ pub async fn show(app: AppState, Path(name): Path<String>, req: Parts) -> AppRes
120120

121121
let encodable_crate = EncodableCrate::from(
122122
krate.clone(),
123+
None,
123124
top_versions.as_ref(),
124125
ids,
125126
kws.as_deref(),

src/controllers/krate/publish.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,15 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
505505
};
506506

507507
Ok(Json(GoodCrate {
508-
krate: EncodableCrate::from_minimal(krate, Some(&top_versions), None, false, downloads, None),
508+
krate: EncodableCrate::from_minimal(
509+
krate,
510+
None,
511+
Some(&top_versions),
512+
None,
513+
false,
514+
downloads,
515+
None,
516+
),
509517
warnings,
510518
}))
511519
})

src/controllers/krate/search.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ pub async fn search(app: AppState, req: Parts) -> AppResult<Json<Value>> {
228228
.map(|(max_version, (krate, perfect_match, total, recent, _))| {
229229
EncodableCrate::from_minimal(
230230
krate,
231+
None,
231232
Some(&max_version),
232233
Some(vec![]),
233234
perfect_match,

src/controllers/summary.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub async fn summary(state: AppState) -> AppResult<Json<Value>> {
3737
.map(|(top_versions, (krate, total, recent))| {
3838
Ok(EncodableCrate::from_minimal(
3939
krate,
40+
None,
4041
Some(&top_versions),
4142
None,
4243
false,

src/views.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ pub struct EncodableCrate {
208208
// NOTE: Used by shields.io, altering `downloads` requires a PR with shields.io
209209
pub downloads: i64,
210210
pub recent_downloads: Option<i64>,
211+
#[serde(skip_serializing_if = "Option::is_none")]
212+
pub default_version: Option<String>,
211213
// NOTE: Used by shields.io, altering `max_version` requires a PR with shields.io
212214
pub max_version: String,
213215
pub newest_version: String, // Most recently updated version, which may not be max
@@ -224,6 +226,7 @@ impl EncodableCrate {
224226
#[allow(clippy::too_many_arguments)]
225227
pub fn from(
226228
krate: Crate,
229+
default_version: Option<&str>,
227230
top_versions: Option<&TopVersions>,
228231
versions: Option<Vec<i32>>,
229232
keywords: Option<&[Keyword]>,
@@ -254,6 +257,8 @@ impl EncodableCrate {
254257
let documentation = remove_blocked_urls(documentation);
255258
let repository = remove_blocked_urls(repository);
256259

260+
let default_version = default_version.map(ToString::to_string);
261+
257262
let max_version = top_versions
258263
.and_then(|v| v.highest.as_ref())
259264
.map(|v| v.to_string())
@@ -289,6 +294,7 @@ impl EncodableCrate {
289294
keywords: keyword_ids,
290295
categories: category_ids,
291296
badges,
297+
default_version,
292298
max_version,
293299
newest_version,
294300
max_stable_version,
@@ -310,6 +316,7 @@ impl EncodableCrate {
310316

311317
pub fn from_minimal(
312318
krate: Crate,
319+
default_version: Option<&str>,
313320
top_versions: Option<&TopVersions>,
314321
badges: Option<Vec<()>>,
315322
exact_match: bool,
@@ -318,6 +325,7 @@ impl EncodableCrate {
318325
) -> Self {
319326
Self::from(
320327
krate,
328+
default_version,
321329
top_versions,
322330
None,
323331
None,
@@ -800,6 +808,7 @@ mod tests {
800808
.unwrap(),
801809
downloads: 0,
802810
recent_downloads: None,
811+
default_version: None,
803812
max_version: "".to_string(),
804813
newest_version: "".to_string(),
805814
max_stable_version: None,

0 commit comments

Comments
 (0)