feat: ability to create a task #14
@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
ServerInternal,
|
ServerInternal,
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use serde_with::serde_derive::Serialize;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub struct ErrorVec<T> {
|
pub struct ErrorVec<T> {
|
||||||
errors: Vec<T>,
|
errors: Vec<T>,
|
||||||
}
|
}
|
||||||
|
@ -33,14 +33,20 @@ pub(crate) async fn create_project(new_project: NewProject)
|
|||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn get_projects()
|
pub(crate) async fn get_projects()
|
||||||
-> Result<Vec<Project>, ServerFnError> {
|
-> Result<Vec<Project>, ServerFnError<ErrorVec<Error>>> {
|
||||||
use crate::schema::projects::dsl::*;
|
use crate::schema::projects::dsl::*;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()?;
|
let mut connection = establish_database_connection()
|
||||||
|
.map_err::<ErrorVec<Error>, _>(
|
||||||
|
|_| vec![Error::ServerInternal].into()
|
||||||
|
)?;
|
||||||
|
|
||||||
let results = projects
|
let results = projects
|
||||||
.select(Project::as_select())
|
.select(Project::as_select())
|
||||||
.load::<Project>(&mut connection)?;
|
.load::<Project>(&mut connection)
|
||||||
|
.map_err::<ErrorVec<Error>, _>(
|
||||||
|
|_| vec![Error::ServerInternal].into()
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(results)
|
Ok(results)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user