pub mod discovery; pub mod git; pub mod github; pub mod user; use anyhow::Error; use async_trait::async_trait; use serde_json::Value; use crate::backend::git::GitBackendError; use giterated_models::{ messages::{ authentication::{ AuthenticationTokenRequest, AuthenticationTokenResponse, RegisterAccountRequest, RegisterAccountResponse, }, repository::{ RepositoryCreateRequest, RepositoryCreateResponse, RepositoryFileInspectRequest, RepositoryFileInspectionResponse, RepositoryInfoRequest, RepositoryIssueLabelsRequest, RepositoryIssueLabelsResponse, RepositoryIssuesCountRequest, RepositoryIssuesCountResponse, RepositoryIssuesRequest, RepositoryIssuesResponse, }, user::{ UserBioRequest, UserBioResponse, UserDisplayImageRequest, UserDisplayImageResponse, UserDisplayNameRequest, UserDisplayNameResponse, }, }, model::{ repository::{RepositorySummary, RepositoryView}, user::User, }, }; #[async_trait] pub trait RepositoryBackend: IssuesBackend { async fn create_repository( &mut self, user: &User, request: &RepositoryCreateRequest, ) -> Result; async fn repository_info( &mut self, requester: Option<&User>, request: &RepositoryInfoRequest, ) -> Result; async fn repository_file_inspect( &mut self, requester: Option<&User>, request: &RepositoryFileInspectRequest, ) -> Result; async fn repositories_for_user( &mut self, requester: Option<&User>, user: &User, ) -> Result, Error>; } 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; fn issues( &mut self, requester: Option<&User>, request: &RepositoryIssuesRequest, ) -> Result; } #[async_trait::async_trait] pub trait AuthBackend { async fn register( &mut self, request: RegisterAccountRequest, ) -> Result; async fn login( &mut self, request: AuthenticationTokenRequest, ) -> Result; } #[async_trait::async_trait] pub trait UserBackend: AuthBackend { async fn display_name( &mut self, request: UserDisplayNameRequest, ) -> Result; async fn display_image( &mut self, request: UserDisplayImageRequest, ) -> Result; async fn bio(&mut self, request: UserBioRequest) -> Result; async fn exists(&mut self, user: &User) -> Result; async fn settings(&mut self, user: &User) -> Result, Error>; async fn write_settings( &mut self, user: &User, settings: &[(String, Value)], ) -> Result<(), Error>; }