style: formatting
This commit is contained in:
		| @@ -37,7 +37,7 @@ impl<T: Display> Display for ErrorVec<T> { | ||||
| impl<T> FromStr for ErrorVec<T> { | ||||
|     type Err = (); | ||||
|  | ||||
|     fn from_str(s: &str) -> Result<Self, Self::Err> { | ||||
|     fn from_str(_: &str) -> Result<Self, Self::Err> { | ||||
|         Ok(ErrorVec { errors: Vec::new() }) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -22,12 +22,12 @@ impl From<ValidationErrors> for ErrorVec<ProjectCreateError> { | ||||
|                         .map(|validation_error| validation_error.code.as_ref()) | ||||
|                         .map(|code| match code { | ||||
|                             "title_length" => ProjectCreateError::TitleLengthInvalid, | ||||
|                             _ => panic!("unexpected validation error code: {code}"), | ||||
|                             _ => panic!("Unexpected validation error code: `{code}`."), | ||||
|                         }) | ||||
|                         .collect::<Vec<ProjectCreateError>>(), | ||||
|                     _ => panic!("unexpected validation error kind"), | ||||
|                     _ => panic!("Unexpected validation error kind."), | ||||
|                 }, | ||||
|                 _ => panic!("unexpected validation field name: {field}"), | ||||
|                 _ => panic!("Unexpected validation field name: `{field}`."), | ||||
|             }) | ||||
|             .collect::<Vec<ProjectCreateError>>() | ||||
|             .into() | ||||
|   | ||||
| @@ -3,23 +3,21 @@ use crate::errors::error_vec::ErrorVec; | ||||
| use crate::errors::project_create_error::ProjectCreateError; | ||||
| use crate::models::project::{NewProject, Project}; | ||||
| use crate::server::database_connection::establish_database_connection; | ||||
| use diesel::{RunQueryDsl, SelectableHelper}; | ||||
| use diesel::{QueryDsl, RunQueryDsl, SelectableHelper}; | ||||
| use dioxus::prelude::*; | ||||
| use validator::Validate; | ||||
|  | ||||
| #[server] | ||||
| pub(crate) async fn create_project( | ||||
|     new_project: NewProject, | ||||
| ) -> Result<Project, ServerFnError<ErrorVec<ProjectCreateError>>> { | ||||
| pub(crate) async fn create_project(new_project: NewProject) | ||||
|                                    -> Result<Project, ServerFnError<ErrorVec<ProjectCreateError>>> { | ||||
|     use crate::schema::projects; | ||||
|  | ||||
|     new_project | ||||
|         .validate() | ||||
|     new_project.validate() | ||||
|         .map_err::<ErrorVec<ProjectCreateError>, _>(|errors| errors.into())?; | ||||
|  | ||||
|     let mut connection = establish_database_connection() | ||||
|         .map_err::<ErrorVec<ProjectCreateError>, _>( | ||||
|             |_| vec![ProjectCreateError::Error(Error::ServerInternal), ].into() | ||||
|             |_| vec![ProjectCreateError::Error(Error::ServerInternal)].into() | ||||
|         )?; | ||||
|  | ||||
|     let new_project = diesel::insert_into(projects::table) | ||||
| @@ -27,8 +25,22 @@ pub(crate) async fn create_project( | ||||
|         .returning(Project::as_returning()) | ||||
|         .get_result(&mut connection) | ||||
|         .map_err::<ErrorVec<ProjectCreateError>, _>( | ||||
|             |_| vec![ProjectCreateError::Error(Error::ServerInternal), ].into() | ||||
|             |_| vec![ProjectCreateError::Error(Error::ServerInternal)].into() | ||||
|         )?; | ||||
|  | ||||
|     Ok(new_project) | ||||
| } | ||||
|  | ||||
| #[server] | ||||
| pub(crate) async fn get_projects() | ||||
|     -> Result<Vec<Project>, ServerFnError> { | ||||
|     use crate::schema::projects::dsl::*; | ||||
|  | ||||
|     let mut connection = establish_database_connection()?; | ||||
|  | ||||
|     let results = projects | ||||
|         .select(Project::as_select()) | ||||
|         .load::<Project>(&mut connection)?; | ||||
|  | ||||
|     Ok(results) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user