text_document_frontend/commands/
root_commands.rs1#![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
13pub 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}
17pub 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}
22pub fn get_root(ctx: &AppContext, id: &EntityId) -> Result<Option<RootDto>> {
24 root_controller::get(&ctx.db_context, id).context("getting root")
25}
26
27pub 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
32pub fn get_all_root(ctx: &AppContext) -> Result<Vec<RootDto>> {
37 root_controller::get_all(&ctx.db_context).context("getting all root entities")
38}
39
40pub 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
45pub 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
51pub 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
57pub 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
67pub fn remove_root(ctx: &AppContext, id: &EntityId) -> Result<()> {
69 root_controller::remove(&ctx.db_context, &ctx.event_hub, id).context("removing root")
70}
71
72pub 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
78pub 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
88pub 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
98pub 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
108pub 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
120pub 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
126pub 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}