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

ambee/giterated

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

woo

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨2d48bc0

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