1
0
Fork 0
forked from 2sys/shoutdotdev
shoutdotdev/src/teams.rs

36 lines
834 B
Rust
Raw Normal View History

2025-02-26 13:10:48 -08:00
use diesel::{
2025-02-26 13:10:47 -08:00
dsl::{auto_type, AsSelect, Eq},
2025-02-26 13:10:48 -08:00
pg::Pg,
prelude::*,
};
use uuid::Uuid;
2025-02-26 13:10:47 -08:00
use crate::{
api_keys::ApiKey,
schema::{api_keys, teams},
};
2025-02-26 13:10:48 -08:00
#[derive(Clone, Debug, Identifiable, Insertable, Queryable, Selectable)]
2025-02-26 13:10:47 -08:00
#[diesel(table_name = teams)]
2025-02-26 13:10:48 -08:00
#[diesel(check_for_backend(Pg))]
pub struct Team {
pub id: Uuid,
pub name: String,
}
impl Team {
2025-02-26 13:10:47 -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-02-26 13:10:48 -08:00
}
}