1
0
Fork 0
forked from 2sys/phonograph
phonograph/phono-models/src/accessors/mod.rs

29 lines
749 B
Rust
Raw Normal View History

use uuid::Uuid;
use crate::errors::AccessError;
pub mod portal;
pub mod workspace;
#[derive(Clone, Copy, Debug, PartialEq, strum::Display)]
pub enum Actor {
/// Bypass explicit auth checks.
Bypass,
#[strum(to_string = "User({0})")]
User(Uuid),
}
/// Provides methods for fetching database entities of type `T`, typically with
/// authorization checks.
pub trait Accessor<T>: Default + Sized {
/// Returns a new builder struct. Alias for [`Self::default()`].
fn new() -> Self {
Self::default()
}
/// Fetch an entity from the database, returning [`AccessError::NotFound`]
/// if access is denied or the object cannot be found.
fn fetch_one(self) -> impl Future<Output = Result<T, AccessError>>;
}