improving depot code for user and static repo examples

This commit is contained in:
2024-07-26 12:56:23 +02:00
parent 843e432ec4
commit 15e60e6325
10 changed files with 78 additions and 40 deletions

View File

@@ -0,0 +1,12 @@
UPDATE:
- The Item is edited successfully: Success Message
- The Item could not be saved, it needs adjustment: Form Errors, Warning Message?
- The Item could not be saved, there was an Error of some sort: Error Message
Widget -builds-> Field
Validation: https://github.com/tokio-rs/axum/blob/main/examples/validator/src/main.rs
AvoRED PRoject seems similar: https://github.com/avored/avored-rust-cms

View File

@@ -99,10 +99,21 @@ impl Into<Option<RepositoryItem>> for RepositoryResponse {
#[derive(Error, Debug)]
pub enum RepositoryError {
// used internally.
#[error("key not found in downcast?")]
WrapperDowncastError,
// to be used by repositories:
#[error("repository item not found")]
ItemNotFound,
#[error("database error: {0}")]
DatabaseError(#[source] Box<dyn std::error::Error + Send + Sync>),
#[error("external error: {0}")]
ExternalError(#[source] Box<dyn std::error::Error + Send + Sync>),
// to be removed or refactored:
#[error("an unknown occurred: {0}")]
UnknownError(String),
#[error("key not found in downcast?")]
KeyNotFound,
}
pub type RepositoryResult = Result<RepositoryResponse, RepositoryError>;
@@ -332,7 +343,7 @@ impl<T: DepotRepository> DynDepotRepository for DepotRepositoryWrapper<T> {
if let Some(key) = id.as_any().downcast_ref::<T::Key>() {
self.inner.get(context, key).await
} else {
Err(RepositoryError::KeyNotFound)
Err(RepositoryError::WrapperDowncastError)
}
}
@@ -349,7 +360,7 @@ impl<T: DepotRepository> DynDepotRepository for DepotRepositoryWrapper<T> {
if let Some(key) = id.as_any().downcast_ref::<T::Key>() {
self.inner.update(context, key, data).await
} else {
Err(RepositoryError::KeyNotFound)
Err(RepositoryError::WrapperDowncastError)
}
}
@@ -362,7 +373,7 @@ impl<T: DepotRepository> DynDepotRepository for DepotRepositoryWrapper<T> {
if let Some(key) = id.as_any().downcast_ref::<T::Key>() {
self.inner.replace(context, key, data).await
} else {
Err(RepositoryError::KeyNotFound)
Err(RepositoryError::WrapperDowncastError)
}
}

View File

@@ -36,15 +36,15 @@ impl Widget {
}
pub fn default() -> Self {
Self::widget("/admin/widgets/input_text.jinja")
Self::widget("/depot/widgets/input_text.jinja")
}
pub fn textarea() -> Self {
Self::widget("/admin/widgets/input_textarea.jinja")
Self::widget("/depot/widgets/input_textarea.jinja")
}
pub fn checkbox() -> Self {
Self::widget("/admin/widgets/checkbox_toggle.jinja")
Self::widget("/depot/widgets/checkbox_toggle.jinja")
}
pub fn required(mut self) -> Self {