pub mod handler; pub mod updates; use std::sync::Arc; use giterated_models::error::OperationError; use giterated_models::instance::Instance; use giterated_models::object::{GiteratedObject, Object, ObjectRequestError}; use giterated_models::object_backend::ObjectBackend; use giterated_models::operation::GiteratedOperation; use giterated_models::repository::{DefaultBranch, Description, Repository, Visibility}; use giterated_models::user::{Bio, DisplayName, User}; use giterated_stack::StackOperationState; use giterated_stack::SubstackBuilder; use std::fmt::Debug; use tokio::sync::Mutex; use crate::backend::{RepositoryBackend, UserBackend}; use self::handler::{ instance_authentication_request, instance_create_repository_request, instance_registration_request, repository_commit_before, repository_commit_by_id, repository_diff, repository_diff_patch, repository_file_from_id, repository_file_from_path, repository_get_branches, repository_get_default_branch, repository_get_latest_commit, repository_get_statistics, repository_get_value_description, repository_get_value_visibility, repository_info, repository_last_commit_of_file, user_get_repositories, user_get_value_bio, user_get_value_display_name, }; #[derive(Clone, Debug)] pub struct Foobackend {} #[async_trait::async_trait(?Send)] impl ObjectBackend for Foobackend { async fn object_operation + Debug>( &self, _object: O, _operation: &str, _payload: D, _operation_state: &StackOperationState, ) -> Result> { // We don't handle operations with this backend Err(OperationError::Unhandled) } async fn get_object( &self, _object_str: &str, _operation_state: &StackOperationState, ) -> Result, OperationError> { Err(OperationError::Unhandled) } } /// A backend implementation which attempts to resolve data from the instance's database. #[derive(Clone)] #[allow(unused)] pub struct DatabaseBackend { pub(self) our_instance: Instance, pub(self) user_backend: Arc>, pub(self) repository_backend: Arc>, } impl DatabaseBackend { pub fn new( instance: Instance, user_backend: Arc>, repository_backend: Arc>, ) -> Self { Self { our_instance: instance, user_backend, repository_backend, } } pub fn into_substack(self) -> SubstackBuilder { let mut builder = SubstackBuilder::::new(self); builder .object::() .object::() .object::(); builder .setting::() .setting::() .setting::() .setting::() .setting::(); builder .value(user_get_value_bio) .value(user_get_value_display_name) .value(repository_get_value_description) .value(repository_get_value_visibility) .value(repository_get_default_branch) .value(repository_get_latest_commit); builder .operation(user_get_repositories) .operation(instance_registration_request) .operation(instance_authentication_request) .operation(instance_create_repository_request) .operation(repository_info) .operation(repository_get_statistics) .operation(repository_file_from_id) .operation(repository_file_from_path) .operation(repository_last_commit_of_file) .operation(repository_commit_by_id) .operation(repository_diff) .operation(repository_diff_patch) .operation(repository_commit_before) .operation(repository_get_branches); builder } } impl Debug for DatabaseBackend { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("DatabaseBackend").finish() } }