use anyhow::Error; use crate::{ backend::git::GitBackendError, message::{AuthenticatedUser, Message, MessageHandler, NetworkMessage, State}, }; use giterated_models::messages::repository::{ RepositoryCreateRequest, RepositoryFileInspectRequest, RepositoryInfoRequest, RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest, }; use super::wrapper::ConnectionState; pub async fn repository_handle( message_type: &str, message: &NetworkMessage, state: &ConnectionState, ) -> Result { match message_type { "&giterated_models::messages::repository::RepositoryCreateRequest" => { create_repository.handle_message(&message, state).await?; Ok(true) } "&giterated_models::messages::repository::RepositoryFileInspectRequest" => { repository_file_inspect .handle_message(&message, state) .await?; Ok(true) } "&giterated_models::messages::repository::RepositoryInfoRequest" => { repository_info.handle_message(&message, state).await?; Ok(true) } "&giterated_models::messages::repository::RepositoryIssuesCountRequest" => { issues_count.handle_message(&message, state).await?; Ok(true) } "&giterated_models::messages::repository::RepositoryIssueLabelsRequest" => { issue_labels.handle_message(&message, state).await?; Ok(true) } "&giterated_models::messages::repository::RepositoryIssuesRequest" => { issues.handle_message(&message, state).await?; Ok(true) } _ => Ok(false), } } async fn create_repository( Message(request): Message, State(connection_state): State, AuthenticatedUser(user): AuthenticatedUser, ) -> Result<(), RepositoryError> { let mut repository_backend = connection_state.repository_backend.lock().await; let response = repository_backend .create_repository(&user, &request) .await?; drop(repository_backend); connection_state.send(response).await?; Ok(()) } async fn repository_file_inspect( Message(request): Message, State(connection_state): State, user: Option, ) -> Result<(), RepositoryError> { let user = user.map(|u| u.0); let mut repository_backend = connection_state.repository_backend.lock().await; let response = repository_backend .repository_file_inspect(user.as_ref(), &request) .await?; drop(repository_backend); connection_state.send(response).await?; Ok(()) } async fn repository_info( Message(request): Message, State(connection_state): State, user: Option, ) -> Result<(), RepositoryError> { let user = user.map(|u| u.0); let mut repository_backend = connection_state.repository_backend.lock().await; let response = repository_backend .repository_info(user.as_ref(), &request) .await?; drop(repository_backend); connection_state.send(response).await?; Ok(()) } async fn issues_count( Message(_request): Message, State(_connection_state): State, _user: Option, ) -> Result<(), RepositoryError> { unimplemented!(); } async fn issue_labels( Message(_request): Message, State(_connection_state): State, _user: Option, ) -> Result<(), RepositoryError> { unimplemented!(); } async fn issues( Message(_request): Message, State(_connection_state): State, _user: Option, ) -> Result<(), RepositoryError> { unimplemented!(); } #[derive(Debug, thiserror::Error)] pub enum RepositoryError { #[error("{0}")] GitBackendError(#[from] GitBackendError), #[error("{0}")] Other(#[from] Error), }