1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use axum::{extract::Query, response::IntoResponse, Extension, Json};
use dialtone_common::rest::ap_objects::ap_object_exchanges::GetApObject;
use dialtone_sqlx::db::ap_object::fetch_sysinfo::fetch_ap_object_system_info;
use sqlx::{Pool, Postgres};

use crate::{
    authz::authz_ap_object::authz_contentadmin_for_ap_object,
    response::response_error::ResponseError,
    start_server::{Claims, SharedState},
};

pub async fn get_ap_object_sysinfo_handler(
    Query(params): Query<GetApObject>,
    _: Claims,
    Extension(pool): Extension<Pool<Postgres>>,
    Extension(state): Extension<SharedState>,
) -> Result<impl IntoResponse, ResponseError> {
    authz_contentadmin_for_ap_object(&state, &params.ap_object_id).await?;
    fetch_ap_object_system_info(&pool, &params.ap_object_id)
        .await?
        .map(|v| Json(v))
        .ok_or(ResponseError::not_found())
}