Skip to content

brokkr-models::models::template_annotations

Rust

Template Annotation Module

This module defines structures and methods for managing template annotations. Template annotations are key-value pairs used for targeting validation.

Constraints

  • The template_id must be a valid, non-nil UUID.
  • The key must be a non-empty string, max 64 characters, no whitespace.
  • The value must be a non-empty string, max 64 characters, no whitespace.

pub

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

Represents a template annotation in the database.

Name Type Description
id Uuid Unique identifier for the template annotation.
template_id Uuid ID of the template this annotation is associated with.
key String The annotation key (max 64 characters, no whitespace).
value String The annotation value (max 64 characters, no whitespace).
created_at DateTime<Utc> Timestamp when the annotation was created.

pub

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

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

Name Type Description
template_id Uuid ID of the template this annotation is associated with.
key String The annotation key (max 64 characters, no whitespace).
value String The annotation value (max 64 characters, no whitespace).

pub

fn new(
template_id: Uuid,
key: String,
value: String,
) -> Result<Self, String>

Creates a new NewTemplateAnnotation instance.

Parameters:

Name Type Description
template_id Uuid UUID of the template to associate the annotation with.
key String The annotation key. Must be non-empty, max 64 characters, no whitespace.
value String 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
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,
})
}