1 |
pub mod discovery;
|
2 |
pub mod git;
|
3 |
pub mod github;
|
4 |
pub mod user;
|
5 |
|
6 |
use anyhow::Error;
|
7 |
use async_trait::async_trait;
|
8 |
|
9 |
use crate::{
|
10 |
messages::{
|
11 |
authentication::{
|
12 |
AuthenticationTokenRequest, AuthenticationTokenResponse, RegisterAccountRequest,
|
13 |
RegisterAccountResponse,
|
14 |
},
|
15 |
discovery::DiscoveryMessage,
|
16 |
repository::{
|
17 |
CreateRepositoryRequest, CreateRepositoryResponse, RepositoryFileInspectRequest,
|
18 |
RepositoryFileInspectionResponse, RepositoryInfoRequest, RepositoryIssueLabelsRequest,
|
19 |
RepositoryIssueLabelsResponse, RepositoryIssuesCountRequest,
|
20 |
RepositoryIssuesCountResponse, RepositoryIssuesRequest, RepositoryIssuesResponse,
|
21 |
},
|
22 |
user::{
|
23 |
UserBioRequest, UserBioResponse, UserDisplayImageRequest, UserDisplayImageResponse,
|
24 |
UserDisplayNameRequest, UserDisplayNameResponse,
|
25 |
},
|
26 |
ValidatedUserAuthenticated,
|
27 |
},
|
28 |
model::{
|
29 |
repository::{Repository, RepositorySummary, RepositoryView},
|
30 |
user::User,
|
31 |
},
|
32 |
};
|
33 |
|
34 |
#[async_trait]
|
35 |
pub trait RepositoryBackend: IssuesBackend {
|
36 |
async fn create_repository(
|
37 |
&mut self,
|
38 |
user: &User,
|
39 |
request: &CreateRepositoryRequest,
|
40 |
) -> Result<CreateRepositoryResponse, Error>;
|
41 |
async fn repository_info(
|
42 |
&mut self,
|
43 |
requester: Option<&User>,
|
44 |
request: &RepositoryInfoRequest,
|
45 |
) -> Result<RepositoryView, Error>;
|
46 |
async fn repository_file_inspect(
|
47 |
&mut self,
|
48 |
requester: Option<&User>,
|
49 |
request: &RepositoryFileInspectRequest,
|
50 |
) -> Result<RepositoryFileInspectionResponse, Error>;
|
51 |
async fn repositories_for_user(&mut self, user: &User)
|
52 |
-> Result<Vec<RepositorySummary>, Error>;
|
53 |
}
|
54 |
|
55 |
pub trait IssuesBackend {
|
56 |
fn issues_count(
|
57 |
&mut self,
|
58 |
request: &ValidatedUserAuthenticated<RepositoryIssuesCountRequest>,
|
59 |
) -> Result<RepositoryIssuesCountResponse, Error>;
|
60 |
fn issue_labels(
|
61 |
&mut self,
|
62 |
request: &ValidatedUserAuthenticated<RepositoryIssueLabelsRequest>,
|
63 |
) -> Result<RepositoryIssueLabelsResponse, Error>;
|
64 |
fn issues(
|
65 |
&mut self,
|
66 |
request: &ValidatedUserAuthenticated<RepositoryIssuesRequest>,
|
67 |
) -> Result<RepositoryIssuesResponse, Error>;
|
68 |
}
|
69 |
|
70 |
#[async_trait::async_trait]
|
71 |
pub trait AuthBackend {
|
72 |
async fn register(
|
73 |
&mut self,
|
74 |
request: RegisterAccountRequest,
|
75 |
) -> Result<RegisterAccountResponse, Error>;
|
76 |
|
77 |
async fn login(
|
78 |
&mut self,
|
79 |
request: AuthenticationTokenRequest,
|
80 |
) -> Result<AuthenticationTokenResponse, Error>;
|
81 |
}
|
82 |
|
83 |
#[async_trait::async_trait]
|
84 |
pub trait UserBackend: AuthBackend {
|
85 |
async fn display_name(
|
86 |
&mut self,
|
87 |
request: UserDisplayNameRequest,
|
88 |
) -> Result<UserDisplayNameResponse, Error>;
|
89 |
|
90 |
async fn display_image(
|
91 |
&mut self,
|
92 |
request: UserDisplayImageRequest,
|
93 |
) -> Result<UserDisplayImageResponse, Error>;
|
94 |
|
95 |
async fn bio(&mut self, request: UserBioRequest) -> Result<UserBioResponse, Error>;
|
96 |
async fn exists(&mut self, user: &User) -> Result<bool, Error>;
|
97 |
}
|
98 |
|
99 |
#[async_trait::async_trait]
|
100 |
pub trait DiscoveryBackend {
|
101 |
async fn try_handle(&mut self, request: &DiscoveryMessage) -> Result<bool, Error>;
|
102 |
async fn search(&mut self, search: &str) -> Result<Vec<Repository>, Error>;
|
103 |
}
|
104 |
|