Added ability to add page, but hangs in main.

This commit is contained in:
2025-05-01 13:46:46 -04:00
parent 1bfbfc5e44
commit 4fbbd30c4b
6 changed files with 131 additions and 24 deletions

View File

@ -1,10 +1,11 @@
use crate::ErrorType;
use crate::{ActionType, ErrorType};
use chrono::prelude::*;
use std::fmt;
use uuid::Uuid;
#[derive(Clone, Debug)]
pub enum Field {
Action(ActionType),
DateTime(DateTime<Utc>),
ErrorType(ErrorType),
Static(String),
@ -12,6 +13,13 @@ pub enum Field {
}
impl Field {
pub fn to_action(&self) -> Result<ActionType, String> {
match self {
Field::Action(data) => Ok(data.clone()),
_ => Err("not an action".to_string()),
}
}
pub fn to_uuid(&self) -> Result<Uuid, String> {
match self {
Field::Uuid(data) => Ok(data.clone()),
@ -54,6 +62,12 @@ impl From<&str> for Field {
}
}
impl From<ActionType> for Field {
fn from(value: ActionType) -> Self {
Field::Action(value)
}
}
impl From<Uuid> for Field {
fn from(value: Uuid) -> Self {
Field::Uuid(value)
@ -219,8 +233,7 @@ mod fields {
let field: Field = err.into();
match field {
Field::ErrorType(data) => match data {
ErrorType::DocumentNotFound => {}
//_ => unreachable!("got {:?}: should have been Document not found", data),
ErrorType::DocumentNotFound => {} //_ => unreachable!("got {:?}: should have been Document not found", data),
},
_ => unreachable!("should have been an error type"),
}
@ -238,8 +251,38 @@ mod fields {
let field: Field = err.into();
let result = field.to_error_type().unwrap();
match result {
ErrorType::DocumentNotFound => {}
//_ => unreachable!("got {:?}: should have been document not found", result),
ErrorType::DocumentNotFound => {} //_ => unreachable!("got {:?}: should have been document not found", result),
}
}
#[test]
fn from_action_to_field() {
let actions = [ActionType::Add, ActionType::Get, ActionType::Update];
for action in actions.into_iter() {
let result: Field = action.clone().into();
match result {
Field::Action(data) => assert_eq!(format!("{:?}", data), format!("{:?}", action)),
_ => unreachable!("should have been an action"),
}
}
}
#[test]
fn from_field_to_action() {
let actions = [ActionType::Add, ActionType::Get, ActionType::Update];
for action in actions.into_iter() {
let field: Field = action.clone().into();
let result = field.to_action().unwrap();
assert_eq!(format!("{:?}", result), format!("{:?}", action));
}
}
#[test]
fn from_uuid_to_action() {
let field: Field = Uuid::new_v4().into();
match field.to_action() {
Ok(_) => unreachable!("should have returned an error"),
Err(_) => {},
}
}
}