-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(sudo) add data endpoint and transfer groups
- Loading branch information
Showing
12 changed files
with
389 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use crate::db::logs::Log; | ||
use crate::db::model::*; | ||
use crate::db::schema; | ||
use crate::db::users::UserProfile; | ||
use crate::db::users::UserProfileValue; | ||
use diesel::prelude::*; | ||
use failure::Error; | ||
use std::convert::TryInto; | ||
use uuid::Uuid; | ||
|
||
pub fn raw_memberships_for_user( | ||
connection: &PgConnection, | ||
user_uuid: &Uuid, | ||
) -> Result<Vec<Membership>, Error> { | ||
use schema::memberships as m; | ||
|
||
m::table | ||
.filter(m::user_uuid.eq(user_uuid)) | ||
.get_results(connection) | ||
.map_err(Into::into) | ||
} | ||
|
||
pub fn raw_invitations_for_user( | ||
connection: &PgConnection, | ||
user_uuid: &Uuid, | ||
) -> Result<Vec<Invitation>, Error> { | ||
use schema::invitations as i; | ||
|
||
i::table | ||
.filter(i::user_uuid.eq(user_uuid).or(i::added_by.eq(user_uuid))) | ||
.get_results(connection) | ||
.map_err(Into::into) | ||
} | ||
|
||
pub fn raw_requests_for_user( | ||
connection: &PgConnection, | ||
user_uuid: &Uuid, | ||
) -> Result<Vec<Request>, Error> { | ||
use schema::requests as r; | ||
|
||
r::table | ||
.filter(r::user_uuid.eq(user_uuid)) | ||
.get_results(connection) | ||
.map_err(Into::into) | ||
} | ||
|
||
pub fn raw_user_for_user( | ||
connection: &PgConnection, | ||
user_uuid: &Uuid, | ||
) -> Result<UserProfile, Error> { | ||
use schema::profiles as p; | ||
|
||
p::table | ||
.filter(p::user_uuid.eq(user_uuid)) | ||
.get_result::<UserProfileValue>(connection) | ||
.map_err(Error::from) | ||
.and_then(TryInto::try_into) | ||
} | ||
|
||
pub fn raw_logs_for_user(connection: &PgConnection, user_uuid: &Uuid) -> Result<Vec<Log>, Error> { | ||
use schema::logs as l; | ||
|
||
l::table | ||
.filter(l::user_uuid.eq(user_uuid).or(l::host_uuid.eq(user_uuid))) | ||
.get_results(connection) | ||
.map_err(Into::into) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::db::internal; | ||
use crate::db::internal::raw::*; | ||
use crate::db::operations::models::RawUserData; | ||
use crate::db::Pool; | ||
use dino_park_gate::scope::ScopeAndUser; | ||
use failure::Error; | ||
use uuid::Uuid; | ||
|
||
pub fn raw_user_data( | ||
pool: &Pool, | ||
scope_and_user: &ScopeAndUser, | ||
user_uuid: Option<Uuid>, | ||
) -> Result<RawUserData, Error> { | ||
let connection = pool.get()?; | ||
let user_uuid = match user_uuid { | ||
Some(user_uuid) => user_uuid, | ||
_ => internal::user::user_by_id(&connection, &scope_and_user.user_id)?.user_uuid, | ||
}; | ||
|
||
let user_profile = raw_user_for_user(&connection, &user_uuid)?; | ||
let memberships = raw_memberships_for_user(&connection, &user_uuid)?; | ||
let invitations = raw_invitations_for_user(&connection, &user_uuid)?; | ||
let requests = raw_requests_for_user(&connection, &user_uuid)?; | ||
let logs = raw_logs_for_user(&connection, &user_uuid)?; | ||
|
||
Ok(RawUserData { | ||
user_profile, | ||
memberships, | ||
invitations, | ||
requests, | ||
logs, | ||
}) | ||
} |
Oops, something went wrong.