diff --git a/src/backend/git.rs b/src/backend/git.rs index e9e6658..199eec8 100644 --- a/src/backend/git.rs +++ b/src/backend/git.rs @@ -1,8 +1,8 @@ use std::error::Error; use crate::{ - command::repository::{ - CreateRepositoryCommand, CreateRepositoryResponse, RepositoryFileInspectionCommand, + messages::repository::{ + CreateRepositoryRequest, CreateRepositoryResponse, RepositoryFileInspectRequest, RepositoryFileInspectionResponse, RepositoryInfoRequest, RepositoryIssueLabelsRequest, RepositoryIssueLabelsResponse, RepositoryIssuesCountRequest, RepositoryIssuesCountResponse, RepositoryIssuesRequest, RepositoryIssuesResponse, @@ -23,7 +23,7 @@ impl GitBackend { impl RepositoryBackend for GitBackend { fn create_repository( &mut self, - request: &CreateRepositoryCommand, + request: &CreateRepositoryRequest, ) -> Result> { todo!() } @@ -37,7 +37,7 @@ impl RepositoryBackend for GitBackend { fn repository_file_inspect( &mut self, - request: &RepositoryFileInspectionCommand, + request: &RepositoryFileInspectRequest, ) -> Result> { todo!() } diff --git a/src/backend/mod.rs b/src/backend/mod.rs index b1de6d6..be6e028 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -3,8 +3,8 @@ pub mod git; use std::error::Error; use crate::{ - command::repository::{ - CreateRepositoryCommand, CreateRepositoryResponse, RepositoryFileInspectionCommand, + messages::repository::{ + CreateRepositoryRequest, CreateRepositoryResponse, RepositoryFileInspectRequest, RepositoryFileInspectionResponse, RepositoryInfoRequest, RepositoryIssueLabelsRequest, RepositoryIssueLabelsResponse, RepositoryIssuesCountRequest, RepositoryIssuesCountResponse, RepositoryIssuesRequest, RepositoryIssuesResponse, @@ -15,7 +15,7 @@ use crate::{ pub trait RepositoryBackend { fn create_repository( &mut self, - request: &CreateRepositoryCommand, + request: &CreateRepositoryRequest, ) -> Result>; fn repository_info( &mut self, @@ -23,7 +23,7 @@ pub trait RepositoryBackend { ) -> Result>; fn repository_file_inspect( &mut self, - request: &RepositoryFileInspectionCommand, + request: &RepositoryFileInspectRequest, ) -> Result>; fn repository_issues_count( diff --git a/src/command/issues.rs b/src/command/issues.rs deleted file mode 100644 index b4a9c3a..0000000 --- a/src/command/issues.rs +++ /dev/null @@ -1,18 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use crate::model::repository::Repository; - -#[derive(Clone)] -pub struct IssuesCountCommand { - pub respository: Repository, -} - -#[derive(Clone, Serialize, Deserialize)] -pub struct IssuesCountResponse { - pub count: u64, -} - -#[derive(Clone)] -pub struct IssuesLabelsCommand { - pub repository: Repository, -} diff --git a/src/command/mod.rs b/src/command/mod.rs deleted file mode 100644 index 685145a..0000000 --- a/src/command/mod.rs +++ /dev/null @@ -1,14 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use crate::handshake::HandshakeMessage; - -use self::repository::RepositoryMessage; - -pub mod issues; -pub mod repository; - -#[derive(Clone, Serialize, Deserialize)] -pub enum MessageKind { - Handshake(HandshakeMessage), - Repository(RepositoryMessage), -} diff --git a/src/command/repository.rs b/src/command/repository.rs deleted file mode 100644 index 496a870..0000000 --- a/src/command/repository.rs +++ /dev/null @@ -1,115 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use crate::model::{ - repository::{CommitMetadata, Repository, RepositoryFile, RepositoryView}, - user::User, -}; - -use super::issues::IssuesCountResponse; - -#[derive(Clone, Serialize, Deserialize)] -pub struct RepositoryMessage { - pub target: Repository, - pub command: RepositoryMessageKind, -} - -#[derive(Clone, Serialize, Deserialize)] -pub enum RepositoryMessageKind { - Request(RepositoryRequest), - Response(RepositoryResponse), -} - -#[derive(Clone, Serialize, Deserialize)] -pub enum RepositoryRequest { - CreateRepository(CreateRepositoryCommand), - RepositoryFileInspection(RepositoryFileInspectionCommand), - RepositoryInfo(RepositoryInfoRequest), - IssuesCount(RepositoryIssuesCountRequest), - IssueLabels(RepositoryIssueLabelsRequest), - Issues(RepositoryIssuesRequest), -} - -#[derive(Clone, Serialize, Deserialize)] -pub enum RepositoryResponse { - CreateRepository(CreateRepositoryResponse), - RepositoryFileInspection(RepositoryFileInspectionResponse), - RepositoryInfo(RepositoryView), - IssuesCount(RepositoryIssuesCountResponse), - IssueLabels(RepositoryIssueLabelsResponse), - Issues(RepositoryIssuesResponse), -} - -#[derive(Clone, Serialize, Deserialize)] -pub struct CreateRepositoryCommand { - pub name: String, - pub description: String, - pub default_branch: String, - pub owner: User, -} - -#[derive(Clone, Serialize, Deserialize)] -pub enum CreateRepositoryResponse { - Created, - Failed, -} - -#[derive(Clone, Serialize, Deserialize)] -pub struct RepositoryFileInspectionCommand { - pub path: RepositoryFile, -} - -#[derive(Clone, Serialize, Deserialize)] -pub enum RepositoryFileInspectionResponse { - File { - commit_metadata: CommitMetadata, - }, - Folder { - commit_metadata: CommitMetadata, - members: Vec, - }, - Invalid { - path: RepositoryFile, - }, -} - -#[derive(Clone, Serialize, Deserialize)] -pub struct RepositoryIssuesCountRequest; - -#[derive(Clone, Serialize, Deserialize)] -pub struct RepositoryIssuesCountResponse { - pub count: u64, -} - -#[derive(Clone, Serialize, Deserialize)] -pub struct RepositoryIssueLabelsRequest; - -#[derive(Clone, Serialize, Deserialize)] -pub struct RepositoryIssueLabelsResponse { - pub labels: Vec, -} - -#[derive(Clone, Serialize, Deserialize)] -pub struct IssueLabel { - pub name: String, - pub color: String, -} - -#[derive(Clone, Serialize, Deserialize)] -pub struct RepositoryIssuesRequest; - -#[derive(Clone, Serialize, Deserialize)] -pub struct RepositoryIssuesResponse { - pub issues: Vec, -} - -#[derive(Clone, Serialize, Deserialize)] -pub struct RepositoryIssue { - pub author: User, - pub id: u64, - pub title: String, - pub contents: String, - pub labels: Vec, -} - -#[derive(Clone, Serialize, Deserialize)] -pub struct RepositoryInfoRequest; diff --git a/src/connection.rs b/src/connection.rs index 27267e4..ee9d20d 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -14,7 +14,7 @@ use tokio_tungstenite::{tungstenite::Message, WebSocketStream}; use crate::{ backend::RepositoryBackend, - command::{ + messages::{ issues::IssuesCountResponse, repository::{ RepositoryFileInspectionResponse, RepositoryIssueLabelsResponse, @@ -62,7 +62,7 @@ pub async fn connection_worker( ) { let mut handshaked = false; let this_instance = Instance { - url: String::from("giterated.com"), + url: String::from("127.0.0.1:8080"), }; while let Some(message) = socket.next().await { @@ -213,7 +213,7 @@ pub async fn connection_worker( .await .unwrap(); } - RepositoryRequest::RepositoryFileInspection(request) => { + RepositoryRequest::RepositoryFileInspect(request) => { let mut backend = backend.lock().await; let response = backend.repository_file_inspect(request); diff --git a/src/lib.rs b/src/lib.rs index f1b7287..80b0761 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ pub mod backend; -pub mod command; +pub mod messages; pub mod connection; pub mod handshake; pub mod listener; diff --git a/src/listener.rs b/src/listener.rs index 1c93005..b4a1956 100644 --- a/src/listener.rs +++ b/src/listener.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use tokio::sync::broadcast::{Receiver, Sender}; use crate::{ - command::{repository::RepositoryMessage, MessageKind}, + messages::{repository::RepositoryMessage, MessageKind}, model::{instance::Instance, repository::Repository, user::User}, }; diff --git a/src/messages/issues.rs b/src/messages/issues.rs new file mode 100644 index 0000000..b4a9c3a --- /dev/null +++ b/src/messages/issues.rs @@ -0,0 +1,18 @@ +use serde::{Deserialize, Serialize}; + +use crate::model::repository::Repository; + +#[derive(Clone)] +pub struct IssuesCountCommand { + pub respository: Repository, +} + +#[derive(Clone, Serialize, Deserialize)] +pub struct IssuesCountResponse { + pub count: u64, +} + +#[derive(Clone)] +pub struct IssuesLabelsCommand { + pub repository: Repository, +} diff --git a/src/messages/mod.rs b/src/messages/mod.rs new file mode 100644 index 0000000..685145a --- /dev/null +++ b/src/messages/mod.rs @@ -0,0 +1,14 @@ +use serde::{Deserialize, Serialize}; + +use crate::handshake::HandshakeMessage; + +use self::repository::RepositoryMessage; + +pub mod issues; +pub mod repository; + +#[derive(Clone, Serialize, Deserialize)] +pub enum MessageKind { + Handshake(HandshakeMessage), + Repository(RepositoryMessage), +} diff --git a/src/messages/repository.rs b/src/messages/repository.rs new file mode 100644 index 0000000..0db8eba --- /dev/null +++ b/src/messages/repository.rs @@ -0,0 +1,115 @@ +use serde::{Deserialize, Serialize}; + +use crate::model::{ + repository::{CommitMetadata, Repository, RepositoryFile, RepositoryView}, + user::User, +}; + +use super::issues::IssuesCountResponse; + +#[derive(Clone, Serialize, Deserialize)] +pub struct RepositoryMessage { + pub target: Repository, + pub command: RepositoryMessageKind, +} + +#[derive(Clone, Serialize, Deserialize)] +pub enum RepositoryMessageKind { + Request(RepositoryRequest), + Response(RepositoryResponse), +} + +#[derive(Clone, Serialize, Deserialize)] +pub enum RepositoryRequest { + CreateRepository(CreateRepositoryRequest), + RepositoryFileInspect(RepositoryFileInspectRequest), + RepositoryInfo(RepositoryInfoRequest), + IssuesCount(RepositoryIssuesCountRequest), + IssueLabels(RepositoryIssueLabelsRequest), + Issues(RepositoryIssuesRequest), +} + +#[derive(Clone, Serialize, Deserialize)] +pub enum RepositoryResponse { + CreateRepository(CreateRepositoryResponse), + RepositoryFileInspection(RepositoryFileInspectionResponse), + RepositoryInfo(RepositoryView), + IssuesCount(RepositoryIssuesCountResponse), + IssueLabels(RepositoryIssueLabelsResponse), + Issues(RepositoryIssuesResponse), +} + +#[derive(Clone, Serialize, Deserialize)] +pub struct CreateRepositoryRequest { + pub name: String, + pub description: String, + pub default_branch: String, + pub owner: User, +} + +#[derive(Clone, Serialize, Deserialize)] +pub enum CreateRepositoryResponse { + Created, + Failed, +} + +#[derive(Clone, Serialize, Deserialize)] +pub struct RepositoryFileInspectRequest { + pub path: RepositoryFile, +} + +#[derive(Clone, Serialize, Deserialize)] +pub enum RepositoryFileInspectionResponse { + File { + commit_metadata: CommitMetadata, + }, + Folder { + commit_metadata: CommitMetadata, + members: Vec, + }, + Invalid { + path: RepositoryFile, + }, +} + +#[derive(Clone, Serialize, Deserialize)] +pub struct RepositoryIssuesCountRequest; + +#[derive(Clone, Serialize, Deserialize)] +pub struct RepositoryIssuesCountResponse { + pub count: u64, +} + +#[derive(Clone, Serialize, Deserialize)] +pub struct RepositoryIssueLabelsRequest; + +#[derive(Clone, Serialize, Deserialize)] +pub struct RepositoryIssueLabelsResponse { + pub labels: Vec, +} + +#[derive(Clone, Serialize, Deserialize)] +pub struct IssueLabel { + pub name: String, + pub color: String, +} + +#[derive(Clone, Serialize, Deserialize)] +pub struct RepositoryIssuesRequest; + +#[derive(Clone, Serialize, Deserialize)] +pub struct RepositoryIssuesResponse { + pub issues: Vec, +} + +#[derive(Clone, Serialize, Deserialize)] +pub struct RepositoryIssue { + pub author: User, + pub id: u64, + pub title: String, + pub contents: String, + pub labels: Vec, +} + +#[derive(Clone, Serialize, Deserialize)] +pub struct RepositoryInfoRequest;