Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

brokkr-models::models::template_labels Rust

Structs

brokkr-models::models::template_labels::TemplateLabel

pub

Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ToSchema, ``

Represents a template label in the database.

Fields

NameTypeDescription
idUuidUnique identifier for the template label.
template_idUuidID of the template this label is associated with.
labelStringThe label text (max 64 characters, no whitespace).
created_atDateTime < Utc >Timestamp when the label was created.

brokkr-models::models::template_labels::NewTemplateLabel

pub

Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema

Represents a new template label to be inserted into the database.

Fields

NameTypeDescription
template_idUuidID of the template this label is associated with.
labelStringThe label text (max 64 characters, no whitespace).

Methods

new pub
#![allow(unused)]
fn main() {
fn new (template_id : Uuid , label : String) -> Result < Self , String >
}

Creates a new NewTemplateLabel instance.

Parameters:

NameTypeDescription
template_id-UUID of the template to associate the label with.
label-The label text. Must be non-empty, max 64 characters, no whitespace.

Returns:

Returns Ok(NewTemplateLabel) if all parameters are valid, otherwise returns an Err with a description of the validation failure.

Source
#![allow(unused)]
fn main() {
    pub fn new(template_id: Uuid, label: String) -> Result<Self, String> {
        // Validate template_id
        if template_id.is_nil() {
            return Err("Invalid template ID".to_string());
        }

        // Validate label
        if label.trim().is_empty() {
            return Err("Label cannot be empty".to_string());
        }

        // Check label length
        if label.len() > 64 {
            return Err("Label cannot exceed 64 characters".to_string());
        }

        // Check whitespace
        if label.contains(char::is_whitespace) {
            return Err("Label cannot contain whitespace".to_string());
        }

        Ok(NewTemplateLabel { template_id, label })
    }
}