brokkr-models::models::work_order_annotations
Rust
Work Order Annotation Module
This module defines structures and methods for managing work order annotations in the system.
Data Model
Work order annotations are key-value pairs used to target agents by their annotations.
They are stored in the work_order_annotations table with the following structure:
id: UUID, primary keywork_order_id: UUID, foreign key referencing thework_orderstablekey: VARCHAR(64), the annotation keyvalue: VARCHAR(64), the annotation valuecreated_at: Timestamp
Usage
Work order annotations allow work orders to target agents that have any of the specified key-value pairs. Matching is OR-based: if a work order has annotations {“region”: “us-east”, “tier”: “production”}, it will be available to any agent that has at least one of those key-value pairs.
Constraints
- The
work_order_idmust be a valid, non-nil UUID. - Both
keyandvaluemust be non-empty strings. - Both
keyandvaluemust not exceed 64 characters. - Neither
keynorvaluecan contain whitespace.
Structs
Section titled “Structs”struct WorkOrderAnnotation
Section titled “struct WorkOrderAnnotation”pub
Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash
Represents a work order annotation in the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
id |
Uuid |
Unique identifier for the annotation. |
work_order_id |
Uuid |
ID of the work order this annotation belongs to. |
key |
String |
Key of the annotation (max 64 characters, no whitespace). |
value |
String |
Value of the annotation (max 64 characters, no whitespace). |
created_at |
chrono::DateTime<chrono::Utc> |
Timestamp when the annotation was created. |
struct NewWorkOrderAnnotation
Section titled “struct NewWorkOrderAnnotation”pub
Derives: Insertable, Debug, Clone, Serialize, Deserialize
Represents a new work order annotation to be inserted into the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
work_order_id |
Uuid |
ID of the work order this annotation belongs to. |
key |
String |
Key of the annotation (max 64 characters, no whitespace). |
value |
String |
Value of the annotation (max 64 characters, no whitespace). |
Methods
Section titled “Methods”pub
fn new( work_order_id: Uuid, key: String, value: String,) -> Result<Self, String>Creates a new NewWorkOrderAnnotation instance.
Parameters:
| Name | Type | Description |
|---|---|---|
work_order_id |
Uuid |
UUID of the work order to associate the annotation with. |
key |
String |
The key for the annotation. Must be non-empty, max 64 characters, and contain no whitespace. |
value |
String |
The value for the annotation. Must be non-empty, max 64 characters, and contain no whitespace. |
Returns:
Returns Ok(NewWorkOrderAnnotation) if all parameters are valid,
otherwise returns an Err with a description of the validation failure.
Source
pub fn new(work_order_id: Uuid, key: String, value: String) -> Result<Self, String> { // Validate work_order_id if work_order_id.is_nil() { return Err("Invalid work order ID".to_string()); }
// Validate key if key.is_empty() { return Err("Key cannot be empty".to_string()); } if key.len() > 64 { return Err("Key cannot exceed 64 characters".to_string()); } if key.contains(char::is_whitespace) { return Err("Key cannot contain whitespace".to_string()); }
// Validate value if value.is_empty() { return Err("Value cannot be empty".to_string()); } if value.len() > 64 { return Err("Value cannot exceed 64 characters".to_string()); } if value.contains(char::is_whitespace) { return Err("Value cannot contain whitespace".to_string()); }
Ok(NewWorkOrderAnnotation { work_order_id, key, value, }) }