Files
oott/backend/src/model/devices.rs
T

60 lines
1.4 KiB
Rust
Raw Normal View History

2026-02-25 15:54:19 -05:00
use crate::utils::date_serializer;
use chrono::{DateTime, Utc};
2026-02-14 12:30:12 -05:00
use serde::{Deserialize, Serialize};
use std::fmt;
2026-05-27 13:36:05 -04:00
use utoipa::ToSchema;
2026-02-14 12:30:12 -05:00
2026-05-27 13:36:05 -04:00
#[derive(Clone, Serialize, Deserialize, ToSchema)]
2026-02-14 12:30:12 -05:00
pub struct Device {
pub mac_address: String,
pub ipv4_address: String,
pub vendor: String,
2026-02-25 15:54:19 -05:00
#[serde(with = "date_serializer")]
2026-05-27 13:36:05 -04:00
#[schema(value_type = String, format = DateTime)]
2026-02-14 12:30:12 -05:00
pub last_seen: DateTime<Utc>,
pub is_registered: bool,
pub owner: String,
pub device_type: String,
}
impl Device {
pub fn new(
mac_address: String,
ipv4_address: String,
vendor: String,
last_seen: DateTime<Utc>,
) -> Self {
Self {
2026-05-27 13:48:33 -04:00
mac_address,
ipv4_address,
vendor,
last_seen,
is_registered: false,
owner: "".to_string(),
device_type: "".to_string(),
}
}
2026-02-14 12:30:12 -05:00
}
impl fmt::Display for Device {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"mac={}, ip={}, vendor={}, last_seen={}, is_registered={}, owner={}, device_type={}",
self.mac_address,
self.ipv4_address,
self.vendor,
self.last_seen,
self.is_registered,
self.owner,
self.device_type
2026-02-14 12:30:12 -05:00
)
}
}
impl PartialEq for Device {
fn eq(&self, other: &Self) -> bool {
self.mac_address == other.mac_address
}
}