From ab95c49663695446ffdc41ecffb1dd66969b1d0c Mon Sep 17 00:00:00 2001 From: rakuja Date: Mon, 9 Dec 2024 10:20:28 +0100 Subject: [PATCH] chore: add sort by is_melee, is_ranged, is_spellcaster --- src/db/bestiary_proxy.rs | 20 ++++++++++++++++++++ src/models/bestiary_structs.rs | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/src/db/bestiary_proxy.rs b/src/db/bestiary_proxy.rs index 52c7af5..ce7a86b 100644 --- a/src/db/bestiary_proxy.rs +++ b/src/db/bestiary_proxy.rs @@ -97,6 +97,26 @@ pub async fn get_paginated_creatures( .essential .family .cmp(&b.core_data.essential.family), + CreatureSortEnum::Alignment => a + .core_data + .essential + .alignment + .cmp(&b.core_data.essential.alignment), + CreatureSortEnum::Melee => a + .core_data + .derived + .is_melee + .cmp(&b.core_data.derived.is_melee), + CreatureSortEnum::Ranged => a + .core_data + .derived + .is_ranged + .cmp(&b.core_data.derived.is_ranged), + CreatureSortEnum::SpellCaster => a + .core_data + .derived + .is_spell_caster + .cmp(&b.core_data.derived.is_spell_caster), }; match pagination .bestiary_sort_data diff --git a/src/models/bestiary_structs.rs b/src/models/bestiary_structs.rs index 5d43997..dc8eef2 100644 --- a/src/models/bestiary_structs.rs +++ b/src/models/bestiary_structs.rs @@ -29,6 +29,14 @@ pub enum CreatureSortEnum { Rarity, #[serde(alias = "family", alias = "FAMILY")] Family, + #[serde(alias = "alignment", alias = "ALIGNMENT")] + Alignment, + #[serde(alias = "melee", alias = "MELEE")] + Melee, + #[serde(alias = "ranged", alias = "RANGED")] + Ranged, + #[serde(alias = "SPELLCASTER", alias = "SPELLCASTER")] + SpellCaster, } #[derive(Serialize, Deserialize, IntoParams, ToSchema, Eq, PartialEq, Hash, Default)]