#![allow(unused_imports, dead_code)]
use crate::app_context::AppContext;
use anyhow::{Context, Result};
use common::direct_access::table_cell::TableCellRelationshipField;
use common::types::EntityId;
use direct_access::TableCellRelationshipDto;
use direct_access::{CreateTableCellDto, TableCellDto, UpdateTableCellDto, table_cell_controller};
pub fn create_orphan_table_cell(
ctx: &AppContext,
stack_id: Option<u64>,
dto: &CreateTableCellDto,
) -> Result<TableCellDto> {
let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
table_cell_controller::create_orphan(
&ctx.db_context,
&ctx.event_hub,
&mut undo_redo_manager,
stack_id,
dto,
)
.context("creating table_cell")
}
pub fn create_table_cell(
ctx: &AppContext,
stack_id: Option<u64>,
dto: &CreateTableCellDto,
owner_id: EntityId,
index: i32,
) -> Result<TableCellDto> {
let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
table_cell_controller::create(
&ctx.db_context,
&ctx.event_hub,
&mut undo_redo_manager,
stack_id,
dto,
owner_id,
index,
)
.context("creating table_cell")
}
pub fn create_orphan_table_cell_multi(
ctx: &AppContext,
stack_id: Option<u64>,
dtos: &[CreateTableCellDto],
) -> Result<Vec<TableCellDto>> {
let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
table_cell_controller::create_orphan_multi(
&ctx.db_context,
&ctx.event_hub,
&mut undo_redo_manager,
stack_id,
dtos,
)
.context("creating table_cell entities")
}
pub fn create_table_cell_multi(
ctx: &AppContext,
stack_id: Option<u64>,
dtos: &[CreateTableCellDto],
owner_id: EntityId,
index: i32,
) -> Result<Vec<TableCellDto>> {
let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
table_cell_controller::create_multi(
&ctx.db_context,
&ctx.event_hub,
&mut undo_redo_manager,
stack_id,
dtos,
owner_id,
index,
)
.context("creating table_cell entities")
}
pub fn get_table_cell(ctx: &AppContext, id: &EntityId) -> Result<Option<TableCellDto>> {
table_cell_controller::get(&ctx.db_context, id).context("getting table_cell")
}
pub fn get_table_cell_multi(
ctx: &AppContext,
ids: &[EntityId],
) -> Result<Vec<Option<TableCellDto>>> {
table_cell_controller::get_multi(&ctx.db_context, ids).context("getting table_cell entities")
}
pub fn get_all_table_cell(ctx: &AppContext) -> Result<Vec<TableCellDto>> {
table_cell_controller::get_all(&ctx.db_context).context("getting all table_cell entities")
}
pub fn update_table_cell(
ctx: &AppContext,
stack_id: Option<u64>,
dto: &UpdateTableCellDto,
) -> Result<TableCellDto> {
let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
table_cell_controller::update(
&ctx.db_context,
&ctx.event_hub,
&mut undo_redo_manager,
stack_id,
dto,
)
.context("updating table_cell")
}
pub fn update_table_cell_multi(
ctx: &AppContext,
stack_id: Option<u64>,
dtos: &[UpdateTableCellDto],
) -> Result<Vec<TableCellDto>> {
let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
table_cell_controller::update_multi(
&ctx.db_context,
&ctx.event_hub,
&mut undo_redo_manager,
stack_id,
dtos,
)
.context("updating table_cell entities")
}
pub fn update_table_cell_with_relationships(
ctx: &AppContext,
stack_id: Option<u64>,
dto: &TableCellDto,
) -> Result<TableCellDto> {
let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
table_cell_controller::update_with_relationships(
&ctx.db_context,
&ctx.event_hub,
&mut undo_redo_manager,
stack_id,
dto,
)
.context("updating table_cell with relationships")
}
pub fn update_table_cell_with_relationships_multi(
ctx: &AppContext,
stack_id: Option<u64>,
dtos: &[TableCellDto],
) -> Result<Vec<TableCellDto>> {
let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
table_cell_controller::update_with_relationships_multi(
&ctx.db_context,
&ctx.event_hub,
&mut undo_redo_manager,
stack_id,
dtos,
)
.context("updating table_cell entities with relationships")
}
pub fn remove_table_cell(ctx: &AppContext, stack_id: Option<u64>, id: &EntityId) -> Result<()> {
let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
table_cell_controller::remove(
&ctx.db_context,
&ctx.event_hub,
&mut undo_redo_manager,
stack_id,
id,
)
.context("removing table_cell")
}
pub fn remove_table_cell_multi(
ctx: &AppContext,
stack_id: Option<u64>,
ids: &[EntityId],
) -> Result<()> {
let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
table_cell_controller::remove_multi(
&ctx.db_context,
&ctx.event_hub,
&mut undo_redo_manager,
stack_id,
ids,
)
.context("removing table_cell entities")
}
pub fn get_table_cell_relationship(
ctx: &AppContext,
id: &EntityId,
field: &TableCellRelationshipField,
) -> Result<Vec<EntityId>> {
table_cell_controller::get_relationship(&ctx.db_context, id, field)
.context("getting table_cell relationship")
}
pub fn get_table_cell_relationship_many(
ctx: &AppContext,
ids: &[EntityId],
field: &TableCellRelationshipField,
) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>> {
table_cell_controller::get_relationship_many(&ctx.db_context, ids, field)
.context("getting table_cell relationships (many)")
}
pub fn get_table_cell_relationship_count(
ctx: &AppContext,
id: &EntityId,
field: &TableCellRelationshipField,
) -> Result<usize> {
table_cell_controller::get_relationship_count(&ctx.db_context, id, field)
.context("getting table_cell relationship count")
}
pub fn get_table_cell_relationship_in_range(
ctx: &AppContext,
id: &EntityId,
field: &TableCellRelationshipField,
offset: usize,
limit: usize,
) -> Result<Vec<EntityId>> {
table_cell_controller::get_relationship_in_range(&ctx.db_context, id, field, offset, limit)
.context("getting table_cell relationship range")
}
pub fn set_table_cell_relationship(
ctx: &AppContext,
stack_id: Option<u64>,
dto: &TableCellRelationshipDto,
) -> Result<()> {
let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
table_cell_controller::set_relationship(
&ctx.db_context,
&ctx.event_hub,
&mut undo_redo_manager,
stack_id,
dto,
)
.context("setting table_cell relationship")
}
pub fn move_table_cell_relationship(
ctx: &AppContext,
stack_id: Option<u64>,
id: &EntityId,
field: &TableCellRelationshipField,
ids_to_move: &[EntityId],
new_index: i32,
) -> Result<Vec<EntityId>> {
let mut undo_redo_manager = ctx.undo_redo_manager.lock().unwrap();
table_cell_controller::move_relationship(
&ctx.db_context,
&ctx.event_hub,
&mut undo_redo_manager,
stack_id,
id,
field,
ids_to_move,
new_index,
)
.context("moving table_cell relationship")
}