1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
//! Mapping methods domain endpoint: the mapping tools GeneNetwork offers.
use axum::Json;
use axum::http::StatusCode;
use gnauth_macros::gnauth;
use crate::auth::AuthToken;
use crate::db;
use crate::error::{ApiError, Unauthorized};
use crate::response::{Ctx, Envelope};
#[utoipa::path(get, path = "/mapping-methods", summary = "List the mapping tools (QTL mapping methods) GeneNetwork offers", responses(
(status = 200, description = "The MappingMethod rows, including tools no group currently uses", body = Envelope<Vec<db::MappingMethod>>),
Unauthorized,
(status = 500, description = "Database error", body = ApiError)
))]
#[gnauth(token_only)]
pub async fn mapping_methods(
ctx: Ctx,
_token: AuthToken,
) -> Result<Json<Envelope<Vec<db::MappingMethod>>>, ApiError> {
let rid = ctx.request_info();
tokio::task::spawn_blocking(db::get_mapping_methods)
.await
.map_err(|e| {
ApiError::new(
StatusCode::INTERNAL_SERVER_ERROR,
"internal_error",
"Internal error",
e.to_string(),
"mapping_methods",
)
.with_request_id(rid.clone())
})?
.map(|methods| {
Json(ctx.envelope(methods).with_links(crate::suggest::root_links()).with_next(
"/groups",
"Groups, each with the mapping tool offered for it (`mapping_method`)",
))
})
.map_err(|e| ApiError::from_db(e, "mapping_methods").with_request_id(rid))
}
|