use crate::{NythosResult, Role, RoleAssignment, RoleId, TenantId, UserId};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RoleAssignmentInput {
tenant_id: TenantId,
user_id: UserId,
role_id: RoleId,
}
impl RoleAssignmentInput {
pub const fn new(tenant_id: TenantId, user_id: UserId, role_id: RoleId) -> Self {
Self {
tenant_id,
user_id,
role_id,
}
}
pub const fn tenant_id(&self) -> TenantId {
self.tenant_id
}
pub const fn user_id(&self) -> UserId {
self.user_id
}
pub const fn role_id(&self) -> RoleId {
self.role_id
}
pub const fn into_assignment(self) -> RoleAssignment {
RoleAssignment::new(self.tenant_id, self.user_id, self.role_id)
}
}
pub trait RoleRepository {
async fn assign_role(&self, input: RoleAssignmentInput) -> NythosResult<()>;
async fn revoke_role(&self, input: RoleAssignmentInput) -> NythosResult<()>;
async fn get_roles_for_user(
&self,
tenant_id: TenantId,
user_id: UserId,
) -> NythosResult<Vec<Role>>;
}