Allow creating and updating tasks on the backend. (#2)
Create hurl tests along with the necessary api code to resolve them. Reviewed-on: #2 Co-authored-by: Drew Galbraith <drew@tiramisu.one> Co-committed-by: Drew Galbraith <drew@tiramisu.one>
This commit is contained in:
parent
82d524a62f
commit
d32f6be813
10 changed files with 306 additions and 28 deletions
|
|
@ -4,6 +4,8 @@ use serde::{Deserialize, Serialize};
|
|||
use sqlx::SqlitePool;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::services::AppError;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy, sqlx::Type)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[sqlx(rename_all = "lowercase")]
|
||||
|
|
@ -13,7 +15,7 @@ pub enum TaskStatus {
|
|||
Backlog,
|
||||
}
|
||||
|
||||
#[derive(sqlx::FromRow)]
|
||||
#[derive(sqlx::FromRow, Serialize)]
|
||||
pub struct TaskModel {
|
||||
pub id: Uuid,
|
||||
pub title: String,
|
||||
|
|
@ -46,15 +48,19 @@ impl TaskModel {
|
|||
Ok(result)
|
||||
}
|
||||
|
||||
pub async fn get_by_id(pool: &SqlitePool, id: Uuid) -> Result<TaskModel> {
|
||||
let result = sqlx::query_as("SELECT * FROM tasks WHERE id = $1")
|
||||
pub async fn get_by_id(pool: &SqlitePool, id: Uuid) -> Result<TaskModel, AppError> {
|
||||
let model = sqlx::query_as("SELECT * FROM tasks WHERE id = $1")
|
||||
.bind(id)
|
||||
.fetch_one(pool)
|
||||
.await?;
|
||||
Ok(result)
|
||||
.await
|
||||
.map_err(|err| match err {
|
||||
sqlx::Error::RowNotFound => AppError::NotFound,
|
||||
e => anyhow::Error::from(e).into(),
|
||||
})?;
|
||||
Ok(model)
|
||||
}
|
||||
|
||||
pub async fn update(self, pool: &SqlitePool) -> Result<TaskModel> {
|
||||
pub async fn update(self, pool: &SqlitePool) -> Result<TaskModel, AppError> {
|
||||
let now: DateTime<Utc> = Utc::now();
|
||||
|
||||
let _ = sqlx::query(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue