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

ambee/giterated

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

Fix settings serialization

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨a70c63a

⁨giterated-daemon/src/backend/mod.rs⁩ - ⁨3418⁩ 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 use serde_json::Value;
9
10 use crate::backend::git::GitBackendError;
11 use giterated_models::{
12 messages::{
13 authentication::{
14 AuthenticationTokenRequest, AuthenticationTokenResponse, RegisterAccountRequest,
15 RegisterAccountResponse,
16 },
17 repository::{
18 RepositoryCreateRequest, RepositoryCreateResponse, RepositoryFileInspectRequest,
19 RepositoryFileInspectionResponse, RepositoryInfoRequest, RepositoryIssueLabelsRequest,
20 RepositoryIssueLabelsResponse, RepositoryIssuesCountRequest,
21 RepositoryIssuesCountResponse, RepositoryIssuesRequest, RepositoryIssuesResponse,
22 },
23 user::{
24 UserBioRequest, UserBioResponse, UserDisplayImageRequest, UserDisplayImageResponse,
25 UserDisplayNameRequest, UserDisplayNameResponse,
26 },
27 },
28 model::{
29 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 user: &User,
39 request: &RepositoryCreateRequest,
40 ) -> Result<RepositoryCreateResponse, GitBackendError>;
41 async fn repository_info(
42 &mut self,
43 requester: Option<&User>,
44 request: &RepositoryInfoRequest,
45 ) -> Result<RepositoryView, Error>;
46 async fn repository_file_inspect(
47 &mut self,
48 requester: Option<&User>,
49 request: &RepositoryFileInspectRequest,
50 ) -> Result<RepositoryFileInspectionResponse, Error>;
51 async fn repositories_for_user(
52 &mut self,
53 requester: Option<&User>,
54 user: &User,
55 ) -> Result<Vec<RepositorySummary>, Error>;
56 }
57
58 pub trait IssuesBackend {
59 fn issues_count(
60 &mut self,
61 requester: Option<&User>,
62 request: &RepositoryIssuesCountRequest,
63 ) -> Result<RepositoryIssuesCountResponse, Error>;
64 fn issue_labels(
65 &mut self,
66 requester: Option<&User>,
67 request: &RepositoryIssueLabelsRequest,
68 ) -> Result<RepositoryIssueLabelsResponse, Error>;
69 fn issues(
70 &mut self,
71 requester: Option<&User>,
72 request: &RepositoryIssuesRequest,
73 ) -> Result<RepositoryIssuesResponse, Error>;
74 }
75
76 #[async_trait::async_trait]
77 pub trait AuthBackend {
78 async fn register(
79 &mut self,
80 request: RegisterAccountRequest,
81 ) -> Result<RegisterAccountResponse, Error>;
82
83 async fn login(
84 &mut self,
85 request: AuthenticationTokenRequest,
86 ) -> Result<AuthenticationTokenResponse, Error>;
87 }
88
89 #[async_trait::async_trait]
90 pub trait UserBackend: AuthBackend {
91 async fn display_name(
92 &mut self,
93 request: UserDisplayNameRequest,
94 ) -> Result<UserDisplayNameResponse, Error>;
95
96 async fn display_image(
97 &mut self,
98 request: UserDisplayImageRequest,
99 ) -> Result<UserDisplayImageResponse, Error>;
100
101 async fn bio(&mut self, request: UserBioRequest) -> Result<UserBioResponse, Error>;
102 async fn exists(&mut self, user: &User) -> Result<bool, Error>;
103
104 async fn settings(&mut self, user: &User) -> Result<Vec<(String, Value)>, Error>;
105 async fn write_settings(
106 &mut self,
107 user: &User,
108 settings: &[(String, String)],
109 ) -> Result<(), Error>;
110 }
111