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

ambee/giterated

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

Add repository settings

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨f8eaf38

⁨giterated-daemon/src/backend/mod.rs⁩ - ⁨3770⁩ bytes
Raw
1 pub mod discovery;
2 pub mod git;
3 pub mod github;
4 pub mod settings;
5 pub mod user;
6
7 use anyhow::Error;
8 use async_trait::async_trait;
9 use serde_json::Value;
10
11 use crate::backend::git::GitBackendError;
12 use giterated_models::{
13 messages::{
14 authentication::{
15 AuthenticationTokenRequest, AuthenticationTokenResponse, RegisterAccountRequest,
16 RegisterAccountResponse,
17 },
18 repository::{
19 RepositoryCreateRequest, RepositoryCreateResponse, RepositoryFileInspectRequest,
20 RepositoryFileInspectionResponse, RepositoryInfoRequest, RepositoryIssueLabelsRequest,
21 RepositoryIssueLabelsResponse, RepositoryIssuesCountRequest,
22 RepositoryIssuesCountResponse, RepositoryIssuesRequest, RepositoryIssuesResponse,
23 },
24 user::{
25 UserBioRequest, UserBioResponse, UserDisplayImageRequest, UserDisplayImageResponse,
26 UserDisplayNameRequest, UserDisplayNameResponse,
27 },
28 },
29 model::{
30 repository::{Repository, RepositorySummary, RepositoryView},
31 user::User,
32 },
33 };
34
35 #[async_trait]
36 pub trait RepositoryBackend: IssuesBackend {
37 async fn create_repository(
38 &mut self,
39 user: &User,
40 request: &RepositoryCreateRequest,
41 ) -> Result<RepositoryCreateResponse, GitBackendError>;
42 async fn repository_info(
43 &mut self,
44 requester: Option<&User>,
45 request: &RepositoryInfoRequest,
46 ) -> Result<RepositoryView, Error>;
47 async fn repository_file_inspect(
48 &mut self,
49 requester: Option<&User>,
50 request: &RepositoryFileInspectRequest,
51 ) -> Result<RepositoryFileInspectionResponse, Error>;
52 async fn repositories_for_user(
53 &mut self,
54 requester: Option<&User>,
55 user: &User,
56 ) -> Result<Vec<RepositorySummary>, Error>;
57 }
58
59 pub trait IssuesBackend {
60 fn issues_count(
61 &mut self,
62 requester: Option<&User>,
63 request: &RepositoryIssuesCountRequest,
64 ) -> Result<RepositoryIssuesCountResponse, Error>;
65 fn issue_labels(
66 &mut self,
67 requester: Option<&User>,
68 request: &RepositoryIssueLabelsRequest,
69 ) -> Result<RepositoryIssueLabelsResponse, Error>;
70 fn issues(
71 &mut self,
72 requester: Option<&User>,
73 request: &RepositoryIssuesRequest,
74 ) -> Result<RepositoryIssuesResponse, Error>;
75 }
76
77 #[async_trait::async_trait]
78 pub trait AuthBackend {
79 async fn register(
80 &mut self,
81 request: RegisterAccountRequest,
82 ) -> Result<RegisterAccountResponse, Error>;
83
84 async fn login(
85 &mut self,
86 request: AuthenticationTokenRequest,
87 ) -> Result<AuthenticationTokenResponse, Error>;
88 }
89
90 #[async_trait::async_trait]
91 pub trait UserBackend: AuthBackend {
92 async fn display_name(
93 &mut self,
94 request: UserDisplayNameRequest,
95 ) -> Result<UserDisplayNameResponse, Error>;
96
97 async fn display_image(
98 &mut self,
99 request: UserDisplayImageRequest,
100 ) -> Result<UserDisplayImageResponse, Error>;
101
102 async fn bio(&mut self, request: UserBioRequest) -> Result<UserBioResponse, Error>;
103 async fn exists(&mut self, user: &User) -> Result<bool, Error>;
104 }
105
106 #[async_trait::async_trait]
107 pub trait SettingsBackend: Send + Sync {
108 async fn user_get(&mut self, user: &User) -> Result<Vec<(String, Value)>, Error>;
109 async fn user_write(&mut self, user: &User, settings: &[(String, String)])
110 -> Result<(), Error>;
111
112 async fn repository_get(
113 &mut self,
114 repository: &Repository,
115 ) -> Result<Vec<(String, Value)>, Error>;
116 async fn repository_write(
117 &mut self,
118 repository: &Repository,
119 settings: &[(String, String)],
120 ) -> Result<(), Error>;
121 }
122