Skip to content

Commit 58842e6

Browse files
committed
models::user: Inline encodable_private() method
1 parent 72d42c2 commit 58842e6

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

src/models/user.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::util::errors::AppResult;
77

88
use crate::models::{ApiToken, Crate, CrateOwner, Email, NewEmail, Owner, OwnerKind, Rights};
99
use crate::schema::{crate_owners, emails, users};
10-
use crate::views::EncodablePrivateUser;
1110

1211
/// The model representing a row in the `users` database table.
1312
#[derive(Clone, Debug, PartialEq, Eq, Queryable, Identifiable, AsChangeset, Associations)]
@@ -168,34 +167,6 @@ impl User {
168167
.optional()?)
169168
}
170169

171-
/// Converts this `User` model into an `EncodablePrivateUser` for JSON serialization.
172-
pub fn encodable_private(
173-
self,
174-
email: Option<String>,
175-
email_verified: bool,
176-
email_verification_sent: bool,
177-
) -> EncodablePrivateUser {
178-
let User {
179-
id,
180-
name,
181-
gh_login,
182-
gh_avatar,
183-
..
184-
} = self;
185-
let url = format!("https://github.com/{}", gh_login);
186-
187-
EncodablePrivateUser {
188-
id,
189-
email,
190-
email_verified,
191-
email_verification_sent,
192-
avatar: gh_avatar,
193-
login: gh_login,
194-
name,
195-
url: Some(url),
196-
}
197-
}
198-
199170
/// Queries for the email belonging to a particular user
200171
pub fn email(&self, conn: &PgConnection) -> AppResult<Option<String>> {
201172
Ok(Email::belonging_to(self)

src/views.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,32 @@ pub struct EncodablePrivateUser {
353353
}
354354

355355
impl EncodablePrivateUser {
356+
/// Converts this `User` model into an `EncodablePrivateUser` for JSON serialization.
356357
pub fn from(
357358
user: User,
358359
email: Option<String>,
359360
email_verified: bool,
360361
email_verification_sent: bool,
361362
) -> Self {
362-
user.encodable_private(email, email_verified, email_verification_sent)
363+
let User {
364+
id,
365+
name,
366+
gh_login,
367+
gh_avatar,
368+
..
369+
} = user;
370+
let url = format!("https://github.com/{}", gh_login);
371+
372+
EncodablePrivateUser {
373+
id,
374+
email,
375+
email_verified,
376+
email_verification_sent,
377+
avatar: gh_avatar,
378+
login: gh_login,
379+
name,
380+
url: Some(url),
381+
}
363382
}
364383
}
365384

0 commit comments

Comments
 (0)