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

ambee/giterated

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

Fixed imports!

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨ef0e853

⁨giterated-daemon/src/backend/mod.rs⁩ - ⁨3663⁩ 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::authenticated::UserAuthenticationToken;
13
14 use giterated_models::instance::{
15 AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest,
16 };
17
18 use giterated_models::repository::{
19 IssueLabel, Repository, RepositoryFileInspectRequest, RepositoryIssue,
20 RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest,
21 RepositorySummary, RepositoryTreeEntry,
22 };
23 use giterated_models::settings::AnySetting;
24 use giterated_models::user::User;
25 use giterated_models::value::AnyValue;
26
27 #[async_trait]
28 pub trait RepositoryBackend {
29 async fn create_repository(
30 &mut self,
31 user: &User,
32 request: &RepositoryCreateRequest,
33 ) -> Result<Repository, GitBackendError>;
34 async fn repository_file_inspect(
35 &mut self,
36 requester: Option<&User>,
37 request: &RepositoryFileInspectRequest,
38 ) -> Result<Vec<RepositoryTreeEntry>, Error>;
39 async fn repositories_for_user(
40 &mut self,
41 requester: Option<&User>,
42 user: &User,
43 ) -> Result<Vec<RepositorySummary>, Error>;
44 async fn get_value(
45 &mut self,
46 user: &Repository,
47 name: &str,
48 ) -> Result<AnyValue<Repository>, Error>;
49 async fn get_setting(&mut self, user: &Repository, name: &str) -> Result<AnySetting, Error>;
50 async fn write_setting(
51 &mut self,
52 user: &Repository,
53 name: &str,
54 setting: &Value,
55 ) -> Result<(), Error>;
56 async fn exists(&mut self, repository: &Repository) -> Result<bool, Error>;
57 }
58
59 pub trait IssuesBackend {
60 fn issues_count(
61 &mut self,
62 requester: Option<&User>,
63 request: &RepositoryIssuesCountRequest,
64 ) -> Result<u64, Error>;
65 fn issue_labels(
66 &mut self,
67 requester: Option<&User>,
68 request: &RepositoryIssueLabelsRequest,
69 ) -> Result<Vec<IssueLabel>, Error>;
70 fn issues(
71 &mut self,
72 requester: Option<&User>,
73 request: &RepositoryIssuesRequest,
74 ) -> Result<Vec<RepositoryIssue>, Error>;
75 }
76
77 #[async_trait::async_trait]
78 pub trait AuthBackend {
79 async fn register(
80 &mut self,
81 request: RegisterAccountRequest,
82 ) -> Result<UserAuthenticationToken, Error>;
83
84 async fn login(
85 &mut self,
86 source: &Instance,
87 request: AuthenticationTokenRequest,
88 ) -> Result<UserAuthenticationToken, Error>;
89 }
90
91 #[async_trait::async_trait]
92 pub trait UserBackend: AuthBackend {
93 async fn get_value(&mut self, user: &User, name: &str) -> Result<AnyValue<User>, Error>;
94 async fn get_setting(&mut self, user: &User, name: &str) -> Result<AnySetting, Error>;
95 async fn write_setting(
96 &mut self,
97 user: &User,
98 name: &str,
99 setting: &Value,
100 ) -> Result<(), Error>;
101 async fn exists(&mut self, user: &User) -> Result<bool, Error>;
102 }
103
104 #[async_trait::async_trait]
105 pub trait MetadataBackend {
106 async fn user_get(&mut self, user: &User, name: &str) -> Result<AnySetting, Error>;
107 async fn user_write(
108 &mut self,
109 user: &User,
110 name: &str,
111 setting: AnySetting,
112 ) -> Result<(), Error>;
113 async fn repository_get(
114 &mut self,
115 repository: &Repository,
116 name: &str,
117 ) -> Result<AnySetting, Error>;
118 async fn repository_write(
119 &mut self,
120 repository: &Repository,
121 name: &str,
122 setting: AnySetting,
123 ) -> Result<(), Error>;
124 }
125