diff options
author | metamuffin <metamuffin@disroot.org> | 2025-04-28 00:48:52 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-04-28 00:48:52 +0200 |
commit | 80d28b764c95891551e28c395783f5ff9d065743 (patch) | |
tree | f25898b1c939a939c63236ca4e8e843e81069947 /common | |
parent | 335ba978dbaf203f3603a815147fd75dbf205723 (diff) | |
download | jellything-80d28b764c95891551e28c395783f5ff9d065743.tar jellything-80d28b764c95891551e28c395783f5ff9d065743.tar.bz2 jellything-80d28b764c95891551e28c395783f5ff9d065743.tar.zst |
start with splitting server
Diffstat (limited to 'common')
-rw-r--r-- | common/src/api.rs | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/common/src/api.rs b/common/src/api.rs index 111ae57..6982e76 100644 --- a/common/src/api.rs +++ b/common/src/api.rs @@ -3,8 +3,9 @@ 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}; +#[cfg(feature = "rocket")] +use rocket::{FromForm, FromFormField, UriDisplayQuery}; use serde::{Deserialize, Serialize}; use std::sync::Arc; @@ -36,3 +37,66 @@ pub struct ApiHomeResponse { pub toplevel: NodesWithUdata, pub categories: Vec<(String, NodesWithUdata)>, } + +#[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>, +} + +#[rustfmt::skip] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "rocket", derive(FromFormField, UriDisplayQuery))] +pub enum SortOrder { + #[field(value = "ascending")] Ascending, + #[field(value = "descending")] Descending, +} + +macro_rules! form_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 { #[allow(unused)] const ALL: &'static [$i] = &[$($i::$vi),*]; } + }; +} + +form_enum!( + enum FilterProperty { + FederationLocal = "fed_local", + FederationRemote = "fed_remote", + Watched = "watched", + Unwatched = "unwatched", + WatchProgress = "watch_progress", + KindMovie = "kind_movie", + KindVideo = "kind_video", + KindShortFormVideo = "kind_short_form_video", + KindMusic = "kind_music", + KindCollection = "kind_collection", + KindChannel = "kind_channel", + KindShow = "kind_show", + KindSeries = "kind_series", + KindSeason = "kind_season", + KindEpisode = "kind_episode", + } +); + +form_enum!( + enum SortProperty { + ReleaseDate = "release_date", + Title = "title", + Index = "index", + Duration = "duration", + RatingRottenTomatoes = "rating_rt", + RatingMetacritic = "rating_mc", + RatingImdb = "rating_imdb", + RatingTmdb = "rating_tmdb", + RatingYoutubeViews = "rating_yt_views", + RatingYoutubeLikes = "rating_yt_likes", + RatingYoutubeFollowers = "rating_yt_followers", + RatingUser = "rating_user", + RatingLikesDivViews = "rating_loved", + } +); |