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

ambee/giterated

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

Fixes!

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨398622e

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