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_annotations Rust

Structs

brokkr-models::models::template_annotations::TemplateAnnotation

pub

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

Represents a template annotation in the database.

Fields

NameTypeDescription
idUuidUnique identifier for the template annotation.
template_idUuidID of the template this annotation is associated with.
keyStringThe annotation key (max 64 characters, no whitespace).
valueStringThe annotation value (max 64 characters, no whitespace).
created_atDateTime < Utc >Timestamp when the annotation was created.

brokkr-models::models::template_annotations::NewTemplateAnnotation

pub

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

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

Fields

NameTypeDescription
template_idUuidID of the template this annotation is associated with.
keyStringThe annotation key (max 64 characters, no whitespace).
valueStringThe annotation value (max 64 characters, no whitespace).

Methods

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

Creates a new NewTemplateAnnotation instance.

Parameters:

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

Returns:

Returns Ok(NewTemplateAnnotation) 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, key: String, value: String) -> Result<Self, String> {
        // Validate template_id
        if template_id.is_nil() {
            return Err("Invalid template ID".to_string());
        }

        // Validate key
        if key.trim().is_empty() {
            return Err("Annotation key cannot be empty".to_string());
        }
        if key.len() > 64 {
            return Err("Annotation key cannot exceed 64 characters".to_string());
        }
        if key.contains(char::is_whitespace) {
            return Err("Annotation key cannot contain whitespace".to_string());
        }

        // Validate value
        if value.trim().is_empty() {
            return Err("Annotation value cannot be empty".to_string());
        }
        if value.len() > 64 {
            return Err("Annotation value cannot exceed 64 characters".to_string());
        }
        if value.contains(char::is_whitespace) {
            return Err("Annotation value cannot contain whitespace".to_string());
        }

        Ok(NewTemplateAnnotation {
            template_id,
            key,
            value,
        })
    }
}