Server API v1 #1
@ -14,7 +14,7 @@ use uuid::Uuid;
|
||||
use models::Task;
|
||||
|
||||
use crate::db::models::NewTask;
|
||||
use crate::schema::tasks;
|
||||
use crate::schema;
|
||||
|
||||
pub mod models;
|
||||
|
||||
@ -33,7 +33,7 @@ pub fn run_migrations(
|
||||
}
|
||||
|
||||
pub async fn get_tasks(database_url: String) -> Result<Vec<Task>, Box<dyn error::Error>> {
|
||||
use tasks::dsl::*;
|
||||
use schema::tasks::dsl::*;
|
||||
|
||||
let conn = &mut establish_connection(&database_url)?;
|
||||
|
||||
@ -41,14 +41,11 @@ pub async fn get_tasks(database_url: String) -> Result<Vec<Task>, Box<dyn error:
|
||||
}
|
||||
|
||||
pub async fn get_task(database_url: String, uuid: Uuid) -> Result<Task, Box<dyn error::Error>> {
|
||||
use tasks::dsl::*;
|
||||
use schema::tasks::dsl::*;
|
||||
|
||||
let conn = &mut establish_connection(&database_url)?;
|
||||
|
||||
Ok(tasks
|
||||
.find(uuid)
|
||||
.select(Task::as_select())
|
||||
.first(conn)?)
|
||||
Ok(tasks.find(uuid).select(Task::as_select()).first(conn)?)
|
||||
}
|
||||
|
||||
pub async fn create_task(
|
||||
@ -67,14 +64,14 @@ pub async fn create_task(
|
||||
due_date,
|
||||
};
|
||||
|
||||
Ok(diesel::insert_into(tasks::table)
|
||||
Ok(diesel::insert_into(schema::tasks::table)
|
||||
.values(&new_task)
|
||||
.returning(Task::as_returning())
|
||||
.get_result(conn)?)
|
||||
}
|
||||
|
||||
pub async fn delete_task(database_url: String, uuid: Uuid) -> Result<usize, Box<dyn error::Error>> {
|
||||
use tasks::dsl::*;
|
||||
use schema::tasks::dsl::*;
|
||||
|
||||
let conn = &mut establish_connection(&database_url)?;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user