Skip to content

Commit

Permalink
fix error and missing structs
Browse files Browse the repository at this point in the history
  • Loading branch information
enaut committed Sep 11, 2024
1 parent ffc1a59 commit 29dd48e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
10 changes: 9 additions & 1 deletion shared/src/apirequests/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use super::general::{EditMode, Filter, Operation, Ordering};
pub struct LinkRequestForm {
pub filter: EnumMap<LinkOverviewColumns, Filter>,
pub order: Option<Operation<LinkOverviewColumns, Ordering>>,
pub offset: usize,
pub amount: usize,
}

Expand All @@ -20,7 +21,8 @@ impl Default for LinkRequestForm {
Self {
filter: EnumMap::default(),
order: None,
amount: 20,
offset: 0,
amount: 60,
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down
27 changes: 11 additions & 16 deletions shared/src/datatypes.rs
Original file line number Diff line number Diff line change
@@ -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<T> {
Expand Down Expand Up @@ -38,14 +38,7 @@ impl PartialEq for Clicks {

impl PartialOrd for Clicks {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
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))
}
}

Expand Down Expand Up @@ -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<std::cmp::Ordering> {
self.total.number.partial_cmp(&other.total.number)
Some(self.cmp(other))
}
}
impl Ord for WeekCount {
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 29dd48e

Please sign in to comment.