//! 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>), Unauthorized, (status = 500, description = "Database error", body = ApiError) ))] #[gnauth(token_only)] pub async fn mapping_methods( ctx: Ctx, _token: AuthToken, ) -> Result>>, 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)) }