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

ambee/giterated

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

Progress on refactor

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨c9f076f

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