diff --git a/README.md b/README.md index c4a255c..3db58d8 100644 --- a/README.md +++ b/README.md @@ -69,3 +69,17 @@ Install a postgres: ![Mugshot of Admin](./docs/mugshot.png) + +### Project Structure + +#### Root Folders + + - docker: all about docker, atm. database docker image for development. + - docs: place for all future documentation, including this. + - entity: crate containing database models + - migration: crate containing database migrations + - rear: crate containing the main library for rear + - src: crate containing a runnable project implementing rear as a demo project + - static: static files used by rear + - strinto: experimental crate for an idea. + - templates: all templates for rear-admiral. \ No newline at end of file diff --git a/rear/src/admin/domain.rs b/rear/src/admin/domain.rs index f29d2f3..53d5124 100644 --- a/rear/src/admin/domain.rs +++ b/rear/src/admin/domain.rs @@ -326,16 +326,6 @@ pub mod repository { } } - impl From for Box { - fn from(s: String) -> Box { - if let Ok(i) = s.parse::() { - Box::new(i) - } else { - Box::new(s) - } - } - } - #[async_trait] pub trait AdminRepository: Send + Sync { type Key: PrimaryKeyType; diff --git a/src/admin_examples/file_repository.rs b/src/admin_examples/file_repository.rs index 5ee8d2b..206dce9 100644 --- a/src/admin_examples/file_repository.rs +++ b/src/admin_examples/file_repository.rs @@ -10,7 +10,6 @@ struct FileRepository { impl FileRepository { pub fn new(from_path: &str) -> Self { - let proper_path = file_operations::get_proper_path(from_path); FileRepository { directory_path: proper_path, @@ -20,6 +19,12 @@ impl FileRepository { #[async_trait] impl AdminRepository for FileRepository { + type Key = String; + + fn key_from_string(&self, s: String) -> Option { + Some(s) + } + async fn info(&self, _: &RepositoryContext) -> RepositoryInfo { RepoInfo { name: "File Repository", @@ -41,13 +46,16 @@ impl AdminRepository for FileRepository { // GET on item collection. async fn list(&self, model: &RepositoryContext) -> RepositoryList { if let Ok(file_data) = file_operations::directory_info(&self.directory_path) { - let items: Vec = file_data.into_iter().map(|fields| { - RepositoryItem { - fields, - detail_url: None, // TODO: change the return type of directory_info into a struct, so we can access key. - change_url: None, - } - }).collect(); + let items: Vec = file_data + .into_iter() + .map(|fields| { + RepositoryItem { + fields, + detail_url: None, // TODO: change the return type of directory_info into a struct, so we can access key. + change_url: None, + } + }) + .collect(); return RepositoryList::List { values: items }; } RepositoryList::Empty @@ -63,7 +71,7 @@ impl AdminRepository for FileRepository { } // GET single item. - async fn get(&self, model: &RepositoryContext, id: LookupKey) -> Option { + async fn get(&self, model: &RepositoryContext, id: &Self::Key) -> Option { None } @@ -71,7 +79,7 @@ impl AdminRepository for FileRepository { async fn update( &mut self, model: &RepositoryContext, - id: LookupKey, + id: &Self::Key, data: Value, ) -> Option { None @@ -81,14 +89,14 @@ impl AdminRepository for FileRepository { async fn replace( &mut self, model: &RepositoryContext, - id: LookupKey, + id: &Self::Key, data: Value, ) -> Option { None } // DELETE single item. - async fn delete(&mut self, _: &RepositoryContext, id: LookupKey) -> Option { + async fn delete(&mut self, _: &RepositoryContext, id: &Self::Key) -> Option { None } } @@ -108,13 +116,13 @@ pub fn register(registry: &mut AdminRegistry, path: &str) { } mod file_operations { + use chrono::{DateTime, TimeZone, Utc}; use serde_json::{json, Value}; + use std::env; use std::fs; use std::path::Path; - use std::env; use std::path::PathBuf; use std::time::SystemTime; - use chrono::{DateTime, Utc, TimeZone}; fn system_time_to_iso_string(system_time: SystemTime) -> String { let datetime: DateTime = system_time.into(); @@ -157,7 +165,9 @@ mod file_operations { get_metadata_as_json(path) } - pub fn directory_info(directory_path: &PathBuf) -> Result, Box> { + pub fn directory_info( + directory_path: &PathBuf, + ) -> Result, Box> { let entries = fs::read_dir(directory_path)?; let mut results = Vec::new(); @@ -181,6 +191,5 @@ mod file_operations { let template_path = PathBuf::from(manifest_dir).join(path); return template_path; } - } }