2024-02-12 01:03:29 +00:00
|
|
|
use super::plate::*;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
#[derive(PartialEq, Clone, Serialize, Deserialize)]
|
|
|
|
pub struct PlateInstance {
|
|
|
|
pub plate: Plate,
|
|
|
|
#[serde(rename = "id_v7")]
|
|
|
|
#[serde(default = "Uuid::now_v7")]
|
|
|
|
id: Uuid,
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PlateInstance {
|
|
|
|
pub fn new(sort: PlateType, format: PlateFormat, name: String) -> Self {
|
|
|
|
PlateInstance {
|
|
|
|
plate: Plate {
|
|
|
|
plate_type: sort,
|
|
|
|
plate_format: format,
|
|
|
|
},
|
|
|
|
id: Uuid::now_v7(),
|
|
|
|
name,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_uuid(&self) -> Uuid {
|
|
|
|
self.id
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn change_name(&mut self, new_name: String) {
|
|
|
|
self.name = new_name;
|
|
|
|
}
|
2024-02-12 03:04:03 +00:00
|
|
|
|
|
|
|
pub fn change_format(&mut self, new_format: &PlateFormat) {
|
|
|
|
self.plate.plate_format = *new_format;
|
|
|
|
}
|
2024-02-12 01:03:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Plate> for PlateInstance {
|
|
|
|
fn from(value: Plate) -> Self {
|
|
|
|
PlateInstance {
|
|
|
|
plate: value,
|
|
|
|
id: Uuid::now_v7(),
|
|
|
|
name: "New Plate".to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&PlateInstance> for String {
|
|
|
|
fn from(value: &PlateInstance) -> Self {
|
|
|
|
// Could have other formatting here
|
|
|
|
format!("{}, {}", value.name, value.plate.plate_format)
|
|
|
|
}
|
|
|
|
}
|