style: fix the rustfmt linted files
Some checks failed
actionlint check / actionlint check (pull_request) Successful in 5s
checkov check / checkov check (pull_request) Successful in 52s
conventional commit messages check / conventional commit messages check (pull_request) Successful in 4s
conventional pull request title check / conventional pull request title check (pull_request) Successful in 2s
dotenv-linter check / dotenv-linter check (pull_request) Successful in 5s
GitLeaks check / GitLeaks check (pull_request) Successful in 6s
hadolint check / hadolint check (pull_request) Successful in 7s
htmlhint check / htmlhint check (pull_request) Successful in 9s
markdownlint check / markdownlint check (pull_request) Successful in 9s
Prettier check / Prettier check (pull_request) Successful in 10s
Rust check / Rust check (pull_request) Failing after 6m20s
ShellCheck check / ShellCheck check (pull_request) Successful in 12s
Stylelint check / Stylelint check (pull_request) Successful in 11s
yamllint check / yamllint check (pull_request) Successful in 13s

This commit is contained in:
2024-12-29 19:30:35 +01:00
parent 149451cc77
commit 3646aa91c4
47 changed files with 393 additions and 296 deletions

View File

@ -1,4 +1,3 @@
use std::hash::Hash;
use crate::schema::tasks;
use chrono::{Duration, NaiveDate, NaiveTime};
use diesel::deserialize::FromSql;
@ -9,6 +8,7 @@ use diesel::{AsExpression, BoxableExpression, FromSqlRow, PgJsonbExpressionMetho
use serde::{Deserialize, Serialize};
use serde_json::json;
use serde_with::DurationSeconds;
use std::hash::Hash;
use std::io::Write;
#[serde_with::serde_as]
@ -30,7 +30,7 @@ pub enum Category {
}
impl Category {
pub fn eq_sql_predicate(&self) -> Box<dyn BoxableExpression<tasks::table, Pg, SqlType=Bool>> {
pub fn eq_sql_predicate(&self) -> Box<dyn BoxableExpression<tasks::table, Pg, SqlType = Bool>> {
use crate::schema::tasks::dsl::*;
match self {
@ -99,13 +99,17 @@ pub struct Reoccurrence {
impl Reoccurrence {
pub fn new(start_date: NaiveDate, interval: ReoccurrenceInterval, length: u32) -> Self {
Self { start_date, interval, length }
Self {
start_date,
interval,
length,
}
}
pub fn start_date(&self) -> NaiveDate {
self.start_date
}
pub fn interval(&self) -> &ReoccurrenceInterval {
&self.interval
}
@ -125,9 +129,12 @@ pub struct CalendarTime {
impl CalendarTime {
pub fn new(time: NaiveTime, reminder_offset: Option<Duration>) -> Self {
Self { time, reminder_offset }
Self {
time,
reminder_offset,
}
}
pub fn time(&self) -> NaiveTime {
self.time
}

View File

@ -1,4 +1,4 @@
pub(crate) mod project;
pub(crate) mod category;
pub(crate) mod task;
pub(crate) mod project;
pub(crate) mod subtask;
pub(crate) mod task;

View File

@ -1,10 +1,10 @@
use std::cmp::Ordering;
use chrono::NaiveDateTime;
use crate::internationalization::COLLATOR;
use crate::schema::projects;
use chrono::NaiveDateTime;
use diesel::prelude::*;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use validator::Validate;
use crate::internationalization::COLLATOR;
const TITLE_LENGTH_MIN: u64 = 1;
const TITLE_LENGTH_MAX: u64 = 255;
@ -27,11 +27,11 @@ impl Project {
pub fn title(&self) -> &str {
&self.title
}
pub fn created_at(&self) -> NaiveDateTime {
self.created_at
}
pub fn updated_at(&self) -> NaiveDateTime {
self.updated_at
}
@ -47,14 +47,21 @@ impl PartialOrd<Self> for Project {
impl Ord for Project {
fn cmp(&self, other: &Self) -> Ordering {
COLLATOR.lock().unwrap().collate(self.title(), other.title())
COLLATOR
.lock()
.unwrap()
.collate(self.title(), other.title())
}
}
#[derive(Insertable, Serialize, Deserialize, Validate, Clone, Debug)]
#[diesel(table_name = projects)]
pub struct NewProject {
#[validate(length(min = "TITLE_LENGTH_MIN", max = "TITLE_LENGTH_MAX", code = "title_length"))]
#[validate(length(
min = "TITLE_LENGTH_MIN",
max = "TITLE_LENGTH_MAX",
code = "title_length"
))]
pub title: String,
}

View File

@ -1,16 +1,25 @@
use std::cmp::Ordering;
use crate::models::task::Task;
use crate::schema::subtasks;
use chrono::NaiveDateTime;
use diesel::prelude::*;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use validator::Validate;
const TITLE_LENGTH_MIN: u64 = 1;
const TITLE_LENGTH_MAX: u64 = 255;
#[derive(Queryable, Selectable, Identifiable, Associations, Serialize, Deserialize, PartialEq,
Clone, Debug)]
#[derive(
Queryable,
Selectable,
Identifiable,
Associations,
Serialize,
Deserialize,
PartialEq,
Clone,
Debug,
)]
#[diesel(belongs_to(Task, foreign_key = task_id))]
#[diesel(table_name = subtasks)]
#[diesel(check_for_backend(diesel::pg::Pg))]
@ -59,7 +68,8 @@ impl PartialOrd<Self> for Subtask {
impl Ord for Subtask {
fn cmp(&self, other: &Self) -> Ordering {
self.is_completed().cmp(&other.is_completed())
self.is_completed()
.cmp(&other.is_completed())
.then(self.created_at().cmp(&other.created_at()))
}
}
@ -68,14 +78,22 @@ impl Ord for Subtask {
#[diesel(table_name = subtasks)]
pub struct NewSubtask {
pub task_id: i32,
#[validate(length(min = "TITLE_LENGTH_MIN", max = "TITLE_LENGTH_MAX", code = "title_length"))]
#[validate(length(
min = "TITLE_LENGTH_MIN",
max = "TITLE_LENGTH_MAX",
code = "title_length"
))]
pub title: String,
pub is_completed: bool,
}
impl NewSubtask {
pub fn new(task_id: i32, title: String, is_completed: bool) -> Self {
Self { task_id, title, is_completed }
Self {
task_id,
title,
is_completed,
}
}
}

View File

@ -67,23 +67,39 @@ impl Ord for Task {
match (&self.category, &other.category) {
(Category::Inbox, Category::Inbox) => self.created_at.cmp(&other.created_at),
(
Category::Calendar { date: self_date, time: self_time, .. },
Category::Calendar { date: other_date, time: other_time, .. }
) => self_date.cmp(other_date)
.then(ReverseOrdOption::from(
&self_time.as_ref().map(|calendar_time| calendar_time.time())
).cmp(&ReverseOrdOption::from(
&other_time.as_ref().map(|calendar_time| calendar_time.time())
)))
.then(ReverseOrdOption::from(&self.deadline()).cmp(
&ReverseOrdOption::from(&other.deadline())
))
Category::Calendar {
date: self_date,
time: self_time,
..
},
Category::Calendar {
date: other_date,
time: other_time,
..
},
) => self_date
.cmp(other_date)
.then(
ReverseOrdOption::from(
&self_time.as_ref().map(|calendar_time| calendar_time.time()),
)
.cmp(&ReverseOrdOption::from(
&other_time
.as_ref()
.map(|calendar_time| calendar_time.time()),
)),
)
.then(
ReverseOrdOption::from(&self.deadline())
.cmp(&ReverseOrdOption::from(&other.deadline())),
)
.then(self.created_at.cmp(&other.created_at)),
(Category::Done, Category::Done) | (Category::Trash, Category::Trash) => {
self.updated_at.cmp(&other.updated_at).reverse()
}
(_, _) => ReverseOrdOption::from(&self.deadline())
.cmp(&ReverseOrdOption::from(&other.deadline()))
.then(self.created_at.cmp(&other.created_at)),
(Category::Done, Category::Done) | (Category::Trash, Category::Trash)
=> self.updated_at.cmp(&other.updated_at).reverse(),
(_, _) => ReverseOrdOption::from(&self.deadline()).cmp(
&ReverseOrdOption::from(&other.deadline())
).then(self.created_at.cmp(&other.created_at)),
}
}
}
@ -125,7 +141,11 @@ impl Ord for TaskWithSubtasks {
#[derive(Insertable, Serialize, Deserialize, Validate, Clone, Debug)]
#[diesel(table_name = tasks)]
pub struct NewTask {
#[validate(length(min = "TITLE_LENGTH_MIN", max = "TITLE_LENGTH_MAX", code = "title_length"))]
#[validate(length(
min = "TITLE_LENGTH_MIN",
max = "TITLE_LENGTH_MAX",
code = "title_length"
))]
pub title: String,
pub deadline: Option<chrono::NaiveDate>,
pub category: Category,
@ -139,7 +159,12 @@ impl NewTask {
category: Category,
project_id: Option<i32>,
) -> Self {
Self { title, deadline, category, project_id }
Self {
title,
deadline,
category,
project_id,
}
}
}