diff --git a/src/backend/git.rs b/src/backend/git.rs index 199eec8..48e1afb 100644 --- a/src/backend/git.rs +++ b/src/backend/git.rs @@ -10,7 +10,7 @@ use crate::{ model::repository::RepositoryView, }; -use super::RepositoryBackend; +use super::{IssuesBackend, RepositoryBackend}; pub struct GitBackend; @@ -41,22 +41,24 @@ impl RepositoryBackend for GitBackend { ) -> Result> { todo!() } +} - fn repository_issues_count( +impl IssuesBackend for GitBackend { + fn issues_count( &mut self, request: &RepositoryIssuesCountRequest, ) -> Result> { todo!() } - fn repository_issue_labels( + fn issue_labels( &mut self, request: &RepositoryIssueLabelsRequest, ) -> Result> { todo!() } - fn repository_issues( + fn issues( &mut self, request: &RepositoryIssuesRequest, ) -> Result> { diff --git a/src/backend/github.rs b/src/backend/github.rs new file mode 100644 index 0000000..051c8cb --- /dev/null +++ b/src/backend/github.rs @@ -0,0 +1,2 @@ +//! TODO: GitHub backend to allow for login with GitHub +//! accounts and interacting with GitHub repositories diff --git a/src/backend/mod.rs b/src/backend/mod.rs index be6e028..5d11e85 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -1,18 +1,25 @@ pub mod git; +pub mod github; use std::error::Error; use crate::{ - messages::repository::{ - CreateRepositoryRequest, CreateRepositoryResponse, RepositoryFileInspectRequest, - RepositoryFileInspectionResponse, RepositoryInfoRequest, RepositoryIssueLabelsRequest, - RepositoryIssueLabelsResponse, RepositoryIssuesCountRequest, RepositoryIssuesCountResponse, - RepositoryIssuesRequest, RepositoryIssuesResponse, + messages::{ + repository::{ + CreateRepositoryRequest, CreateRepositoryResponse, RepositoryFileInspectRequest, + RepositoryFileInspectionResponse, RepositoryInfoRequest, RepositoryIssueLabelsRequest, + RepositoryIssueLabelsResponse, RepositoryIssuesCountRequest, + RepositoryIssuesCountResponse, RepositoryIssuesRequest, RepositoryIssuesResponse, + }, + user::{ + UserBioRequest, UserBioResponse, UserDisplayImageRequest, UserDisplayImageResponse, + UserDisplayNameRequest, UserDisplayNameResponse, + }, }, model::repository::RepositoryView, }; -pub trait RepositoryBackend { +pub trait RepositoryBackend: IssuesBackend { fn create_repository( &mut self, request: &CreateRepositoryRequest, @@ -25,17 +32,39 @@ pub trait RepositoryBackend { &mut self, request: &RepositoryFileInspectRequest, ) -> Result>; +} - fn repository_issues_count( +pub trait IssuesBackend { + fn issues_count( &mut self, request: &RepositoryIssuesCountRequest, ) -> Result>; - fn repository_issue_labels( + fn issue_labels( &mut self, request: &RepositoryIssueLabelsRequest, ) -> Result>; - fn repository_issues( + fn issues( &mut self, request: &RepositoryIssuesRequest, ) -> Result>; } + +pub trait AuthBackend { + fn register(&mut self, request: ()) -> Result<(), Box>; + + fn login(&mut self, request: ()) -> Result<(), Box>; +} + +pub trait UserBackend { + fn display_name( + &mut self, + request: UserDisplayNameRequest, + ) -> Result>; + + fn display_image( + &mut self, + request: UserDisplayImageRequest, + ) -> Result>; + + fn bio(&mut self, request: UserBioRequest) -> Result>; +} diff --git a/src/connection.rs b/src/connection.rs index ee9d20d..49f03d3 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -13,7 +13,9 @@ use tokio::{ use tokio_tungstenite::{tungstenite::Message, WebSocketStream}; use crate::{ - backend::RepositoryBackend, + backend::{IssuesBackend, RepositoryBackend}, + handshake::{HandshakeFinalize, HandshakeMessage, HandshakeResponse, InitiateHandshake}, + listener::Listeners, messages::{ issues::IssuesCountResponse, repository::{ @@ -23,8 +25,6 @@ use crate::{ }, MessageKind, }, - handshake::{HandshakeFinalize, HandshakeMessage, HandshakeResponse, InitiateHandshake}, - listener::Listeners, model::{ instance::{Instance, InstanceMeta}, repository::{CommitMetadata, Repository, RepositoryView}, @@ -273,7 +273,7 @@ pub async fn connection_worker( } RepositoryRequest::IssuesCount(request) => { let mut backend = backend.lock().await; - let response = backend.repository_issues_count(request); + let response = backend.issues_count(request); let response = match response { Ok(response) => response, @@ -301,7 +301,7 @@ pub async fn connection_worker( } RepositoryRequest::IssueLabels(request) => { let mut backend = backend.lock().await; - let response = backend.repository_issue_labels(request); + let response = backend.issue_labels(request); let response = match response { Ok(response) => response, @@ -328,7 +328,7 @@ pub async fn connection_worker( } RepositoryRequest::Issues(request) => { let mut backend = backend.lock().await; - let response = backend.repository_issues(request); + let response = backend.issues(request); let response = match response { Ok(response) => response, diff --git a/src/lib.rs b/src/lib.rs index 80b0761..cebef1a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,8 @@ pub mod backend; -pub mod messages; pub mod connection; pub mod handshake; pub mod listener; +pub mod messages; pub mod model; #[macro_use] diff --git a/src/messages/mod.rs b/src/messages/mod.rs index 685145a..cb91226 100644 --- a/src/messages/mod.rs +++ b/src/messages/mod.rs @@ -6,6 +6,7 @@ use self::repository::RepositoryMessage; pub mod issues; pub mod repository; +pub mod user; #[derive(Clone, Serialize, Deserialize)] pub enum MessageKind { diff --git a/src/messages/user.rs b/src/messages/user.rs new file mode 100644 index 0000000..36a3d5f --- /dev/null +++ b/src/messages/user.rs @@ -0,0 +1,59 @@ +use serde::{Deserialize, Serialize}; + +use crate::model::{instance::Instance, user::User}; + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct UserMessage { + pub instance: Instance, + pub message: UserMessageKind, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub enum UserMessageKind { + Request(UserMessageRequest), + Response(UserMessageResponse), +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub enum UserMessageRequest { + DisplayName(UserDisplayNameRequest), + DisplayImage(UserDisplayImageRequest), + Bio(UserBioRequest), +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub enum UserMessageResponse { + DisplayName(UserDisplayImageResponse), + DisplayImage(UserDisplayImageResponse), + Bio(UserBioResponse), +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct UserDisplayNameRequest { + pub user: User, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct UserDisplayNameResponse { + pub display_name: String, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct UserDisplayImageRequest { + pub user: User, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct UserDisplayImageResponse { + pub image_url: String, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct UserBioRequest { + pub user: User, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct UserBioResponse { + pub bio: String, +} diff --git a/src/model/instance.rs b/src/model/instance.rs index 3d7e80f..91b20f5 100644 --- a/src/model/instance.rs +++ b/src/model/instance.rs @@ -5,7 +5,7 @@ pub struct InstanceMeta { pub public_key: String, } -#[derive(Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] pub struct Instance { pub url: String, } diff --git a/src/model/user.rs b/src/model/user.rs index 299f55e..ec83dce 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use super::instance::Instance; -#[derive(Clone, Hash, Serialize, Deserialize)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] pub struct User { pub username: String, pub instance: Instance,