97 lines
2.6 KiB
Rust
97 lines
2.6 KiB
Rust
use heromodels_core::BaseModelData;
|
|
use heromodels_derive::model;
|
|
use rhai::{CustomType, TypeBuilder};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// Represents a collection of library items.
|
|
#[model]
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType)]
|
|
pub struct Collection {
|
|
/// Base model data
|
|
pub base_data: BaseModelData,
|
|
/// Title of the collection
|
|
#[index]
|
|
pub title: String,
|
|
/// Optional description of the collection
|
|
pub description: Option<String>,
|
|
/// List of image item IDs belonging to this collection
|
|
pub images: Vec<u32>,
|
|
/// List of PDF item IDs belonging to this collection
|
|
pub pdfs: Vec<u32>,
|
|
/// List of Markdown item IDs belonging to this collection
|
|
pub markdowns: Vec<u32>,
|
|
/// List of Book item IDs belonging to this collection
|
|
pub books: Vec<u32>,
|
|
/// List of Slides item IDs belonging to this collection
|
|
pub slides: Vec<u32>,
|
|
}
|
|
|
|
impl Default for Collection {
|
|
fn default() -> Self {
|
|
Self {
|
|
base_data: BaseModelData::new(),
|
|
title: String::new(),
|
|
description: None,
|
|
images: Vec::new(),
|
|
pdfs: Vec::new(),
|
|
markdowns: Vec::new(),
|
|
books: Vec::new(),
|
|
slides: Vec::new(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Collection {
|
|
/// Creates a new `Collection` with default values.
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
/// Returns the ID of the collection.
|
|
pub fn id(&self) -> u32 {
|
|
self.base_data.id
|
|
}
|
|
|
|
/// Sets the title of the collection.
|
|
pub fn title(mut self, title: impl Into<String>) -> Self {
|
|
self.title = title.into();
|
|
self
|
|
}
|
|
|
|
/// Sets the description of the collection.
|
|
pub fn description(mut self, description: impl Into<String>) -> Self {
|
|
self.description = Some(description.into());
|
|
self
|
|
}
|
|
|
|
/// Adds an image ID to the collection.
|
|
pub fn add_image(mut self, image_id: u32) -> Self {
|
|
self.images.push(image_id);
|
|
self
|
|
}
|
|
|
|
/// Adds a PDF ID to the collection.
|
|
pub fn add_pdf(mut self, pdf_id: u32) -> Self {
|
|
self.pdfs.push(pdf_id);
|
|
self
|
|
}
|
|
|
|
/// Adds a markdown ID to the collection.
|
|
pub fn add_markdown(mut self, markdown_id: u32) -> Self {
|
|
self.markdowns.push(markdown_id);
|
|
self
|
|
}
|
|
|
|
/// Adds a book ID to the collection.
|
|
pub fn add_book(mut self, book_id: u32) -> Self {
|
|
self.books.push(book_id);
|
|
self
|
|
}
|
|
|
|
/// Adds a slides ID to the collection.
|
|
pub fn add_slides(mut self, slides_id: u32) -> Self {
|
|
self.slides.push(slides_id);
|
|
self
|
|
}
|
|
}
|