mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
37 lines
1.2 KiB
Rust
37 lines
1.2 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use axum::{Json, extract::Query, http::StatusCode};
|
|
use chrono::{DateTime, Utc};
|
|
use log::error;
|
|
|
|
use crate::{db, model::devices::Device};
|
|
|
|
use crate::web_server::utils;
|
|
|
|
pub async fn list_devices(
|
|
Query(params): Query<HashMap<String, String>>,
|
|
) -> Result<Json<Vec<Device>>, StatusCode> {
|
|
let is_registered: Option<bool> = utils::parse_parameter_bool(¶ms, "is_registered");
|
|
let last_seen_from: Option<DateTime<Utc>> =
|
|
utils::parse_parameter_date(¶ms, "last_seen_from");
|
|
let last_seen_to: Option<DateTime<Utc>> = utils::parse_parameter_date(¶ms, "last_seen_to");
|
|
let owner: Option<String> = utils::parse_parameter_string(¶ms, "owner");
|
|
let device_type: Option<String> = utils::parse_parameter_string(¶ms, "device_type");
|
|
let vendor: Option<String> = utils::parse_parameter_string(¶ms, "vendor");
|
|
|
|
match db::devices::list_devices(
|
|
is_registered,
|
|
last_seen_from,
|
|
last_seen_to,
|
|
owner,
|
|
device_type,
|
|
vendor,
|
|
) {
|
|
Ok(value) => Ok(Json(value)),
|
|
Err(err) => {
|
|
error!("Error listing devices: {}", err);
|
|
Err(StatusCode::INTERNAL_SERVER_ERROR)
|
|
}
|
|
}
|
|
}
|