JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Add all the user request handling

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨e3bda14

⁨src/backend/mod.rs⁩ - ⁨3241⁩ bytes
Raw
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, RepositoryView},
30 user::User,
31 },
32 };
33
34 #[async_trait]
35 pub trait RepositoryBackend: IssuesBackend {
36 async fn create_repository(
37 &mut self,
38 request: &ValidatedUserAuthenticated<CreateRepositoryRequest>,
39 ) -> Result<CreateRepositoryResponse, Error>;
40 async fn repository_info(
41 &mut self,
42 request: &ValidatedUserAuthenticated<RepositoryInfoRequest>,
43 ) -> Result<RepositoryView, Error>;
44 fn repository_file_inspect(
45 &mut self,
46 request: &ValidatedUserAuthenticated<RepositoryFileInspectRequest>,
47 ) -> Result<RepositoryFileInspectionResponse, Error>;
48 async fn repositories_for_user(&mut self, user: &User) -> Result<Vec<Repository>, Error>;
49 }
50
51 pub trait IssuesBackend {
52 fn issues_count(
53 &mut self,
54 request: &ValidatedUserAuthenticated<RepositoryIssuesCountRequest>,
55 ) -> Result<RepositoryIssuesCountResponse, Error>;
56 fn issue_labels(
57 &mut self,
58 request: &ValidatedUserAuthenticated<RepositoryIssueLabelsRequest>,
59 ) -> Result<RepositoryIssueLabelsResponse, Error>;
60 fn issues(
61 &mut self,
62 request: &ValidatedUserAuthenticated<RepositoryIssuesRequest>,
63 ) -> Result<RepositoryIssuesResponse, Error>;
64 }
65
66 #[async_trait::async_trait]
67 pub trait AuthBackend {
68 async fn register(
69 &mut self,
70 request: RegisterAccountRequest,
71 ) -> Result<RegisterAccountResponse, Error>;
72
73 async fn login(
74 &mut self,
75 request: AuthenticationTokenRequest,
76 ) -> Result<AuthenticationTokenResponse, Error>;
77 }
78
79 #[async_trait::async_trait]
80 pub trait UserBackend: AuthBackend {
81 async fn display_name(
82 &mut self,
83 request: UserDisplayNameRequest,
84 ) -> Result<UserDisplayNameResponse, Error>;
85
86 async fn display_image(
87 &mut self,
88 request: UserDisplayImageRequest,
89 ) -> Result<UserDisplayImageResponse, Error>;
90
91 async fn bio(&mut self, request: UserBioRequest) -> Result<UserBioResponse, Error>;
92 }
93
94 #[async_trait::async_trait]
95 pub trait DiscoveryBackend {
96 async fn try_handle(&mut self, request: &DiscoveryMessage) -> Result<bool, Error>;
97 async fn search(&mut self, search: &str) -> Result<Vec<Repository>, Error>;
98 }
99