Skip to content

CrateOwnerInvitation: Replace encodable() method #3168

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
Jan 11, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/controllers/crate_owner_invitation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn list(req: &mut dyn RequestExt) -> EndpointResult {
.load(&*conn)?;
let crate_owner_invitations = crate_owner_invitations
.into_iter()
.map(|i| i.encodable(conn))
.map(|i| EncodableCrateOwnerInvitation::from(i, conn))
.collect();

#[derive(Serialize)]
Expand Down
10 changes: 0 additions & 10 deletions src/models/crate_owner_invitation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use chrono::NaiveDateTime;
use diesel::prelude::*;

use crate::schema::{crate_owner_invitations, crates, users};
use crate::views::EncodableCrateOwnerInvitation;

/// The model representing a row in the `crate_owner_invitations` database table.
#[derive(Clone, Debug, PartialEq, Eq, Identifiable, Queryable)]
Expand Down Expand Up @@ -40,13 +39,4 @@ impl CrateOwnerInvitation {
.first(&*conn)
.unwrap_or_else(|_| String::from("(unknown crate name)"))
}

pub fn encodable(self, conn: &PgConnection) -> EncodableCrateOwnerInvitation {
EncodableCrateOwnerInvitation {
invited_by_username: self.invited_by_username(conn),
crate_name: self.crate_name(conn),
crate_id: self.crate_id,
created_at: self.created_at,
}
}
}
16 changes: 14 additions & 2 deletions src/views.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use chrono::NaiveDateTime;
use diesel::PgConnection;
use std::collections::HashMap;

use crate::github;
use crate::models::{
Badge, Category, CreatedApiToken, Dependency, DependencyKind, Keyword, Owner,
ReverseDependency, Team, User, VersionDownload,
Badge, Category, CrateOwnerInvitation, CreatedApiToken, Dependency, DependencyKind, Keyword,
Owner, ReverseDependency, Team, User, VersionDownload,
};
use crate::util::rfc3339;

Expand Down Expand Up @@ -76,6 +77,17 @@ pub struct EncodableCrateOwnerInvitation {
pub created_at: NaiveDateTime,
}

impl EncodableCrateOwnerInvitation {
pub fn from(invitation: CrateOwnerInvitation, conn: &PgConnection) -> Self {
Self {
invited_by_username: invitation.invited_by_username(conn),
crate_name: invitation.crate_name(conn),
crate_id: invitation.crate_id,
created_at: invitation.created_at,
}
}
}

#[derive(Deserialize, Serialize, Debug, Copy, Clone)]
pub struct InvitationResponse {
pub crate_id: i32,
Expand Down