Skip to main content

potree_auth/project/ports/
project_repository.rs

1use std::fmt::Debug;
2
3use async_trait::async_trait;
4
5use super::super::domain::Project;
6use super::super::domain::ProjectId;
7
8/// Defines the functionality needed to for the application to interact with
9/// persisted [`Project`]s.
10#[cfg_attr(test, mockall::automock)]
11#[async_trait]
12pub trait ProjectRepository: Debug + Send + Sync + 'static {
13    /// Read a specific project by its `project_id`. The `project_id` is a
14    /// unique identifier of the [`Project`].
15    ///
16    /// # Errors
17    ///
18    /// - [`ProjectRepositoryError::ResourceNotFound`] should be returned if the
19    /// [`Project`] can't be found.
20    /// - [`ProjectRepositoryError::Parsing`] if the project has an invalid
21    ///   format.
22    async fn read(&self, project_id: &ProjectId) -> Result<Project, ProjectRepositoryError>;
23
24    /// List all the projects available in the datastore.
25    ///
26    /// Should sort by project.name.
27    ///
28    /// # Errors
29    ///
30    /// - [`ProjectRepositoryError::Parsing`] if the project has an invalid
31    ///   format.
32    async fn list(&self) -> Result<Vec<Project>, ProjectRepositoryError>;
33}
34
35#[derive(Debug, Clone, thiserror::Error)]
36pub enum ProjectRepositoryError {
37    #[error("the `Project` ({id}) could not be found")]
38    ResourceNotFound { id: ProjectId },
39
40    #[error("unable to parse the `Project` ({id}) ")]
41    Parsing { id: ProjectId },
42
43    #[error("unable to interact with the datastore backend: {message}")]
44    Infrastucture { message: String },
45}