pub mod discovery; pub mod git; pub mod github; pub mod settings; pub mod user; use anyhow::Error; use async_trait::async_trait; use serde_json::Value; use crate::backend::git::GitBackendError; use giterated_models::{ model::{ authenticated::UserAuthenticationToken, instance::Instance, repository::{ IssueLabel, Repository, RepositoryIssue, RepositorySummary, RepositoryTreeEntry, }, settings::AnySetting, user::User, }, operation::{ instance::{AuthenticationTokenRequest, RegisterAccountRequest, RepositoryCreateRequest}, repository::{ RepositoryFileInspectRequest, RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest, }, }, values::AnyValue, }; #[async_trait] pub trait RepositoryBackend { async fn create_repository( &mut self, user: &User, request: &RepositoryCreateRequest, ) -> Result; async fn repository_file_inspect( &mut self, requester: Option<&User>, request: &RepositoryFileInspectRequest, ) -> Result, Error>; async fn repositories_for_user( &mut self, requester: Option<&User>, user: &User, ) -> Result, Error>; async fn get_value( &mut self, user: &Repository, name: &str, ) -> Result, Error>; async fn get_setting(&mut self, user: &Repository, name: &str) -> Result; async fn write_setting( &mut self, user: &Repository, name: &str, setting: &Value, ) -> Result<(), Error>; async fn exists(&mut self, repository: &Repository) -> Result; } pub trait IssuesBackend { fn issues_count( &mut self, requester: Option<&User>, request: &RepositoryIssuesCountRequest, ) -> Result; fn issue_labels( &mut self, requester: Option<&User>, request: &RepositoryIssueLabelsRequest, ) -> Result, Error>; fn issues( &mut self, requester: Option<&User>, request: &RepositoryIssuesRequest, ) -> Result, Error>; } #[async_trait::async_trait] pub trait AuthBackend { async fn register( &mut self, request: RegisterAccountRequest, ) -> Result; async fn login( &mut self, source: &Instance, request: AuthenticationTokenRequest, ) -> Result; } #[async_trait::async_trait] pub trait UserBackend: AuthBackend { async fn get_value(&mut self, user: &User, name: &str) -> Result, Error>; async fn get_setting(&mut self, user: &User, name: &str) -> Result; async fn write_setting( &mut self, user: &User, name: &str, setting: &Value, ) -> Result<(), Error>; async fn exists(&mut self, user: &User) -> Result; } #[async_trait::async_trait] pub trait MetadataBackend { async fn user_get(&mut self, user: &User, name: &str) -> Result; async fn user_write( &mut self, user: &User, name: &str, setting: AnySetting, ) -> Result<(), Error>; async fn repository_get( &mut self, repository: &Repository, name: &str, ) -> Result; async fn repository_write( &mut self, repository: &Repository, name: &str, setting: AnySetting, ) -> Result<(), Error>; }