2026-02-16 07:12:59 -05:00
|
|
|
use super::{Addition, DocDef, Query, Records, Reply, Show, UserAction};
|
2026-02-07 22:03:00 -05:00
|
|
|
use crate::{
|
2026-02-12 10:18:53 -05:00
|
|
|
message::{
|
2026-02-14 13:04:55 -05:00
|
|
|
wrapper::{Delete, Update},
|
2026-02-12 10:18:53 -05:00
|
|
|
MessageAction,
|
|
|
|
|
},
|
2026-02-07 22:03:00 -05:00
|
|
|
mtterror::MTTError,
|
2026-02-09 19:28:22 -05:00
|
|
|
name::NameType,
|
2026-02-07 22:03:00 -05:00
|
|
|
queue::data_director::Register,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
|
pub enum MsgAction {
|
|
|
|
|
Addition(Addition),
|
|
|
|
|
Create(DocDef),
|
|
|
|
|
Error(MTTError),
|
|
|
|
|
OnAddition(Records),
|
|
|
|
|
OnDelete(Records),
|
|
|
|
|
OnQuery(Records),
|
|
|
|
|
OnUpdate(Records),
|
|
|
|
|
Query(Query),
|
|
|
|
|
Records(Records),
|
|
|
|
|
Register(Register),
|
|
|
|
|
Reply(Reply),
|
2026-02-16 07:12:59 -05:00
|
|
|
Show(Show),
|
2026-02-07 22:03:00 -05:00
|
|
|
Delete(Delete),
|
|
|
|
|
Update(Update),
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-12 10:18:53 -05:00
|
|
|
impl MessageAction for MsgAction {
|
2026-02-12 12:24:20 -05:00
|
|
|
fn doc_name(&self) -> &NameType {
|
2026-02-09 19:28:22 -05:00
|
|
|
match self {
|
2026-02-12 10:18:53 -05:00
|
|
|
Self::Addition(data) => data.doc_name(),
|
|
|
|
|
Self::Create(data) => data.doc_name(),
|
2026-02-13 12:00:39 -05:00
|
|
|
Self::Error(data) => data.doc_name(),
|
2026-02-13 15:04:16 -05:00
|
|
|
Self::OnAddition(data) => data.doc_name(),
|
|
|
|
|
Self::OnDelete(data) => data.doc_name(),
|
|
|
|
|
Self::OnQuery(data) => data.doc_name(),
|
|
|
|
|
Self::OnUpdate(data) => data.doc_name(),
|
|
|
|
|
Self::Query(data) => data.doc_name(),
|
|
|
|
|
Self::Records(data) => data.doc_name(),
|
2026-02-14 12:34:19 -05:00
|
|
|
Self::Register(data) => data.doc_name(),
|
2026-02-14 13:45:49 -05:00
|
|
|
Self::Reply(data) => data.doc_name(),
|
2026-02-16 07:12:59 -05:00
|
|
|
Self::Show(data) => data.doc_name(),
|
2026-02-12 12:24:20 -05:00
|
|
|
_ => &NameType::None,
|
2026-02-09 19:28:22 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-07 22:03:00 -05:00
|
|
|
impl From<Addition> for MsgAction {
|
|
|
|
|
fn from(value: Addition) -> Self {
|
|
|
|
|
MsgAction::Addition(value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<Delete> for MsgAction {
|
|
|
|
|
fn from(value: Delete) -> Self {
|
|
|
|
|
MsgAction::Delete(value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<DocDef> for MsgAction {
|
|
|
|
|
fn from(value: DocDef) -> Self {
|
|
|
|
|
MsgAction::Create(value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<MTTError> for MsgAction {
|
|
|
|
|
fn from(value: MTTError) -> Self {
|
|
|
|
|
MsgAction::Error(value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<Query> for MsgAction {
|
|
|
|
|
fn from(value: Query) -> Self {
|
|
|
|
|
MsgAction::Query(value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<Records> for MsgAction {
|
|
|
|
|
fn from(value: Records) -> Self {
|
|
|
|
|
MsgAction::Records(value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<Register> for MsgAction {
|
|
|
|
|
fn from(value: Register) -> Self {
|
|
|
|
|
MsgAction::Register(value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<Reply> for MsgAction {
|
|
|
|
|
fn from(value: Reply) -> Self {
|
|
|
|
|
MsgAction::Reply(value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<Update> for MsgAction {
|
|
|
|
|
fn from(value: Update) -> Self {
|
|
|
|
|
MsgAction::Update(value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<UserAction> for MsgAction {
|
|
|
|
|
fn from(value: UserAction) -> Self {
|
|
|
|
|
match value {
|
|
|
|
|
UserAction::CreateDocument(data) => Self::Create(data),
|
|
|
|
|
UserAction::Query(data) => Self::Query(data),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod msgactions {
|
|
|
|
|
use super::*;
|
2026-02-12 22:49:19 -05:00
|
|
|
use crate::{mtterror::ErrorID, name::Name};
|
2026-02-07 22:03:00 -05:00
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn turn_document_definition_into_action() {
|
|
|
|
|
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
|
|
|
|
let value = DocDef::new(name.clone());
|
|
|
|
|
let result: MsgAction = value.into();
|
|
|
|
|
match result {
|
|
|
|
|
MsgAction::Create(def) => assert_eq!(def.get_document_names(), &[name].to_vec()),
|
|
|
|
|
_ => unreachable!("Got {:?}: dhould have been create", result),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn turn_error_into_action() {
|
2026-02-12 22:49:19 -05:00
|
|
|
let doc_name = Name::english(Uuid::new_v4().to_string().as_str());
|
|
|
|
|
let expected_name: NameType = doc_name.clone().into();
|
|
|
|
|
let error = ErrorID::DocumentNameAlreadyExists;
|
|
|
|
|
let err = MTTError::new(doc_name.clone(), error.clone());
|
|
|
|
|
let result: MsgAction = err.into();
|
2026-02-07 22:03:00 -05:00
|
|
|
match result {
|
2026-02-12 22:49:19 -05:00
|
|
|
MsgAction::Error(err) => {
|
|
|
|
|
assert_eq!(err.doc_name(), &expected_name);
|
|
|
|
|
let err_id = err.error_id();
|
|
|
|
|
match err_id {
|
|
|
|
|
ErrorID::DocumentNameAlreadyExists => {}
|
|
|
|
|
_ => unreachable!("got {:?}, expected document name exists", err_id),
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-07 22:03:00 -05:00
|
|
|
_ => unreachable!("Got {:?}: dhould have been create", result),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn turn_query_into_action() {
|
2026-02-09 19:28:22 -05:00
|
|
|
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
2026-02-12 12:24:20 -05:00
|
|
|
let expected_name: NameType = name.clone().into();
|
2026-02-09 19:28:22 -05:00
|
|
|
let value = Query::new(name.clone());
|
2026-02-07 22:03:00 -05:00
|
|
|
let result: MsgAction = value.into();
|
|
|
|
|
match result {
|
2026-02-12 12:24:20 -05:00
|
|
|
MsgAction::Query(data) => assert_eq!(data.doc_name(), &expected_name),
|
2026-02-07 22:03:00 -05:00
|
|
|
_ => unreachable!("Got {:?}: dhould have been query", result),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn turn_reply_into_action() {
|
2026-02-14 13:45:49 -05:00
|
|
|
let value = Reply::new(Name::english("something"));
|
2026-02-07 22:03:00 -05:00
|
|
|
let result: MsgAction = value.into();
|
|
|
|
|
match result {
|
|
|
|
|
MsgAction::Reply(_) => {}
|
|
|
|
|
_ => unreachable!("Got {:?}: dhould have been reply", result),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|