1use crate::attribute::Attribute;
2
3use super::GetUrl;
4
5#[derive(Debug, Copy, Clone, PartialEq, Eq)]
18pub struct Sort {
19 pub(crate) sort_type: SortOrder,
20 pub(crate) sort_by: Attribute,
21}
22
23impl GetUrl for Sort {
24 fn get_url(&self) -> String {
25 let mut url = String::from("sort=");
26 url.push_str(format!("{}:{}", self.sort_by.get_url(), self.sort_type.get_url()).as_str());
27 url
28 }
29}
30
31impl Sort {
32 pub fn new(sort_type: SortOrder, sort_by: Attribute) -> Self {
33 Self { sort_type, sort_by }
34 }
35
36 pub(crate) fn get_item_type(&self) -> crate::ItemType {
37 self.sort_by.get_item_type()
38 }
39}
40
41#[derive(Debug, Copy, Clone, PartialEq, Eq)]
43pub enum SortOrder {
44 Ascending,
45 Descending,
46}
47
48impl GetUrl for SortOrder {
49 fn get_url(&self) -> String {
50 match self {
51 SortOrder::Ascending => "asc",
52 SortOrder::Descending => "desc",
53 }
54 .to_string()
55 }
56}