2025-01-28 18:01:43 -08:00
|
|
|
use diesel::{
|
2025-01-31 14:30:08 -08:00
|
|
|
dsl::{auto_type, AsSelect, Eq},
|
2025-01-28 18:01:43 -08:00
|
|
|
pg::Pg,
|
|
|
|
prelude::*,
|
|
|
|
};
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
2025-01-31 14:30:08 -08:00
|
|
|
use crate::{
|
|
|
|
api_keys::ApiKey,
|
|
|
|
schema::{api_keys, teams},
|
|
|
|
};
|
2025-01-28 18:01:43 -08:00
|
|
|
|
|
|
|
#[derive(Clone, Debug, Identifiable, Insertable, Queryable, Selectable)]
|
2025-01-31 14:30:08 -08:00
|
|
|
#[diesel(table_name = teams)]
|
2025-01-28 18:01:43 -08:00
|
|
|
#[diesel(check_for_backend(Pg))]
|
|
|
|
pub struct Team {
|
|
|
|
pub id: Uuid,
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Team {
|
2025-01-31 14:30:08 -08:00
|
|
|
#[auto_type(no_type_alias)]
|
|
|
|
pub fn all() -> _ {
|
|
|
|
let select: AsSelect<Team, Pg> = Team::as_select();
|
|
|
|
teams::table.select(select)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[auto_type(no_type_alias)]
|
|
|
|
pub fn api_keys(self) -> _ {
|
|
|
|
let all: diesel::dsl::Select<api_keys::table, AsSelect<ApiKey, Pg>> = ApiKey::all();
|
|
|
|
let id: Uuid = self.id;
|
|
|
|
let filter: Eq<api_keys::team_id, Uuid> = ApiKey::with_team(id);
|
|
|
|
all.filter(filter)
|
2025-01-28 18:01:43 -08:00
|
|
|
}
|
|
|
|
}
|