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
80 lines
1.8 KiB
Rust
80 lines
1.8 KiB
Rust
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;
|
|
use validator::Validate;
|
|
|
|
const TITLE_LENGTH_MIN: u64 = 1;
|
|
const TITLE_LENGTH_MAX: u64 = 255;
|
|
|
|
#[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,
|
|
created_at: NaiveDateTime,
|
|
updated_at: NaiveDateTime,
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
impl Project {
|
|
pub fn id(&self) -> i32 {
|
|
self.id
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
impl Eq for Project {}
|
|
|
|
impl PartialOrd<Self> for Project {
|
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
|
Some(self.cmp(other))
|
|
}
|
|
}
|
|
|
|
impl Ord for Project {
|
|
fn cmp(&self, other: &Self) -> Ordering {
|
|
COLLATOR
|
|
.lock()
|
|
.unwrap()
|
|
.collate(self.title(), other.title())
|
|
}
|
|
}
|
|
|
|
#[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",
|
|
max = "TITLE_LENGTH_MAX",
|
|
code = "title_length"
|
|
))]
|
|
pub title: String,
|
|
}
|
|
|
|
impl NewProject {
|
|
pub fn new(title: String) -> Self {
|
|
Self { title }
|
|
}
|
|
}
|