text-document-io 1.7.0

Import/export for text-document: plain text, Markdown, HTML, LaTeX, DOCX
Documentation
// Generated by Qleany v1.4.8 from feature_use_case_uow.tera

use crate::use_cases::export_latex_uc::{
    ExportLatexUnitOfWorkFactoryTrait, ExportLatexUnitOfWorkTrait,
};
use anyhow::{Ok, Result};
use common::database::QueryUnitOfWork;
use common::database::{db_context::DbContext, transactions::Transaction};
#[allow(unused_imports)]
use common::entities::{Block, Document, Frame, List, Root, Table, TableCell};
#[allow(unused_imports)]
use common::types;
#[allow(unused_imports)]
use common::types::EntityId;
use std::cell::RefCell;

// Unit of work for ExportLatex

pub struct ExportLatexUnitOfWork {
    context: DbContext,
    transaction: RefCell<Option<Transaction>>,
}

impl ExportLatexUnitOfWork {
    pub fn new(db_context: &DbContext) -> Self {
        ExportLatexUnitOfWork {
            context: db_context.clone(),
            transaction: RefCell::new(None),
        }
    }
}

impl QueryUnitOfWork for ExportLatexUnitOfWork {
    fn begin_transaction(&self) -> Result<()> {
        self.transaction
            .replace(Some(Transaction::begin_read_transaction(&self.context)?));
        Ok(())
    }

    fn end_transaction(&self) -> Result<()> {
        self.transaction.take().unwrap().end_read_transaction()?;
        Ok(())
    }

    fn store(&self) -> std::sync::Arc<common::database::Store> {
        self.context.get_store().clone()
    }
}

#[macros::uow_action(entity = "Root", action = "GetRO")]
#[macros::uow_action(entity = "Root", action = "GetRelationshipRO")]
#[macros::uow_action(entity = "Document", action = "GetRO")]
#[macros::uow_action(entity = "Document", action = "GetRelationshipRO")]
#[macros::uow_action(entity = "Frame", action = "GetRO")]
#[macros::uow_action(entity = "Frame", action = "GetRelationshipRO")]
#[macros::uow_action(entity = "Block", action = "GetMultiRO")]
#[macros::uow_action(entity = "Block", action = "GetRelationshipRO")]
#[macros::uow_action(entity = "List", action = "GetRO")]
#[macros::uow_action(entity = "Table", action = "GetRO")]
#[macros::uow_action(entity = "Table", action = "GetRelationshipRO")]
#[macros::uow_action(entity = "TableCell", action = "GetMultiRO")]
impl ExportLatexUnitOfWorkTrait for ExportLatexUnitOfWork {}

pub struct ExportLatexUnitOfWorkFactory {
    context: DbContext,
}

impl ExportLatexUnitOfWorkFactory {
    pub fn new(db_context: &DbContext) -> Self {
        ExportLatexUnitOfWorkFactory {
            context: db_context.clone(),
        }
    }
}

impl ExportLatexUnitOfWorkFactoryTrait for ExportLatexUnitOfWorkFactory {
    fn create(&self) -> Box<dyn ExportLatexUnitOfWorkTrait> {
        Box::new(ExportLatexUnitOfWork::new(&self.context))
    }
}