From 73d2d5eb01fceae9e0b1c58afb648822000c878a Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 28 Apr 2025 21:50:51 +0200 Subject: yes --- common/src/api.rs | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'common/src/api.rs') diff --git a/common/src/api.rs b/common/src/api.rs index a58c445..aaff940 100644 --- a/common/src/api.rs +++ b/common/src/api.rs @@ -3,7 +3,7 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2025 metamuffin */ -use crate::{user::NodeUserData, Node, NodeKind}; +use crate::{url_enum, user::NodeUserData, Node, NodeKind}; use serde::{Deserialize, Serialize}; use std::{collections::BTreeMap, sync::Arc, time::Duration}; @@ -53,32 +53,14 @@ pub struct StatsBin { } #[derive(Debug, Default, Clone)] -#[cfg_attr(feature = "rocket", derive(FromForm, UriDisplayQuery))] pub struct NodeFilterSort { pub sort_by: Option, pub filter_kind: Option>, pub sort_order: Option, } - -pub trait UrlEnum: Sized { - fn to_str(&self) -> &'static str; - fn from_str(s: &str) -> Option; -} -macro_rules! url_enum { - (enum $i:ident { $($vi:ident = $vk:literal),*, }) => { - #[derive(Debug, Clone, Copy, PartialEq, Eq)] - #[cfg_attr(feature = "rocket", derive(FromFormField, UriDisplayQuery))] - pub enum $i { $(#[cfg_attr(feature = "rocket", field(value = $vk))] $vi),* } - impl $i { pub const ALL: &'static [$i] = &[$($i::$vi),*]; } - impl UrlEnum for $i { - fn to_str(&self) -> &'static str { match self { $(Self::$vi => $vk),* } } - fn from_str(s: &str) -> Option { match s { $($vk => Some(Self::$vi) ),*, _ => None } } - } - }; -} - url_enum!( + #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum FilterProperty { FederationLocal = "fed_local", FederationRemote = "fed_remote", @@ -98,6 +80,7 @@ url_enum!( } ); url_enum!( + #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum SortProperty { ReleaseDate = "release_date", Title = "title", @@ -115,8 +98,9 @@ url_enum!( } ); url_enum!( + #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum SortOrder { Ascending = "ascending", Descending = "descending", - } + } ); -- cgit v1.2.3-70-g09d2