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

ambee/giterated

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

Begin new protocol refactor

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨26651b1

⁨giterated-daemon/src/backend/mod.rs⁩ - ⁨2938⁩ 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 model::{
14 authenticated::UserAuthenticationToken,
15 instance::Instance,
16 repository::{
17 IssueLabel, Repository, RepositoryIssue, RepositorySummary, RepositoryTreeEntry,
18 },
19 user::User,
20 },
21 operation::{
22 instance::{AuthenticationTokenRequest, RegisterAccountRequest, RepositoryCreateRequest},
23 repository::{
24 RepositoryFileInspectRequest, RepositoryIssueLabelsRequest,
25 RepositoryIssuesCountRequest, RepositoryIssuesRequest,
26 },
27 },
28 };
29
30 #[async_trait]
31 pub trait RepositoryBackend: IssuesBackend {
32 async fn create_repository(
33 &mut self,
34 user: &User,
35 request: &RepositoryCreateRequest,
36 ) -> Result<Repository, GitBackendError>;
37 async fn repository_file_inspect(
38 &mut self,
39 requester: Option<&User>,
40 request: &RepositoryFileInspectRequest,
41 ) -> Result<Vec<RepositoryTreeEntry>, Error>;
42 async fn repositories_for_user(
43 &mut self,
44 requester: Option<&User>,
45 user: &User,
46 ) -> Result<Vec<RepositorySummary>, Error>;
47 async fn exists(&mut self, repository: &Repository) -> Result<bool, Error>;
48 }
49
50 pub trait IssuesBackend {
51 fn issues_count(
52 &mut self,
53 requester: Option<&User>,
54 request: &RepositoryIssuesCountRequest,
55 ) -> Result<u64, Error>;
56 fn issue_labels(
57 &mut self,
58 requester: Option<&User>,
59 request: &RepositoryIssueLabelsRequest,
60 ) -> Result<Vec<IssueLabel>, Error>;
61 fn issues(
62 &mut self,
63 requester: Option<&User>,
64 request: &RepositoryIssuesRequest,
65 ) -> Result<Vec<RepositoryIssue>, Error>;
66 }
67
68 #[async_trait::async_trait]
69 pub trait AuthBackend {
70 async fn register(
71 &mut self,
72 request: RegisterAccountRequest,
73 ) -> Result<UserAuthenticationToken, Error>;
74
75 async fn login(
76 &mut self,
77 source: &Instance,
78 request: AuthenticationTokenRequest,
79 ) -> Result<UserAuthenticationToken, Error>;
80 }
81
82 #[async_trait::async_trait]
83 pub trait UserBackend: AuthBackend {
84 async fn exists(&mut self, user: &User) -> Result<bool, Error>;
85 }
86
87 #[async_trait::async_trait]
88 pub trait SettingsBackend: Send + Sync {
89 async fn user_get(&mut self, user: &User) -> Result<Vec<(String, Value)>, Error>;
90 async fn user_write(&mut self, user: &User, settings: &[(String, String)])
91 -> Result<(), Error>;
92
93 async fn repository_get(
94 &mut self,
95 repository: &Repository,
96 ) -> Result<Vec<(String, Value)>, Error>;
97 async fn repository_write(
98 &mut self,
99 repository: &Repository,
100 settings: &[(String, String)],
101 ) -> Result<(), Error>;
102 }
103