Skip to main content

text_document_frontend/commands/
root_commands.rs

1// Generated by Qleany v1.5.0 from frontend_entity_commands.tera
2
3//! Root entity commands
4#![allow(unused_imports, dead_code)]
5
6use crate::app_context::AppContext;
7use anyhow::{Context, Result};
8use common::direct_access::root::RootRelationshipField;
9use common::types::EntityId;
10use direct_access::RootRelationshipDto;
11use direct_access::{CreateRootDto, RootDto, UpdateRootDto, root_controller};
12
13/// Create a new root entity (orphan, no parent)
14pub fn create_orphan_root(ctx: &AppContext, dto: &CreateRootDto) -> Result<RootDto> {
15    root_controller::create_orphan(&ctx.db_context, &ctx.event_hub, dto).context("creating root")
16}
17/// Create multiple root entities (orphan, no parent)
18pub fn create_orphan_root_multi(ctx: &AppContext, dtos: &[CreateRootDto]) -> Result<Vec<RootDto>> {
19    root_controller::create_orphan_multi(&ctx.db_context, &ctx.event_hub, dtos)
20        .context("creating root entities")
21}
22/// Get a root entity by ID
23pub fn get_root(ctx: &AppContext, id: &EntityId) -> Result<Option<RootDto>> {
24    root_controller::get(&ctx.db_context, id).context("getting root")
25}
26
27/// Get multiple root entities by IDs
28pub fn get_root_multi(ctx: &AppContext, ids: &[EntityId]) -> Result<Vec<Option<RootDto>>> {
29    root_controller::get_multi(&ctx.db_context, ids).context("getting root entities")
30}
31
32/// Get all root entities.
33/// Note: returns entities in database key order (by EntityId), not insertion order
34/// or any user-defined sort. For ordered collections, use relationship-based
35/// retrieval (e.g. get_*_relationship for ordered_one_to_many fields).
36pub fn get_all_root(ctx: &AppContext) -> Result<Vec<RootDto>> {
37    root_controller::get_all(&ctx.db_context).context("getting all root entities")
38}
39
40/// Update a root entity
41pub fn update_root(ctx: &AppContext, dto: &UpdateRootDto) -> Result<RootDto> {
42    root_controller::update(&ctx.db_context, &ctx.event_hub, dto).context("updating root")
43}
44
45/// Update multiple root entities
46pub fn update_root_multi(ctx: &AppContext, dtos: &[UpdateRootDto]) -> Result<Vec<RootDto>> {
47    root_controller::update_multi(&ctx.db_context, &ctx.event_hub, dtos)
48        .context("updating root entities")
49}
50
51/// Update a root entity with relationships
52pub fn update_root_with_relationships(ctx: &AppContext, dto: &RootDto) -> Result<RootDto> {
53    root_controller::update_with_relationships(&ctx.db_context, &ctx.event_hub, dto)
54        .context("updating root with relationships")
55}
56
57/// Update multiple root entities with relationships
58pub fn update_root_with_relationships_multi(
59    ctx: &AppContext,
60
61    dtos: &[RootDto],
62) -> Result<Vec<RootDto>> {
63    root_controller::update_with_relationships_multi(&ctx.db_context, &ctx.event_hub, dtos)
64        .context("updating root entities with relationships")
65}
66
67/// Remove a root entity by ID
68pub fn remove_root(ctx: &AppContext, id: &EntityId) -> Result<()> {
69    root_controller::remove(&ctx.db_context, &ctx.event_hub, id).context("removing root")
70}
71
72/// Remove multiple root entities by IDs
73pub fn remove_root_multi(ctx: &AppContext, ids: &[EntityId]) -> Result<()> {
74    root_controller::remove_multi(&ctx.db_context, &ctx.event_hub, ids)
75        .context("removing root entities")
76}
77
78/// Get a root relationship
79pub fn get_root_relationship(
80    ctx: &AppContext,
81    id: &EntityId,
82    field: &RootRelationshipField,
83) -> Result<Vec<EntityId>> {
84    root_controller::get_relationship(&ctx.db_context, id, field)
85        .context("getting root relationship")
86}
87
88/// Get relationship IDs for multiple root entities at once
89pub fn get_root_relationship_many(
90    ctx: &AppContext,
91    ids: &[EntityId],
92    field: &RootRelationshipField,
93) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>> {
94    root_controller::get_relationship_many(&ctx.db_context, ids, field)
95        .context("getting root relationships (many)")
96}
97
98/// Get relationship count for a root entity
99pub fn get_root_relationship_count(
100    ctx: &AppContext,
101    id: &EntityId,
102    field: &RootRelationshipField,
103) -> Result<usize> {
104    root_controller::get_relationship_count(&ctx.db_context, id, field)
105        .context("getting root relationship count")
106}
107
108/// Get relationship IDs for a root entity with pagination
109pub fn get_root_relationship_in_range(
110    ctx: &AppContext,
111    id: &EntityId,
112    field: &RootRelationshipField,
113    offset: usize,
114    limit: usize,
115) -> Result<Vec<EntityId>> {
116    root_controller::get_relationship_in_range(&ctx.db_context, id, field, offset, limit)
117        .context("getting root relationship range")
118}
119
120/// Set a root relationship
121pub fn set_root_relationship(ctx: &AppContext, dto: &RootRelationshipDto) -> Result<()> {
122    root_controller::set_relationship(&ctx.db_context, &ctx.event_hub, dto)
123        .context("setting root relationship")
124}
125
126/// Move (reorder) IDs within a root relationship
127pub fn move_root_relationship(
128    ctx: &AppContext,
129
130    id: &EntityId,
131    field: &RootRelationshipField,
132    ids_to_move: &[EntityId],
133    new_index: i32,
134) -> Result<Vec<EntityId>> {
135    root_controller::move_relationship(
136        &ctx.db_context,
137        &ctx.event_hub,
138        id,
139        field,
140        ids_to_move,
141        new_index,
142    )
143    .context("moving root relationship")
144}