use std::collections::HashMap; use axum::{ Json, extract::{Path, Query}, http::StatusCode, }; use log::error; use crate::{db, model::device_events::DeviceEvent, web_server::utils}; #[utoipa::path( get, path = "/api/devices/{mac_address}/events", tag = "device_events", params( ("mac_address" = String, Path, description = "MAC address of the device"), ("page_offset" = Option, Query, description = "Pagination offset"), ("page_limit" = Option, Query, description = "Maximum number of results to return"), ), responses( (status = 200, description = "List of device events", body = Vec), (status = 500, description = "Internal server error"), ), security(("bearer_auth" = [])) )] pub async fn list( Path(mac_address): Path, Query(params): Query>, ) -> Result>, StatusCode> { let page_offset: Option = utils::parse_parameter_int(¶ms, "page_offset"); let page_limit: Option = utils::parse_parameter_int(¶ms, "page_limit"); match db::device_events::list(Some(mac_address), page_offset, page_limit) { Ok(value) => Ok(Json(value)), Err(err) => { error!("Error listing device events: {}", err); Err(StatusCode::INTERNAL_SERVER_ERROR) } } }