|
| 1 | +use app::{ |
| 2 | + requests::post_json_request, |
| 3 | + responses::{APIResponse, APIRoutingError}, |
| 4 | + router::ParsedRequest, |
| 5 | +}; |
| 6 | +use serde::{Deserialize, Serialize}; |
| 7 | +use serde_json::Value as JSONValue; |
| 8 | +use utils::api::get_default_headers; |
| 9 | +use utoipa::ToSchema; |
| 10 | + |
| 11 | +use crate::api::routes::testbed::productizers::build_data_product_uri; |
| 12 | + |
| 13 | +#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone, ToSchema)] |
| 14 | +pub struct NSGAgentBasicInformationRequest { |
| 15 | + #[serde(rename = "nationalIdentifier")] |
| 16 | + pub national_identifier: String, |
| 17 | +} |
| 18 | + |
| 19 | +#[utoipa::path( |
| 20 | + post, |
| 21 | + path = "/testbed/productizer/nsg/basic-information", |
| 22 | + request_body( |
| 23 | + content = NSGAgentBasicInformationRequest, |
| 24 | + description = "Get company basic information input", |
| 25 | + examples( |
| 26 | + ( |
| 27 | + "Success" = ( |
| 28 | + summary = "National identifier", |
| 29 | + value = json!({ |
| 30 | + "nationalIdentifier": "2464491-9" |
| 31 | + }), |
| 32 | + ) |
| 33 | + ) |
| 34 | + ) |
| 35 | + ), |
| 36 | + params( |
| 37 | + ("source" = String, Query, description = "Data source: fi, se, no..", example = "fi"), |
| 38 | + ), |
| 39 | + responses(( |
| 40 | + status = 200, |
| 41 | + body = Object, |
| 42 | + description = "Basic information response", |
| 43 | + examples(( "Success" = ( |
| 44 | + summary = "JSON example", |
| 45 | + value = json!("Loading..."), |
| 46 | + external_value = "https://raw.githubusercontent.com/Virtual-Finland/definitions/main/DataProducts/draft/NSG/Agent/BasicInformation.json" |
| 47 | + ))) |
| 48 | + )) |
| 49 | +)] |
| 50 | +pub async fn get_nsg_basic_information(request: ParsedRequest) -> APIResponse { |
| 51 | + let request_input: NSGAgentBasicInformationRequest = |
| 52 | + serde_json::from_str(request.body.as_str())?; |
| 53 | + |
| 54 | + let data_product = "draft/NSG/Agent/BasicInformation"; |
| 55 | + let data_source = request.query.first("source").unwrap_or(""); |
| 56 | + if data_source.is_empty() { |
| 57 | + return Err(APIRoutingError::BadRequest( |
| 58 | + "Missing source parameter".to_string(), |
| 59 | + )); |
| 60 | + } |
| 61 | + |
| 62 | + let response = post_json_request::<NSGAgentBasicInformationRequest, JSONValue>( |
| 63 | + build_data_product_uri(data_product, data_source), |
| 64 | + &request_input, |
| 65 | + get_default_headers(), |
| 66 | + ) |
| 67 | + .await?; |
| 68 | + |
| 69 | + Ok(response) |
| 70 | +} |
0 commit comments