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() }