Housekeeping. Unit tests, coverage, formatter, linter. #4

Merged
drew merged 1 commit from housekeep into main 2025-09-20 19:30:36 +00:00
4 changed files with 8 additions and 7 deletions
Showing only changes of commit fd1ee102d0 - Show all commits

View file

@ -1,3 +1,3 @@
pub mod connection; pub mod connection;
pub use connection::*; pub use connection::*;

View file

@ -32,7 +32,7 @@ impl TaskModel {
title: &str, title: &str,
description: Option<&str>, description: Option<&str>,
) -> Result<TaskModel> { ) -> Result<TaskModel> {
if title.len() == 0 { if title.is_empty() {
bail!("Title must not be empty"); bail!("Title must not be empty");
} }
@ -70,10 +70,10 @@ impl TaskModel {
) )
.bind(&self.title) .bind(&self.title)
.bind(&self.description) .bind(&self.description)
.bind(&self.status) .bind(self.status)
.bind(now) .bind(now)
.bind(&self.completed_at) .bind(self.completed_at)
.bind(&self.id) .bind(self.id)
.execute(pool) .execute(pool)
.await?; .await?;

View file

@ -9,6 +9,7 @@ use axum::{
// AppError // AppError
// Borrowed from example: https://github.com/tokio-rs/axum/blob/axum-v0.8.4/examples/anyhow-error-response/src/main.rs // Borrowed from example: https://github.com/tokio-rs/axum/blob/axum-v0.8.4/examples/anyhow-error-response/src/main.rs
#[derive(Debug)]
pub enum AppError { pub enum AppError {
InternalError(anyhow::Error), InternalError(anyhow::Error),
JsonExtractError(JsonRejection), JsonExtractError(JsonRejection),
@ -74,7 +75,7 @@ impl From<PathRejection> for AppError {
impl From<anyhow::Error> for AppError { impl From<anyhow::Error> for AppError {
fn from(err: anyhow::Error) -> Self { fn from(err: anyhow::Error) -> Self {
Self::InternalError(err.into()) Self::InternalError(err)
} }
} }

View file

@ -73,7 +73,7 @@ pub async fn update_task(
let mut model = TaskModel::get_by_id(&pool, task_id).await?; let mut model = TaskModel::get_by_id(&pool, task_id).await?;
if let Some(title) = input.title { if let Some(title) = input.title {
if title.len() == 0 { if title.is_empty() {
return Err(AppError::Unprocessable( return Err(AppError::Unprocessable(
"Title must not be empty".to_string(), "Title must not be empty".to_string(),
)); ));