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

ambee/giterated

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

Major post-refactor cleanup

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨f90d7fb

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