use anyhow::Error; use crate::{ messages::repository::{ CreateRepositoryRequest, RepositoryFileInspectRequest, RepositoryInfoRequest, RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest, }, model::authenticated::{AuthenticatedUser, Message, MessageHandler, NetworkMessage, State}, }; use super::{wrapper::ConnectionState, HandlerUnhandled}; pub async fn repository_handle( message: &NetworkMessage, state: &ConnectionState, ) -> Result<(), Error> { if create_repository .handle_message(&message, state) .await .is_ok() { Ok(()) } else if repository_file_inspect .handle_message(&message, state) .await .is_ok() { Ok(()) } else if repository_info .handle_message(&message, state) .await .is_ok() { Ok(()) } else if issues_count.handle_message(&message, state).await.is_ok() { Ok(()) } else if issue_labels.handle_message(&message, state).await.is_ok() { Ok(()) } else if issues.handle_message(&message, state).await.is_ok() { Ok(()) } else { Err(Error::from(HandlerUnhandled)) } } 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}")] Other(#[from] Error), }