Skip to content

added the exact_match field to encodablecrate #673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/krate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub struct EncodableCrate {
pub license: Option<String>,
pub repository: Option<String>,
pub links: CrateLinks,
pub exact_match: bool,
}

#[derive(RustcEncodable, RustcDecodable)]
Expand Down Expand Up @@ -391,16 +392,17 @@ impl Crate {

pub fn minimal_encodable(self,
max_version: semver::Version,
badges: Option<Vec<Badge>>) -> EncodableCrate {
self.encodable(max_version, None, None, None, badges)
badges: Option<Vec<Badge>>, exact_match: bool) -> EncodableCrate {
self.encodable(max_version, None, None, None, badges, exact_match)
}

pub fn encodable(self,
max_version: semver::Version,
versions: Option<Vec<i32>>,
keywords: Option<&[Keyword]>,
categories: Option<&[Category]>,
badges: Option<Vec<Badge>>)
badges: Option<Vec<Badge>>,
exact_match: bool)
-> EncodableCrate {
let Crate {
name, created_at, updated_at, downloads, description,
Expand Down Expand Up @@ -428,6 +430,7 @@ impl Crate {
max_version: max_version.to_string(),
documentation: documentation,
homepage: homepage,
exact_match: exact_match,
description: description,
license: license,
repository: repository,
Expand Down Expand Up @@ -726,7 +729,7 @@ pub fn index(req: &mut Request) -> CargoResult<Response> {
// this N+1
let badges = badges::table.filter(badges::crate_id.eq(krate.id))
.load::<Badge>(&*conn)?;
Ok(krate.minimal_encodable(max_version, Some(badges)))
Ok(krate.minimal_encodable(max_version, Some(badges), false))
}).collect::<Result<_, ::diesel::result::Error>>()?;

#[derive(RustcEncodable)]
Expand Down Expand Up @@ -758,7 +761,7 @@ pub fn summary(req: &mut Request) -> CargoResult<Response> {
.map(|versions| Version::max(versions.into_iter().map(|v| v.num)))
.zip(krates)
.map(|(max_version, krate)| {
Ok(krate.minimal_encodable(max_version, None))
Ok(krate.minimal_encodable(max_version, None, false))
}).collect()
};

Expand Down Expand Up @@ -841,7 +844,7 @@ pub fn show(req: &mut Request) -> CargoResult<Response> {
}
Ok(req.json(&R {
krate: krate.clone().encodable(
max_version, Some(ids), Some(&kws), Some(&cats), Some(badges)
max_version, Some(ids), Some(&kws), Some(&cats), Some(badges), false
),
versions: versions.into_iter().map(|v| {
v.encodable(&krate.name)
Expand Down Expand Up @@ -961,7 +964,7 @@ pub fn new(req: &mut Request) -> CargoResult<Response> {
#[derive(RustcEncodable)]
struct R<'a> { krate: EncodableCrate, warnings: Warnings<'a> }
Ok(req.json(&R {
krate: krate.minimal_encodable(max_version, None),
krate: krate.minimal_encodable(max_version, None, false),
warnings: warnings
}))
})
Expand Down