aboutsummaryrefslogtreecommitdiff
path: root/common/src/api.rs
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/api.rs')
-rw-r--r--common/src/api.rs26
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",
- }
+ }
);