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