improving depot code for user and static repo examples
This commit is contained in:
12
rear/src/depot/depot_cycle.md
Normal file
12
rear/src/depot/depot_cycle.md
Normal 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
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user