first commit

This commit is contained in:
Timur Gordon
2025-10-20 22:24:25 +02:00
commit 097360ad12
48 changed files with 6712 additions and 0 deletions

78
src/store/base_data.rs Normal file
View File

@@ -0,0 +1,78 @@
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
/// Base data that all OSIRIS objects must include
/// Similar to heromodels BaseModelData but adapted for OSIRIS
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct BaseData {
/// Unique ID (auto-generated or user-assigned)
pub id: String,
/// Namespace this object belongs to
pub ns: String,
/// Unix timestamp for creation time
#[serde(with = "time::serde::timestamp")]
pub created_at: OffsetDateTime,
/// Unix timestamp for last modification time
#[serde(with = "time::serde::timestamp")]
pub modified_at: OffsetDateTime,
/// Optional MIME type
pub mime: Option<String>,
/// Content size in bytes
pub size: Option<u64>,
}
impl BaseData {
/// Create new base data with generated UUID
pub fn new(ns: String) -> Self {
let now = OffsetDateTime::now_utc();
Self {
id: uuid::Uuid::new_v4().to_string(),
ns,
created_at: now,
modified_at: now,
mime: None,
size: None,
}
}
/// Create new base data with specific ID
pub fn with_id(id: String, ns: String) -> Self {
let now = OffsetDateTime::now_utc();
Self {
id,
ns,
created_at: now,
modified_at: now,
mime: None,
size: None,
}
}
/// Update the modified timestamp
pub fn update_modified(&mut self) {
self.modified_at = OffsetDateTime::now_utc();
}
/// Set the MIME type
pub fn set_mime(&mut self, mime: Option<String>) {
self.mime = mime;
self.update_modified();
}
/// Set the size
pub fn set_size(&mut self, size: Option<u64>) {
self.size = size;
self.update_modified();
}
}
impl Default for BaseData {
fn default() -> Self {
Self::new(String::from("default"))
}
}