brokkr-models::models::work_order_labels
Rust
Work Order Label Module
This module defines structures and methods for managing work order labels in the system.
Data Model
Work order labels are used to target agents by their labels. They are stored in the
work_order_labels table with the following structure:
id: UUID, primary keywork_order_id: UUID, foreign key referencing thework_orderstablelabel: VARCHAR(64), the label to match against agent labelscreated_at: Timestamp
Usage
Work order labels allow work orders to target agents that have any of the specified labels. Matching is OR-based: if a work order has labels [“gpu”, “production”], it will be available to any agent that has at least one of those labels.
Constraints
- The
work_order_idmust be a valid, non-nil UUID. - The
labelmust be a non-empty string. - The
labelmust not exceed 64 characters. - The
labelcannot contain whitespace.
Structs
Section titled “Structs”struct WorkOrderLabel
Section titled “struct WorkOrderLabel”pub
Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash
Represents a work order label in the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
id |
Uuid |
Unique identifier for the work order label. |
work_order_id |
Uuid |
ID of the work order this label is associated with. |
label |
String |
The label text (max 64 characters, no whitespace). |
created_at |
chrono::DateTime<chrono::Utc> |
Timestamp when the label was created. |
struct NewWorkOrderLabel
Section titled “struct NewWorkOrderLabel”pub
Derives: Insertable, Debug, Clone, Serialize, Deserialize
Represents a new work order label to be inserted into the database.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
work_order_id |
Uuid |
ID of the work order this label is associated with. |
label |
String |
The label text (max 64 characters, no whitespace). |
Methods
Section titled “Methods”pub
fn new(work_order_id: Uuid, label: String) -> Result<Self, String>Creates a new NewWorkOrderLabel instance.
Parameters:
| Name | Type | Description |
|---|---|---|
work_order_id |
Uuid |
UUID of the work order to associate the label with. |
label |
String |
The label text. Must be non-empty, max 64 characters, and contain no whitespace. |
Returns:
Returns Ok(NewWorkOrderLabel) if all parameters are valid,
otherwise returns an Err with a description of the validation failure.
Source
pub fn new(work_order_id: Uuid, label: String) -> Result<Self, String> { // Validate work_order_id if work_order_id.is_nil() { return Err("Invalid work order 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(NewWorkOrderLabel { work_order_id, label, }) }