diff options
author | metamuffin <metamuffin@disroot.org> | 2025-04-28 21:50:51 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-04-28 21:50:51 +0200 |
commit | 73d2d5eb01fceae9e0b1c58afb648822000c878a (patch) | |
tree | 8fd0279949251245e2086ad28e99b114eac1bf14 /common/src/api.rs | |
parent | 51761cbdefa39107b9e1f931f1aa8df6aebb2a94 (diff) | |
download | jellything-73d2d5eb01fceae9e0b1c58afb648822000c878a.tar jellything-73d2d5eb01fceae9e0b1c58afb648822000c878a.tar.bz2 jellything-73d2d5eb01fceae9e0b1c58afb648822000c878a.tar.zst |
yes
Diffstat (limited to 'common/src/api.rs')
-rw-r--r-- | common/src/api.rs | 26 |
1 files changed, 5 insertions, 21 deletions
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 <metamuffin.org> */ -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<SortProperty>, pub filter_kind: Option<Vec<FilterProperty>>, pub sort_order: Option<SortOrder>, } - -pub trait UrlEnum: Sized { - fn to_str(&self) -> &'static str; - fn from_str(s: &str) -> Option<Self>; -} -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<Self> { 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", - } + } ); |