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

ambee/giterated

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

Major post-refactor cleanup

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨f90d7fb

⁨src/connection/repository.rs⁩ - ⁨3588⁩ bytes
Raw
1 use anyhow::Error;
2
3 use crate::{
4 messages::repository::{
5 CreateRepositoryRequest, RepositoryFileInspectRequest, RepositoryInfoRequest,
6 RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest,
7 },
8 model::authenticated::{AuthenticatedUser, Message, MessageHandler, NetworkMessage, State},
9 };
10
11 use super::{wrapper::ConnectionState, HandlerUnhandled};
12
13 pub async fn repository_handle(
14 message: &NetworkMessage,
15 state: &ConnectionState,
16 ) -> Result<(), Error> {
17 if create_repository
18 .handle_message(&message, state)
19 .await
20 .is_ok()
21 {
22 Ok(())
23 } else if repository_file_inspect
24 .handle_message(&message, state)
25 .await
26 .is_ok()
27 {
28 Ok(())
29 } else if repository_info
30 .handle_message(&message, state)
31 .await
32 .is_ok()
33 {
34 Ok(())
35 } else if issues_count.handle_message(&message, state).await.is_ok() {
36 Ok(())
37 } else if issue_labels.handle_message(&message, state).await.is_ok() {
38 Ok(())
39 } else if issues.handle_message(&message, state).await.is_ok() {
40 Ok(())
41 } else {
42 Err(Error::from(HandlerUnhandled))
43 }
44 }
45
46 async fn create_repository(
47 Message(request): Message<CreateRepositoryRequest>,
48 State(connection_state): State<ConnectionState>,
49 AuthenticatedUser(user): AuthenticatedUser,
50 ) -> Result<(), RepositoryError> {
51 let mut repository_backend = connection_state.repository_backend.lock().await;
52 let response = repository_backend
53 .create_repository(&user, &request)
54 .await?;
55
56 drop(repository_backend);
57
58 connection_state.send(response).await?;
59
60 Ok(())
61 }
62
63 async fn repository_file_inspect(
64 Message(request): Message<RepositoryFileInspectRequest>,
65 State(connection_state): State<ConnectionState>,
66 user: Option<AuthenticatedUser>,
67 ) -> Result<(), RepositoryError> {
68 let user = user.map(|u| u.0);
69
70 let mut repository_backend = connection_state.repository_backend.lock().await;
71 let response = repository_backend
72 .repository_file_inspect(user.as_ref(), &request)
73 .await?;
74
75 drop(repository_backend);
76
77 connection_state.send(response).await?;
78
79 Ok(())
80 }
81
82 async fn repository_info(
83 Message(request): Message<RepositoryInfoRequest>,
84 State(connection_state): State<ConnectionState>,
85 user: Option<AuthenticatedUser>,
86 ) -> Result<(), RepositoryError> {
87 let user = user.map(|u| u.0);
88
89 let mut repository_backend = connection_state.repository_backend.lock().await;
90 let response = repository_backend
91 .repository_info(user.as_ref(), &request)
92 .await?;
93
94 drop(repository_backend);
95
96 connection_state.send(response).await?;
97
98 Ok(())
99 }
100
101 async fn issues_count(
102 Message(_request): Message<RepositoryIssuesCountRequest>,
103 State(_connection_state): State<ConnectionState>,
104 _user: Option<AuthenticatedUser>,
105 ) -> Result<(), RepositoryError> {
106 unimplemented!();
107 }
108
109 async fn issue_labels(
110 Message(_request): Message<RepositoryIssueLabelsRequest>,
111 State(_connection_state): State<ConnectionState>,
112 _user: Option<AuthenticatedUser>,
113 ) -> Result<(), RepositoryError> {
114 unimplemented!();
115 }
116
117 async fn issues(
118 Message(_request): Message<RepositoryIssuesRequest>,
119 State(_connection_state): State<ConnectionState>,
120 _user: Option<AuthenticatedUser>,
121 ) -> Result<(), RepositoryError> {
122 unimplemented!();
123 }
124
125 #[derive(Debug, thiserror::Error)]
126 pub enum RepositoryError {
127 #[error("{0}")]
128 Other(#[from] Error),
129 }
130