refactor: import different dependencies only in the correct target binary
Some checks failed
actionlint check / actionlint check (pull_request) Successful in 7s
checkov check / checkov check (pull_request) Successful in 53s
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 6s
GitLeaks check / GitLeaks check (pull_request) Successful in 7s
hadolint check / hadolint check (pull_request) Successful in 9s
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 7m40s
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 14s

This commit is contained in:
2024-12-29 20:50:06 +01:00
parent 3646aa91c4
commit a83b376f7b
19 changed files with 639 additions and 50 deletions

View File

@ -1,19 +1,28 @@
#[cfg(feature = "server")]
use crate::schema::tasks;
use chrono::{Duration, NaiveDate, NaiveTime};
#[cfg(feature = "server")]
use diesel::deserialize::FromSql;
#[cfg(feature = "server")]
use diesel::pg::{Pg, PgValue};
#[cfg(feature = "server")]
use diesel::serialize::{Output, ToSql};
#[cfg(feature = "server")]
use diesel::sql_types::{Bool, Jsonb};
#[cfg(feature = "server")]
use diesel::{AsExpression, BoxableExpression, FromSqlRow, PgJsonbExpressionMethods};
use serde::{Deserialize, Serialize};
#[cfg(feature = "server")]
use serde_json::json;
use serde_with::DurationSeconds;
use std::hash::Hash;
#[cfg(feature = "server")]
use std::io::Write;
#[serde_with::serde_as]
#[derive(AsExpression, FromSqlRow, Serialize, Deserialize, Clone, Debug)]
#[diesel(sql_type = Jsonb)]
#[derive(Serialize, Deserialize, Clone, Debug)]
#[cfg_attr(feature = "server", derive(AsExpression, FromSqlRow))]
#[cfg_attr(feature = "server", diesel(sql_type = Jsonb))]
pub enum Category {
Inbox,
SomedayMaybe,
@ -29,6 +38,7 @@ pub enum Category {
Trash,
}
#[cfg(feature = "server")]
impl Category {
pub fn eq_sql_predicate(&self) -> Box<dyn BoxableExpression<tasks::table, Pg, SqlType = Bool>> {
use crate::schema::tasks::dsl::*;
@ -60,6 +70,7 @@ impl PartialEq for Category {
impl Eq for Category {}
#[cfg(feature = "server")]
impl ToSql<Jsonb, Pg> for Category {
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> diesel::serialize::Result {
let json = serde_json::to_string(self)?;
@ -72,6 +83,7 @@ impl ToSql<Jsonb, Pg> for Category {
}
}
#[cfg(feature = "server")]
impl FromSql<Jsonb, Pg> for Category {
fn from_sql(bytes: PgValue) -> diesel::deserialize::Result<Self> {
let bytes = bytes.as_bytes();

View File

@ -1,6 +1,8 @@
use crate::internationalization::COLLATOR;
#[cfg(feature = "server")]
use crate::schema::projects;
use chrono::NaiveDateTime;
#[cfg(feature = "server")]
use diesel::prelude::*;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
@ -9,9 +11,12 @@ use validator::Validate;
const TITLE_LENGTH_MIN: u64 = 1;
const TITLE_LENGTH_MAX: u64 = 255;
#[derive(Queryable, Selectable, Identifiable, Serialize, Deserialize, PartialEq, Clone, Debug)]
#[diesel(table_name = crate::schema::projects)]
#[diesel(check_for_backend(diesel::pg::Pg))]
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
#[cfg_attr(feature = "server", derive(Queryable, Selectable, Identifiable))]
#[cfg_attr(
feature = "server",
diesel(table_name = crate::schema::projects, check_for_backend(diesel::pg::Pg))
)]
pub struct Project {
id: i32,
title: String,
@ -19,6 +24,7 @@ pub struct Project {
updated_at: NaiveDateTime,
}
#[allow(dead_code)]
impl Project {
pub fn id(&self) -> i32 {
self.id
@ -54,8 +60,9 @@ impl Ord for Project {
}
}
#[derive(Insertable, Serialize, Deserialize, Validate, Clone, Debug)]
#[diesel(table_name = projects)]
#[derive(Serialize, Deserialize, Validate, Clone, Debug)]
#[cfg_attr(feature = "server", derive(Insertable))]
#[cfg_attr(feature = "server", diesel(table_name = projects))]
pub struct NewProject {
#[validate(length(
min = "TITLE_LENGTH_MIN",

View File

@ -1,6 +1,9 @@
#[cfg(feature = "server")]
use crate::models::task::Task;
#[cfg(feature = "server")]
use crate::schema::subtasks;
use chrono::NaiveDateTime;
#[cfg(feature = "server")]
use diesel::prelude::*;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
@ -9,20 +12,19 @@ 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(Serialize, Deserialize, PartialEq, Clone, Debug)]
#[cfg_attr(
feature = "server",
derive(Queryable, Selectable, Identifiable, Associations)
)]
#[cfg_attr(
feature = "server",
diesel(
table_name = subtasks,
belongs_to(Task, foreign_key = task_id),
check_for_backend(diesel::pg::Pg)
)
)]
#[diesel(belongs_to(Task, foreign_key = task_id))]
#[diesel(table_name = subtasks)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Subtask {
id: i32,
task_id: i32,
@ -74,8 +76,9 @@ impl Ord for Subtask {
}
}
#[derive(Insertable, Serialize, Deserialize, Validate, Clone, Debug)]
#[diesel(table_name = subtasks)]
#[derive(Serialize, Deserialize, Validate, Clone, Debug)]
#[cfg_attr(feature = "server", derive(Insertable))]
#[cfg_attr(feature = "server", diesel(table_name = subtasks))]
pub struct NewSubtask {
pub task_id: i32,
#[validate(length(

View File

@ -1,8 +1,10 @@
use crate::models::category::Category;
use crate::models::subtask::Subtask;
#[cfg(feature = "server")]
use crate::schema::tasks;
use crate::utils::reverse_ord_option::ReverseOrdOption;
use chrono::NaiveDateTime;
#[cfg(feature = "server")]
use diesel::prelude::*;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
@ -11,9 +13,9 @@ use validator::Validate;
const TITLE_LENGTH_MIN: u64 = 1;
const TITLE_LENGTH_MAX: u64 = 255;
#[derive(Queryable, Selectable, Identifiable, Serialize, Deserialize, PartialEq, Clone, Debug)]
#[diesel(table_name = tasks)]
#[diesel(check_for_backend(diesel::pg::Pg))]
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
#[cfg_attr(feature = "server", derive(Queryable, Selectable, Identifiable))]
#[cfg_attr(feature = "server", diesel(table_name = tasks, check_for_backend(diesel::pg::Pg)))]
pub struct Task {
id: i32,
title: String,
@ -138,8 +140,9 @@ impl Ord for TaskWithSubtasks {
}
}
#[derive(Insertable, Serialize, Deserialize, Validate, Clone, Debug)]
#[diesel(table_name = tasks)]
#[derive(Serialize, Deserialize, Validate, Clone, Debug)]
#[cfg_attr(feature = "server", derive(Insertable))]
#[cfg_attr(feature = "server", diesel(table_name = tasks))]
pub struct NewTask {
#[validate(length(
min = "TITLE_LENGTH_MIN",