#![allow(unused_imports, dead_code)]
use crate::app_context::AppContext;
use anyhow::{Context, Result};
use common::direct_access::root::RootRelationshipField;
use common::types::EntityId;
use direct_access::RootRelationshipDto;
use direct_access::{CreateRootDto, RootDto, UpdateRootDto, root_controller};
pub fn create_orphan_root(ctx: &AppContext, dto: &CreateRootDto) -> Result<RootDto> {
root_controller::create_orphan(&ctx.db_context, &ctx.event_hub, dto).context("creating root")
}
pub fn create_orphan_root_multi(ctx: &AppContext, dtos: &[CreateRootDto]) -> Result<Vec<RootDto>> {
root_controller::create_orphan_multi(&ctx.db_context, &ctx.event_hub, dtos)
.context("creating root entities")
}
pub fn get_root(ctx: &AppContext, id: &EntityId) -> Result<Option<RootDto>> {
root_controller::get(&ctx.db_context, id).context("getting root")
}
pub fn get_root_multi(ctx: &AppContext, ids: &[EntityId]) -> Result<Vec<Option<RootDto>>> {
root_controller::get_multi(&ctx.db_context, ids).context("getting root entities")
}
pub fn get_all_root(ctx: &AppContext) -> Result<Vec<RootDto>> {
root_controller::get_all(&ctx.db_context).context("getting all root entities")
}
pub fn update_root(ctx: &AppContext, dto: &UpdateRootDto) -> Result<RootDto> {
root_controller::update(&ctx.db_context, &ctx.event_hub, dto).context("updating root")
}
pub fn update_root_multi(ctx: &AppContext, dtos: &[UpdateRootDto]) -> Result<Vec<RootDto>> {
root_controller::update_multi(&ctx.db_context, &ctx.event_hub, dtos)
.context("updating root entities")
}
pub fn update_root_with_relationships(ctx: &AppContext, dto: &RootDto) -> Result<RootDto> {
root_controller::update_with_relationships(&ctx.db_context, &ctx.event_hub, dto)
.context("updating root with relationships")
}
pub fn update_root_with_relationships_multi(
ctx: &AppContext,
dtos: &[RootDto],
) -> Result<Vec<RootDto>> {
root_controller::update_with_relationships_multi(&ctx.db_context, &ctx.event_hub, dtos)
.context("updating root entities with relationships")
}
pub fn remove_root(ctx: &AppContext, id: &EntityId) -> Result<()> {
root_controller::remove(&ctx.db_context, &ctx.event_hub, id).context("removing root")
}
pub fn remove_root_multi(ctx: &AppContext, ids: &[EntityId]) -> Result<()> {
root_controller::remove_multi(&ctx.db_context, &ctx.event_hub, ids)
.context("removing root entities")
}
pub fn get_root_relationship(
ctx: &AppContext,
id: &EntityId,
field: &RootRelationshipField,
) -> Result<Vec<EntityId>> {
root_controller::get_relationship(&ctx.db_context, id, field)
.context("getting root relationship")
}
pub fn get_root_relationship_many(
ctx: &AppContext,
ids: &[EntityId],
field: &RootRelationshipField,
) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>> {
root_controller::get_relationship_many(&ctx.db_context, ids, field)
.context("getting root relationships (many)")
}
pub fn get_root_relationship_count(
ctx: &AppContext,
id: &EntityId,
field: &RootRelationshipField,
) -> Result<usize> {
root_controller::get_relationship_count(&ctx.db_context, id, field)
.context("getting root relationship count")
}
pub fn get_root_relationship_in_range(
ctx: &AppContext,
id: &EntityId,
field: &RootRelationshipField,
offset: usize,
limit: usize,
) -> Result<Vec<EntityId>> {
root_controller::get_relationship_in_range(&ctx.db_context, id, field, offset, limit)
.context("getting root relationship range")
}
pub fn set_root_relationship(ctx: &AppContext, dto: &RootRelationshipDto) -> Result<()> {
root_controller::set_relationship(&ctx.db_context, &ctx.event_hub, dto)
.context("setting root relationship")
}
pub fn move_root_relationship(
ctx: &AppContext,
id: &EntityId,
field: &RootRelationshipField,
ids_to_move: &[EntityId],
new_index: i32,
) -> Result<Vec<EntityId>> {
root_controller::move_relationship(
&ctx.db_context,
&ctx.event_hub,
id,
field,
ids_to_move,
new_index,
)
.context("moving root relationship")
}