about summary refs log tree commit diff
path: root/src/routes/mapping_methods.rs
blob: 224d90f713c47705d2a4573901b46fe87dc6dc22 (plain)
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
44
45
46
47
48
49
50
51
52
//! 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_next(
                "/groups",
                "Groups, each with the mapping tool offered for it (`mapping_method`)",
            ))
        })
        .map_err(|e| {
            ApiError::new(
                StatusCode::INTERNAL_SERVER_ERROR,
                "database_error",
                "Database error",
                e.to_string(),
                "mapping_methods",
            )
            .with_request_id(rid)
        })
}