Server API v1 #1
@ -33,15 +33,19 @@ pub fn run_migrations(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_tasks(database_url: String) -> Result<Vec<Task>, Box<dyn error::Error>> {
|
pub async fn get_tasks(database_url: String) -> Result<Vec<Task>, Box<dyn error::Error>> {
|
||||||
|
use tasks::dsl::*;
|
||||||
|
|
||||||
let conn = &mut establish_connection(&database_url)?;
|
let conn = &mut establish_connection(&database_url)?;
|
||||||
|
|
||||||
Ok(tasks::dsl::tasks.select(Task::as_select()).load(conn)?)
|
Ok(tasks.select(Task::as_select()).load(conn)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_task(database_url: String, uuid: Uuid) -> Result<Task, Box<dyn error::Error>> {
|
pub async fn get_task(database_url: String, uuid: Uuid) -> Result<Task, Box<dyn error::Error>> {
|
||||||
|
use tasks::dsl::*;
|
||||||
|
|
||||||
let conn = &mut establish_connection(&database_url)?;
|
let conn = &mut establish_connection(&database_url)?;
|
||||||
|
|
||||||
Ok(tasks::dsl::tasks
|
Ok(tasks
|
||||||
.find(uuid)
|
.find(uuid)
|
||||||
.select(Task::as_select())
|
.select(Task::as_select())
|
||||||
.first(conn)?)
|
.first(conn)?)
|
||||||
@ -70,7 +74,9 @@ pub async fn create_task(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_task(database_url: String, uuid: Uuid) -> Result<usize, Box<dyn error::Error>> {
|
pub async fn delete_task(database_url: String, uuid: Uuid) -> Result<usize, Box<dyn error::Error>> {
|
||||||
|
use tasks::dsl::*;
|
||||||
|
|
||||||
let conn = &mut establish_connection(&database_url)?;
|
let conn = &mut establish_connection(&database_url)?;
|
||||||
|
|
||||||
Ok(diesel::delete(tasks::dsl::tasks.filter(tasks::dsl::id.eq(uuid))).execute(conn)?)
|
Ok(diesel::delete(tasks.filter(id.eq(uuid))).execute(conn)?)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user