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

ambee/giterated

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

Add RepositorySummary and return in user repositories

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨8512ab4

⁨src/backend/mod.rs⁩ - ⁨3275⁩ 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, 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 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)
49 -> Result<Vec<RepositorySummary>, Error>;
50 }
51
52 pub trait IssuesBackend {
53 fn issues_count(
54 &mut self,
55 request: &ValidatedUserAuthenticated<RepositoryIssuesCountRequest>,
56 ) -> Result<RepositoryIssuesCountResponse, Error>;
57 fn issue_labels(
58 &mut self,
59 request: &ValidatedUserAuthenticated<RepositoryIssueLabelsRequest>,
60 ) -> Result<RepositoryIssueLabelsResponse, Error>;
61 fn issues(
62 &mut self,
63 request: &ValidatedUserAuthenticated<RepositoryIssuesRequest>,
64 ) -> Result<RepositoryIssuesResponse, Error>;
65 }
66
67 #[async_trait::async_trait]
68 pub trait AuthBackend {
69 async fn register(
70 &mut self,
71 request: RegisterAccountRequest,
72 ) -> Result<RegisterAccountResponse, Error>;
73
74 async fn login(
75 &mut self,
76 request: AuthenticationTokenRequest,
77 ) -> Result<AuthenticationTokenResponse, Error>;
78 }
79
80 #[async_trait::async_trait]
81 pub trait UserBackend: AuthBackend {
82 async fn display_name(
83 &mut self,
84 request: UserDisplayNameRequest,
85 ) -> Result<UserDisplayNameResponse, Error>;
86
87 async fn display_image(
88 &mut self,
89 request: UserDisplayImageRequest,
90 ) -> Result<UserDisplayImageResponse, Error>;
91
92 async fn bio(&mut self, request: UserBioRequest) -> Result<UserBioResponse, Error>;
93 }
94
95 #[async_trait::async_trait]
96 pub trait DiscoveryBackend {
97 async fn try_handle(&mut self, request: &DiscoveryMessage) -> Result<bool, Error>;
98 async fn search(&mut self, search: &str) -> Result<Vec<Repository>, Error>;
99 }
100