use futures_util::{future::BoxFuture, FutureExt}; use giterated_models::{ repository::{DefaultBranch, Description, Repository}, settings::{AnySetting, Setting}, update::ValueUpdate, user::User, value::{AnyValue, GiteratedObjectValue}, }; use giterated_stack::{AuthorizedUser, StackOperationState}; use super::DatabaseBackend; pub fn user_set_value( object: User, value_name: String, value: AnyValue, operation_state: &StackOperationState, ) -> BoxFuture<'static, Result<(), ()>> { todo!() } pub fn user_set_setting( object: User, value_name: String, value: AnySetting, operation_state: &StackOperationState, ) -> BoxFuture<'static, Result<(), ()>> { todo!() } pub fn repository_set_value( object: Repository, value_name: String, value: AnyValue, operation_state: &StackOperationState, ) -> BoxFuture<'static, Result<(), ()>> { todo!() } pub fn repository_set_setting( object: Repository, value_name: String, value: AnySetting, operation_state: &StackOperationState, ) -> BoxFuture<'static, Result<(), ()>> { todo!() } pub fn repository_set_description( object: Repository, description: Description, user: AuthorizedUser, ) -> BoxFuture<'static, Result<(), ()>> { async { Ok(()) }.boxed() } pub fn repository_set_default_branch( object: Repository, default_branch: DefaultBranch, // Ensure user is authorized for this request _user: AuthorizedUser, backend: DatabaseBackend, ) -> BoxFuture<'static, Result<(), ()>> { async move { let mut repository_backend = backend.repository_backend.lock().await; repository_backend .write_setting( &object, DefaultBranch::name(), &serde_json::to_value(default_branch.clone()).unwrap(), ) .await .unwrap(); let set_value = ValueUpdate { object: object.to_string(), value_name: DefaultBranch::value_name().to_owned(), value: unsafe { AnyValue::from_raw(serde_json::to_value(default_branch).unwrap()) }, }; // Submit value update back to the daemon // state.value_update(set_value); Ok(()) } .boxed() }