Moved addition into action.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s
This commit is contained in:
94
src/action/addition.rs
Normal file
94
src/action/addition.rs
Normal file
@@ -0,0 +1,94 @@
|
||||
use super::{CalcValue, Field, RequestData};
|
||||
use crate::name::NameType;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Addition {
|
||||
data: RequestData,
|
||||
}
|
||||
|
||||
impl Addition {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
data: RequestData::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn add_field<NT, CV>(&mut self, name: NT, field: CV)
|
||||
where
|
||||
CV: Into<CalcValue>,
|
||||
NT: Into<NameType>,
|
||||
{
|
||||
self.data.add_field(name, field);
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = (&NameType, &CalcValue)> {
|
||||
self.data.iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod additions {
|
||||
use super::*;
|
||||
use crate::name::Name;
|
||||
|
||||
#[test]
|
||||
fn can_add_static_string() {
|
||||
let mut add = Addition::new();
|
||||
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
let ntype: NameType = name.clone().into();
|
||||
let data = Uuid::new_v4().to_string();
|
||||
add.add_field(name.clone(), data.clone());
|
||||
assert_eq!(add.iter().count(), 1);
|
||||
for (field_name, value) in add.iter() {
|
||||
assert_eq!(field_name, &ntype);
|
||||
match value {
|
||||
CalcValue::Value(result) => match result {
|
||||
Field::StaticString(output) => assert_eq!(output, &data),
|
||||
_ => unreachable!("got {:?}, should have been a string", result),
|
||||
},
|
||||
_ => unreachable!("got {:?}: should have received value", value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_add_uuid() {
|
||||
let mut add = Addition::new();
|
||||
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
let ntype: NameType = name.clone().into();
|
||||
let data = Uuid::new_v4();
|
||||
add.add_field(name.clone(), data.clone());
|
||||
assert_eq!(add.iter().count(), 1);
|
||||
for (field_name, value) in add.iter() {
|
||||
assert_eq!(field_name, &ntype);
|
||||
match value {
|
||||
CalcValue::Value(result) => match result {
|
||||
Field::Uuid(output) => assert_eq!(output, &data),
|
||||
_ => unreachable!("got {:?}, should have been a string", result),
|
||||
},
|
||||
_ => unreachable!("got {:?}: should have received value", value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#[test]
|
||||
fn can_get_document() {
|
||||
let mut add = Addition::new();
|
||||
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
let data = Uuid::new_v4();
|
||||
add.add_field(name.clone(), data.clone());
|
||||
let doc = add.get_document();
|
||||
let output = doc.get_field(&name);
|
||||
match output {
|
||||
CalcValue::Value(holder) => match holder {
|
||||
Field::Uuid(result) => assert_eq!(result, &data),
|
||||
_ => unreachable!("should have received uuid"),
|
||||
},
|
||||
_ => unreachable!("got {:?}: should have received value", output),
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::{DocDef, Query, UserAction};
|
||||
use super::{Addition, DocDef, Query, UserAction};
|
||||
use crate::{
|
||||
message::wrapper::{Addition, Delete, Records, Reply, Update},
|
||||
message::wrapper::{Delete, Records, Reply, Update},
|
||||
mtterror::MTTError,
|
||||
name::NameType,
|
||||
queue::data_director::Register,
|
||||
@@ -27,6 +27,7 @@ pub enum MsgAction {
|
||||
impl MsgAction {
|
||||
fn doc_name(&self) -> NameType {
|
||||
match self {
|
||||
Self::Addition(data) => NameType::None,
|
||||
Self::Query(data) => data.doc_name(),
|
||||
_ => NameType::None,
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ pub struct RequestData {
|
||||
}
|
||||
|
||||
impl RequestData {
|
||||
fn new() -> Self {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
data: HashMap::new(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user