Updated reply to include document name.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 0s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 0s
This commit is contained in:
parent
1f82c07565
commit
903158b72a
@ -40,6 +40,7 @@ impl MessageAction for MsgAction {
|
|||||||
Self::Query(data) => data.doc_name(),
|
Self::Query(data) => data.doc_name(),
|
||||||
Self::Records(data) => data.doc_name(),
|
Self::Records(data) => data.doc_name(),
|
||||||
Self::Register(data) => data.doc_name(),
|
Self::Register(data) => data.doc_name(),
|
||||||
|
Self::Reply(data) => data.doc_name(),
|
||||||
_ => &NameType::None,
|
_ => &NameType::None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,7 +160,7 @@ mod msgactions {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn turn_reply_into_action() {
|
fn turn_reply_into_action() {
|
||||||
let value = Reply::new();
|
let value = Reply::new(Name::english("something"));
|
||||||
let result: MsgAction = value.into();
|
let result: MsgAction = value.into();
|
||||||
match result {
|
match result {
|
||||||
MsgAction::Reply(_) => {}
|
MsgAction::Reply(_) => {}
|
||||||
|
|||||||
@ -1,13 +1,21 @@
|
|||||||
use super::{CalcValue, RequestData};
|
use super::{CalcValue, RequestData};
|
||||||
|
use crate::{message::MessageAction, name::NameType};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Reply {
|
pub struct Reply {
|
||||||
|
doc_name: NameType,
|
||||||
data: Vec<RequestData>,
|
data: Vec<RequestData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Reply {
|
impl Reply {
|
||||||
pub fn new() -> Self {
|
pub fn new<NT>(name: NT) -> Self
|
||||||
Self { data: Vec::new() }
|
where
|
||||||
|
NT: Into<NameType>,
|
||||||
|
{
|
||||||
|
Self {
|
||||||
|
doc_name: name.into(),
|
||||||
|
data: Vec::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add(&mut self, doc: RequestData) {
|
fn add(&mut self, doc: RequestData) {
|
||||||
@ -23,20 +31,35 @@ impl Reply {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl MessageAction for Reply {
|
||||||
|
fn doc_name(&self) -> &NameType {
|
||||||
|
&self.doc_name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod replies {
|
mod replies {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{action::Field, name::Name};
|
use crate::{action::Field, name::Name};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn does_default_reply_return_document() {
|
||||||
|
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||||
|
let expected: NameType = name.clone().into();
|
||||||
|
let reply = Reply::new(name.clone());
|
||||||
|
assert_eq!(reply.doc_name(), &expected);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_new_empty() {
|
fn is_new_empty() {
|
||||||
let reply = Reply::new();
|
let reply = Reply::new(Name::english("something"));
|
||||||
assert_eq!(reply.len(), 0, "should have no records");
|
assert_eq!(reply.len(), 0, "should have no records");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_add_documents() {
|
fn can_add_documents() {
|
||||||
let mut reply = Reply::new();
|
let mut reply = Reply::new(Name::english("something"));
|
||||||
let doc = RequestData::new();
|
let doc = RequestData::new();
|
||||||
reply.add(doc.clone());
|
reply.add(doc.clone());
|
||||||
assert_eq!(reply.len(), 1);
|
assert_eq!(reply.len(), 1);
|
||||||
@ -51,7 +74,7 @@ mod replies {
|
|||||||
doc1.add_field(fieldname.clone(), "one");
|
doc1.add_field(fieldname.clone(), "one");
|
||||||
let mut doc2 = RequestData::new();
|
let mut doc2 = RequestData::new();
|
||||||
doc2.add_field(fieldname.clone(), "two");
|
doc2.add_field(fieldname.clone(), "two");
|
||||||
let mut reply = Reply::new();
|
let mut reply = Reply::new(Name::english("something"));
|
||||||
reply.add(doc1);
|
reply.add(doc1);
|
||||||
reply.add(doc2);
|
reply.add(doc2);
|
||||||
let mut reply_iter = reply.iter();
|
let mut reply_iter = reply.iter();
|
||||||
|
|||||||
@ -537,11 +537,17 @@ impl DocumentFile {
|
|||||||
};
|
};
|
||||||
route_action.insert(route_id.clone(), path_action.doc_function());
|
route_action.insert(route_id.clone(), path_action.doc_function());
|
||||||
}
|
}
|
||||||
let mut doc = DocumentFile::new(queue.clone(), rx, docdef, route_action, name_id.clone());
|
let mut doc = DocumentFile::new(
|
||||||
|
queue.clone(),
|
||||||
|
rx,
|
||||||
|
docdef.clone(),
|
||||||
|
route_action,
|
||||||
|
name_id.clone(),
|
||||||
|
);
|
||||||
spawn(move || {
|
spawn(move || {
|
||||||
doc.listen();
|
doc.listen();
|
||||||
});
|
});
|
||||||
let reply = msg.response(Reply::new());
|
let reply = msg.response(Reply::new(names[0].clone()));
|
||||||
queue.send(reply.clone());
|
queue.send(reply.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,7 +561,9 @@ impl DocumentFile {
|
|||||||
DocFuncType::Add => self.add_document(&msg),
|
DocFuncType::Add => self.add_document(&msg),
|
||||||
DocFuncType::Delete => self.delete(&msg),
|
DocFuncType::Delete => self.delete(&msg),
|
||||||
DocFuncType::Query => self.query(&msg),
|
DocFuncType::Query => self.query(&msg),
|
||||||
DocFuncType::Show => self.queue.send(msg.response(Reply::new())),
|
DocFuncType::Show => self.queue.send(
|
||||||
|
msg.response(Reply::new(self.docdef.get_document_names()[0].clone())),
|
||||||
|
),
|
||||||
DocFuncType::Update => self.update(&msg),
|
DocFuncType::Update => self.update(&msg),
|
||||||
DocFuncType::ExistingQuery(action) => self.existing_query(&msg, action),
|
DocFuncType::ExistingQuery(action) => self.existing_query(&msg, action),
|
||||||
DocFuncType::Trigger(action) => self.trigger(&msg, action),
|
DocFuncType::Trigger(action) => self.trigger(&msg, action),
|
||||||
|
|||||||
@ -176,7 +176,7 @@ mod messages {
|
|||||||
fn can_make_reply_message() {
|
fn can_make_reply_message() {
|
||||||
let name = Name::english("testing");
|
let name = Name::english("testing");
|
||||||
let msg = Message::new(name.clone(), Query::new(name.clone()));
|
let msg = Message::new(name.clone(), Query::new(name.clone()));
|
||||||
let responce = Reply::new();
|
let responce = Reply::new(Name::english("something"));
|
||||||
let reply = msg.response(responce);
|
let reply = msg.response(responce);
|
||||||
assert_eq!(reply.get_message_id(), msg.get_message_id());
|
assert_eq!(reply.get_message_id(), msg.get_message_id());
|
||||||
match &reply.document_id {
|
match &reply.document_id {
|
||||||
@ -215,7 +215,7 @@ mod messages {
|
|||||||
let msg = Message::new(doc_id.clone(), Query::new(doc_id.clone()));
|
let msg = Message::new(doc_id.clone(), Query::new(doc_id.clone()));
|
||||||
let data = Uuid::new_v4().to_string();
|
let data = Uuid::new_v4().to_string();
|
||||||
let result1 = msg.response(MTTError::new(NameType::None, ErrorID::DocumentNotFound));
|
let result1 = msg.response(MTTError::new(NameType::None, ErrorID::DocumentNotFound));
|
||||||
let result2 = msg.response(Reply::new());
|
let result2 = msg.response(Reply::new(NameType::None));
|
||||||
assert_eq!(result1.get_message_id(), msg.get_message_id());
|
assert_eq!(result1.get_message_id(), msg.get_message_id());
|
||||||
assert_eq!(result2.get_message_id(), msg.get_message_id());
|
assert_eq!(result2.get_message_id(), msg.get_message_id());
|
||||||
assert_eq!(result1.document_id, msg.document_id);
|
assert_eq!(result1.document_id, msg.document_id);
|
||||||
@ -266,88 +266,6 @@ impl Operation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Reply {
|
|
||||||
data: Vec<Document>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
impl Reply {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self { data: Vec::new() }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add(&mut self, doc: Document) {
|
|
||||||
self.data.push(doc);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn len(&self) -> usize {
|
|
||||||
self.data.len()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn iter(&self) -> impl Iterator<Item = &Document> {
|
|
||||||
self.data.iter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod replies {
|
|
||||||
use super::*;
|
|
||||||
use crate::name::Name;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn is_new_empty() {
|
|
||||||
let reply = Reply::new();
|
|
||||||
assert_eq!(reply.len(), 0, "should have no records");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn can_add_documents() {
|
|
||||||
let mut reply = Reply::new();
|
|
||||||
let doc = Document::new();
|
|
||||||
reply.add(doc.clone());
|
|
||||||
assert_eq!(reply.len(), 1);
|
|
||||||
reply.add(doc.clone());
|
|
||||||
assert_eq!(reply.len(), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn can_retrieve_documents() {
|
|
||||||
let fieldname = Name::english("field");
|
|
||||||
let mut doc1 = Document::new();
|
|
||||||
doc1.add_field(fieldname.clone(), "one");
|
|
||||||
let mut doc2 = Document::new();
|
|
||||||
doc2.add_field(fieldname.clone(), "two");
|
|
||||||
let mut reply = Reply::new();
|
|
||||||
reply.add(doc1);
|
|
||||||
reply.add(doc2);
|
|
||||||
let mut reply_iter = reply.iter();
|
|
||||||
let result1 = reply_iter.next().unwrap();
|
|
||||||
match result1.get_field(&fieldname) {
|
|
||||||
CalcValue::Value(data) => match data {
|
|
||||||
Field::StaticString(output) => assert_eq!(output, "one"),
|
|
||||||
_ => unreachable!("got {:?}: should have been static string", result1),
|
|
||||||
},
|
|
||||||
_ => unreachable!("got {:?}, should have been value", result1),
|
|
||||||
}
|
|
||||||
let result2 = reply_iter.next().unwrap();
|
|
||||||
match result2.get_field(&fieldname) {
|
|
||||||
CalcValue::Value(data) => match data {
|
|
||||||
Field::StaticString(output) => assert_eq!(output, "two"),
|
|
||||||
_ => unreachable!("got {:?}: should have been static string", result2),
|
|
||||||
},
|
|
||||||
_ => unreachable!("got {:?}, should have been value", result2),
|
|
||||||
}
|
|
||||||
match reply_iter.next() {
|
|
||||||
None => {}
|
|
||||||
Some(_) => unreachable!("should be out of data"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Document {
|
pub struct Document {
|
||||||
data: HashMap<NameType, CalcValue>,
|
data: HashMap<NameType, CalcValue>,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user