From 29dd48e61fb90733be510418bbf83bd0c63ad21d Mon Sep 17 00:00:00 2001 From: Franz Dietrich Date: Wed, 11 Sep 2024 13:23:42 +0200 Subject: [PATCH] fix error and missing structs --- shared/src/apirequests/links.rs | 10 +++++++++- shared/src/datatypes.rs | 27 +++++++++++---------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/shared/src/apirequests/links.rs b/shared/src/apirequests/links.rs index acbacc0..6dfb314 100644 --- a/shared/src/apirequests/links.rs +++ b/shared/src/apirequests/links.rs @@ -12,6 +12,7 @@ use super::general::{EditMode, Filter, Operation, Ordering}; pub struct LinkRequestForm { pub filter: EnumMap, pub order: Option>, + pub offset: usize, pub amount: usize, } @@ -20,7 +21,8 @@ impl Default for LinkRequestForm { Self { filter: EnumMap::default(), order: None, - amount: 20, + offset: 0, + amount: 60, } } } @@ -77,6 +79,12 @@ pub enum LinkOverviewColumns { Statistics, } +/// A struct to request the statistics of a link +#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)] +pub struct StatisticsRequest { + pub link_id: i64, +} + /// A struct to request a qr-code from the server #[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)] pub struct QrCodeRequest { diff --git a/shared/src/datatypes.rs b/shared/src/datatypes.rs index 8b5fb45..4b7a23d 100644 --- a/shared/src/datatypes.rs +++ b/shared/src/datatypes.rs @@ -1,9 +1,9 @@ //! The more generic data-types used in pslink use std::ops::Deref; +use crate::apirequests::users::Role; use serde::{Deserialize, Serialize, Serializer}; use strum_macros::{AsRefStr, Display, EnumIter, EnumString}; -use crate::apirequests::users::Role; /// A generic list returntype containing the User and a Vec containing e.g. Links or Users #[derive(Clone, Deserialize, Serialize)] pub struct ListWithOwner { @@ -38,14 +38,7 @@ impl PartialEq for Clicks { impl PartialOrd for Clicks { fn partial_cmp(&self, other: &Self) -> Option { - match (self, other) { - (Self::Count(l0), Self::Count(r0)) => l0.number.partial_cmp(&r0.number), - (Self::Extended(l0), Self::Extended(r0)) => { - l0.total.number.partial_cmp(&r0.total.number) - } - (Clicks::Count(l0), Clicks::Extended(r0)) => l0.number.partial_cmp(&r0.total.number), - (Clicks::Extended(l0), Clicks::Count(r0)) => l0.total.number.partial_cmp(&r0.number), - } + Some(self.cmp(other)) } } @@ -89,11 +82,19 @@ pub struct Link { pub struct Count { pub number: i64, } + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct WeekCount { + pub month: chrono::NaiveDateTime, + pub total: Count, + pub week: i32, +} + impl Eq for WeekCount {} impl PartialOrd for WeekCount { fn partial_cmp(&self, other: &Self) -> std::option::Option { - self.total.number.partial_cmp(&other.total.number) + Some(self.cmp(other)) } } impl Ord for WeekCount { @@ -201,9 +202,3 @@ pub enum Lang { #[strum(serialize = "de-DE", serialize = "de", serialize = "deDE")] DeDE, } - -impl std::fmt::Display for Lang { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self) - } -}