Added request information.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s

This commit is contained in:
Jeff Baskin 2026-02-07 23:13:24 -05:00
parent 5d8624656a
commit 445cbb57f1
2 changed files with 90 additions and 0 deletions

View File

@ -1,6 +1,7 @@
mod action_type; mod action_type;
mod message; mod message;
mod query; mod query;
mod request_data;
mod user; mod user;
pub use action_type::Action; pub use action_type::Action;
@ -8,3 +9,4 @@ pub use crate::document::{definition::DocDef, field::FieldType};
pub use message::MsgAction; pub use message::MsgAction;
pub use query::Query; pub use query::Query;
pub use user::UserAction; pub use user::UserAction;
use request_data::RequestData;

View File

@ -0,0 +1,88 @@
use crate::{
document::field::Field,
message::wrapper::CalcValue,
name::NameType,
};
use std::collections::HashMap;
#[derive(Clone, Debug)]
pub struct RequestData {
data: HashMap<NameType, CalcValue>,
}
impl RequestData {
fn new() -> Self {
Self {
data: HashMap::new(),
}
}
pub fn add_field<NT, CV>(&mut self, name: NT, field: CV)
where
CV: Into<CalcValue>,
NT: Into<NameType>,
{
self.data.insert(name.into(), field.into());
}
fn get_field<NT>(&self, name: NT) -> &CalcValue
where
NT: Into<NameType>,
{
match self.data.get(&name.into()) {
Some(data) => data,
None => &CalcValue::None,
}
}
fn get_all(&self) -> Vec<(NameType, Field)> {
let mut output = Vec::new();
for (key, value) in self.data.iter() {
output.push((key.clone(), value.get(&Field::None)));
}
output
}
pub fn iter(&self) -> impl Iterator<Item = (&NameType, &CalcValue)> {
self.data.iter()
}
}
#[cfg(test)]
mod request_datum {
use super::*;
use crate::name::Name;
use uuid::Uuid;
#[test]
fn can_add_static_string() {
let mut add = RequestData::new();
let name = Name::english(Uuid::new_v4().to_string().as_str());
let data = Uuid::new_v4().to_string();
add.add_field(name.clone(), data.clone());
let result = add.get_field(&name);
match result {
CalcValue::Value(holder) => match holder {
Field::StaticString(result) => assert_eq!(result, &data),
_ => unreachable!("got {:?}: should have received static string", holder),
},
_ => unreachable!("got {:?}, should have been value", result),
}
}
#[test]
fn can_add_uuid() {
let mut add = RequestData::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 result = add.get_field(&name);
match result {
CalcValue::Value(holder) => match holder {
Field::Uuid(result) => assert_eq!(result, &data),
_ => unreachable!("got {:?}: should have received static string", holder),
},
_ => unreachable!("got {:?}, should have been value", result),
}
}
}