Skip to content

Commit 1518282

Browse files
committed
models::version: Inline encodable() method
1 parent 920bc1d commit 1518282

File tree

2 files changed

+44
-52
lines changed

2 files changed

+44
-52
lines changed

src/models/version.rs

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use diesel::prelude::*;
55

66
use crate::util::errors::{cargo_err, AppResult};
77

8-
use crate::models::{Crate, Dependency, User, VersionOwnerAction};
8+
use crate::models::{Crate, Dependency, User};
99
use crate::schema::*;
10-
use crate::views::{EncodableAuditAction, EncodableVersion, EncodableVersionLinks};
1110

1211
// Queryable has a custom implementation below
1312
#[derive(Clone, Identifiable, Associations, Debug, Queryable, Deserialize, Serialize)]
@@ -80,55 +79,6 @@ impl TopVersions {
8079
}
8180

8281
impl Version {
83-
pub fn encodable(
84-
self,
85-
crate_name: &str,
86-
published_by: Option<User>,
87-
audit_actions: Vec<(VersionOwnerAction, User)>,
88-
) -> EncodableVersion {
89-
let Version {
90-
id,
91-
num,
92-
updated_at,
93-
created_at,
94-
downloads,
95-
features,
96-
yanked,
97-
license,
98-
crate_size,
99-
..
100-
} = self;
101-
let num = num.to_string();
102-
EncodableVersion {
103-
dl_path: format!("/api/v1/crates/{}/{}/download", crate_name, num),
104-
readme_path: format!("/api/v1/crates/{}/{}/readme", crate_name, num),
105-
num: num.clone(),
106-
id,
107-
krate: crate_name.to_string(),
108-
updated_at,
109-
created_at,
110-
downloads,
111-
features,
112-
yanked,
113-
license,
114-
links: EncodableVersionLinks {
115-
dependencies: format!("/api/v1/crates/{}/{}/dependencies", crate_name, num),
116-
version_downloads: format!("/api/v1/crates/{}/{}/downloads", crate_name, num),
117-
authors: format!("/api/v1/crates/{}/{}/authors", crate_name, num),
118-
},
119-
crate_size,
120-
published_by: published_by.map(User::into),
121-
audit_actions: audit_actions
122-
.into_iter()
123-
.map(|(audit_action, user)| EncodableAuditAction {
124-
action: audit_action.action.into(),
125-
user: user.into(),
126-
time: audit_action.time,
127-
})
128-
.collect(),
129-
}
130-
}
131-
13282
/// Returns (dependency, crate dependency name)
13383
pub fn dependencies(&self, conn: &PgConnection) -> QueryResult<Vec<(Dependency, String)>> {
13484
Dependency::belonging_to(self)

src/views.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,49 @@ impl EncodableVersion {
453453
published_by: Option<User>,
454454
audit_actions: Vec<(VersionOwnerAction, User)>,
455455
) -> Self {
456-
version.encodable(crate_name, published_by, audit_actions)
456+
let Version {
457+
id,
458+
num,
459+
updated_at,
460+
created_at,
461+
downloads,
462+
features,
463+
yanked,
464+
license,
465+
crate_size,
466+
..
467+
} = version;
468+
469+
let num = num.to_string();
470+
471+
Self {
472+
dl_path: format!("/api/v1/crates/{}/{}/download", crate_name, num),
473+
readme_path: format!("/api/v1/crates/{}/{}/readme", crate_name, num),
474+
num: num.clone(),
475+
id,
476+
krate: crate_name.to_string(),
477+
updated_at,
478+
created_at,
479+
downloads,
480+
features,
481+
yanked,
482+
license,
483+
links: EncodableVersionLinks {
484+
dependencies: format!("/api/v1/crates/{}/{}/dependencies", crate_name, num),
485+
version_downloads: format!("/api/v1/crates/{}/{}/downloads", crate_name, num),
486+
authors: format!("/api/v1/crates/{}/{}/authors", crate_name, num),
487+
},
488+
crate_size,
489+
published_by: published_by.map(User::into),
490+
audit_actions: audit_actions
491+
.into_iter()
492+
.map(|(audit_action, user)| EncodableAuditAction {
493+
action: audit_action.action.into(),
494+
user: user.into(),
495+
time: audit_action.time,
496+
})
497+
.collect(),
498+
}
457499
}
458500
}
459501

0 commit comments

Comments
 (0)