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