Add more backend logic
parent: tbd commit: 5060ca2
Showing 9 changed files with 115 insertions and 22 deletions
src/backend/git.rs
@@ -10,7 +10,7 @@ use crate::{ | ||
10 | 10 | model::repository::RepositoryView, |
11 | 11 | }; |
12 | 12 | |
13 | use super::RepositoryBackend; | |
13 | use super::{IssuesBackend, RepositoryBackend}; | |
14 | 14 | |
15 | 15 | pub struct GitBackend; |
16 | 16 | |
@@ -41,22 +41,24 @@ impl RepositoryBackend for GitBackend { | ||
41 | 41 | ) -> Result<RepositoryFileInspectionResponse, Box<dyn Error + Send>> { |
42 | 42 | todo!() |
43 | 43 | } |
44 | } | |
44 | 45 | |
45 | fn repository_issues_count( | |
46 | impl IssuesBackend for GitBackend { | |
47 | fn issues_count( | |
46 | 48 | &mut self, |
47 | 49 | request: &RepositoryIssuesCountRequest, |
48 | 50 | ) -> Result<RepositoryIssuesCountResponse, Box<dyn Error + Send>> { |
49 | 51 | todo!() |
50 | 52 | } |
51 | 53 | |
52 | fn repository_issue_labels( | |
54 | fn issue_labels( | |
53 | 55 | &mut self, |
54 | 56 | request: &RepositoryIssueLabelsRequest, |
55 | 57 | ) -> Result<RepositoryIssueLabelsResponse, Box<dyn Error + Send>> { |
56 | 58 | todo!() |
57 | 59 | } |
58 | 60 | |
59 | fn repository_issues( | |
61 | fn issues( | |
60 | 62 | &mut self, |
61 | 63 | request: &RepositoryIssuesRequest, |
62 | 64 | ) -> Result<RepositoryIssuesResponse, Box<dyn Error + Send>> { |
src/backend/github.rs
@@ -0,0 +1,2 @@ | ||
1 | //! TODO: GitHub backend to allow for login with GitHub | |
2 | //! accounts and interacting with GitHub repositories |
src/backend/mod.rs
@@ -1,18 +1,25 @@ | ||
1 | 1 | pub mod git; |
2 | pub mod github; | |
2 | 3 | |
3 | 4 | use std::error::Error; |
4 | 5 | |
5 | 6 | use crate::{ |
6 | messages::repository::{ | |
7 | CreateRepositoryRequest, CreateRepositoryResponse, RepositoryFileInspectRequest, | |
8 | RepositoryFileInspectionResponse, RepositoryInfoRequest, RepositoryIssueLabelsRequest, | |
9 | RepositoryIssueLabelsResponse, RepositoryIssuesCountRequest, RepositoryIssuesCountResponse, | |
10 | RepositoryIssuesRequest, RepositoryIssuesResponse, | |
7 | messages::{ | |
8 | repository::{ | |
9 | CreateRepositoryRequest, CreateRepositoryResponse, RepositoryFileInspectRequest, | |
10 | RepositoryFileInspectionResponse, RepositoryInfoRequest, RepositoryIssueLabelsRequest, | |
11 | RepositoryIssueLabelsResponse, RepositoryIssuesCountRequest, | |
12 | RepositoryIssuesCountResponse, RepositoryIssuesRequest, RepositoryIssuesResponse, | |
13 | }, | |
14 | user::{ | |
15 | UserBioRequest, UserBioResponse, UserDisplayImageRequest, UserDisplayImageResponse, | |
16 | UserDisplayNameRequest, UserDisplayNameResponse, | |
17 | }, | |
11 | 18 | }, |
12 | 19 | model::repository::RepositoryView, |
13 | 20 | }; |
14 | 21 | |
15 | pub trait RepositoryBackend { | |
22 | pub trait RepositoryBackend: IssuesBackend { | |
16 | 23 | fn create_repository( |
17 | 24 | &mut self, |
18 | 25 | request: &CreateRepositoryRequest, |
@@ -25,17 +32,39 @@ pub trait RepositoryBackend { | ||
25 | 32 | &mut self, |
26 | 33 | request: &RepositoryFileInspectRequest, |
27 | 34 | ) -> Result<RepositoryFileInspectionResponse, Box<dyn Error + Send>>; |
35 | } | |
28 | 36 | |
29 | fn repository_issues_count( | |
37 | pub trait IssuesBackend { | |
38 | fn issues_count( | |
30 | 39 | &mut self, |
31 | 40 | request: &RepositoryIssuesCountRequest, |
32 | 41 | ) -> Result<RepositoryIssuesCountResponse, Box<dyn Error + Send>>; |
33 | fn repository_issue_labels( | |
42 | fn issue_labels( | |
34 | 43 | &mut self, |
35 | 44 | request: &RepositoryIssueLabelsRequest, |
36 | 45 | ) -> Result<RepositoryIssueLabelsResponse, Box<dyn Error + Send>>; |
37 | fn repository_issues( | |
46 | fn issues( | |
38 | 47 | &mut self, |
39 | 48 | request: &RepositoryIssuesRequest, |
40 | 49 | ) -> Result<RepositoryIssuesResponse, Box<dyn Error + Send>>; |
41 | 50 | } |
51 | ||
52 | pub trait AuthBackend { | |
53 | fn register(&mut self, request: ()) -> Result<(), Box<dyn Error + Send>>; | |
54 | ||
55 | fn login(&mut self, request: ()) -> Result<(), Box<dyn Error + Send>>; | |
56 | } | |
57 | ||
58 | pub trait UserBackend { | |
59 | fn display_name( | |
60 | &mut self, | |
61 | request: UserDisplayNameRequest, | |
62 | ) -> Result<UserDisplayNameResponse, Box<dyn Error + Send>>; | |
63 | ||
64 | fn display_image( | |
65 | &mut self, | |
66 | request: UserDisplayImageRequest, | |
67 | ) -> Result<UserDisplayImageResponse, Box<dyn Error + Send>>; | |
68 | ||
69 | fn bio(&mut self, request: UserBioRequest) -> Result<UserBioResponse, Box<dyn Error + Send>>; | |
70 | } |
src/connection.rs
@@ -13,7 +13,9 @@ use tokio::{ | ||
13 | 13 | use tokio_tungstenite::{tungstenite::Message, WebSocketStream}; |
14 | 14 | |
15 | 15 | use crate::{ |
16 | backend::RepositoryBackend, | |
16 | backend::{IssuesBackend, RepositoryBackend}, | |
17 | handshake::{HandshakeFinalize, HandshakeMessage, HandshakeResponse, InitiateHandshake}, | |
18 | listener::Listeners, | |
17 | 19 | messages::{ |
18 | 20 | issues::IssuesCountResponse, |
19 | 21 | repository::{ |
@@ -23,8 +25,6 @@ use crate::{ | ||
23 | 25 | }, |
24 | 26 | MessageKind, |
25 | 27 | }, |
26 | handshake::{HandshakeFinalize, HandshakeMessage, HandshakeResponse, InitiateHandshake}, | |
27 | listener::Listeners, | |
28 | 28 | model::{ |
29 | 29 | instance::{Instance, InstanceMeta}, |
30 | 30 | repository::{CommitMetadata, Repository, RepositoryView}, |
@@ -273,7 +273,7 @@ pub async fn connection_worker( | ||
273 | 273 | } |
274 | 274 | RepositoryRequest::IssuesCount(request) => { |
275 | 275 | let mut backend = backend.lock().await; |
276 | let response = backend.repository_issues_count(request); | |
276 | let response = backend.issues_count(request); | |
277 | 277 | |
278 | 278 | let response = match response { |
279 | 279 | Ok(response) => response, |
@@ -301,7 +301,7 @@ pub async fn connection_worker( | ||
301 | 301 | } |
302 | 302 | RepositoryRequest::IssueLabels(request) => { |
303 | 303 | let mut backend = backend.lock().await; |
304 | let response = backend.repository_issue_labels(request); | |
304 | let response = backend.issue_labels(request); | |
305 | 305 | |
306 | 306 | let response = match response { |
307 | 307 | Ok(response) => response, |
@@ -328,7 +328,7 @@ pub async fn connection_worker( | ||
328 | 328 | } |
329 | 329 | RepositoryRequest::Issues(request) => { |
330 | 330 | let mut backend = backend.lock().await; |
331 | let response = backend.repository_issues(request); | |
331 | let response = backend.issues(request); | |
332 | 332 | |
333 | 333 | let response = match response { |
334 | 334 | Ok(response) => response, |
src/lib.rs
@@ -1,8 +1,8 @@ | ||
1 | 1 | pub mod backend; |
2 | pub mod messages; | |
3 | 2 | pub mod connection; |
4 | 3 | pub mod handshake; |
5 | 4 | pub mod listener; |
5 | pub mod messages; | |
6 | 6 | pub mod model; |
7 | 7 | |
8 | 8 | #[macro_use] |
src/messages/mod.rs
@@ -6,6 +6,7 @@ use self::repository::RepositoryMessage; | ||
6 | 6 | |
7 | 7 | pub mod issues; |
8 | 8 | pub mod repository; |
9 | pub mod user; | |
9 | 10 | |
10 | 11 | #[derive(Clone, Serialize, Deserialize)] |
11 | 12 | pub enum MessageKind { |
src/messages/user.rs
@@ -0,0 +1,59 @@ | ||
1 | use serde::{Deserialize, Serialize}; | |
2 | ||
3 | use crate::model::{instance::Instance, user::User}; | |
4 | ||
5 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
6 | pub struct UserMessage { | |
7 | pub instance: Instance, | |
8 | pub message: UserMessageKind, | |
9 | } | |
10 | ||
11 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
12 | pub enum UserMessageKind { | |
13 | Request(UserMessageRequest), | |
14 | Response(UserMessageResponse), | |
15 | } | |
16 | ||
17 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
18 | pub enum UserMessageRequest { | |
19 | DisplayName(UserDisplayNameRequest), | |
20 | DisplayImage(UserDisplayImageRequest), | |
21 | Bio(UserBioRequest), | |
22 | } | |
23 | ||
24 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
25 | pub enum UserMessageResponse { | |
26 | DisplayName(UserDisplayImageResponse), | |
27 | DisplayImage(UserDisplayImageResponse), | |
28 | Bio(UserBioResponse), | |
29 | } | |
30 | ||
31 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
32 | pub struct UserDisplayNameRequest { | |
33 | pub user: User, | |
34 | } | |
35 | ||
36 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
37 | pub struct UserDisplayNameResponse { | |
38 | pub display_name: String, | |
39 | } | |
40 | ||
41 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
42 | pub struct UserDisplayImageRequest { | |
43 | pub user: User, | |
44 | } | |
45 | ||
46 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
47 | pub struct UserDisplayImageResponse { | |
48 | pub image_url: String, | |
49 | } | |
50 | ||
51 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
52 | pub struct UserBioRequest { | |
53 | pub user: User, | |
54 | } | |
55 | ||
56 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
57 | pub struct UserBioResponse { | |
58 | pub bio: String, | |
59 | } |
src/model/instance.rs
@@ -5,7 +5,7 @@ pub struct InstanceMeta { | ||
5 | 5 | pub public_key: String, |
6 | 6 | } |
7 | 7 | |
8 | #[derive(Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] | |
8 | #[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] | |
9 | 9 | pub struct Instance { |
10 | 10 | pub url: String, |
11 | 11 | } |
src/model/user.rs
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; | ||
2 | 2 | |
3 | 3 | use super::instance::Instance; |
4 | 4 | |
5 | #[derive(Clone, Hash, Serialize, Deserialize)] | |
5 | #[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] | |
6 | 6 | pub struct User { |
7 | 7 | pub username: String, |
8 | 8 | pub instance: Instance, |