2021-11-07 21:23:18 +00:00
|
|
|
use crate::models::parameters::CommandRequest;
|
|
|
|
use crate::models::player::UserID;
|
|
|
|
use serde::{Deserialize, Serialize};
|
2021-12-01 04:13:56 +00:00
|
|
|
use std::fmt::{Display, Formatter};
|
|
|
|
use std::str::FromStr;
|
2021-11-07 21:23:18 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub enum ItemSort {
|
|
|
|
Price,
|
|
|
|
Restock,
|
|
|
|
}
|
|
|
|
|
2021-12-01 04:13:56 +00:00
|
|
|
impl Display for ItemSort {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
let s = match self {
|
|
|
|
ItemSort::Price => "Price",
|
|
|
|
ItemSort::Restock => "Restock Time",
|
|
|
|
};
|
|
|
|
|
|
|
|
write!(f, "{}", s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for ItemSort {
|
|
|
|
type Err = String;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
let sort = match s.to_lowercase().as_str() {
|
|
|
|
"price" => ItemSort::Price,
|
|
|
|
"restock" => ItemSort::Restock,
|
|
|
|
&_ => return Err(format!("Unknown sort '{}'", s)),
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(sort)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-14 23:28:55 +00:00
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
2021-11-07 21:23:18 +00:00
|
|
|
pub enum Order {
|
|
|
|
High,
|
|
|
|
Low,
|
|
|
|
}
|
|
|
|
|
2021-12-01 04:13:56 +00:00
|
|
|
impl Display for Order {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
let s = match self {
|
|
|
|
Order::High => "High",
|
|
|
|
Order::Low => "Low",
|
|
|
|
};
|
|
|
|
|
|
|
|
write!(f, "{}", s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for Order {
|
|
|
|
type Err = String;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
let order = match s.to_lowercase().as_str() {
|
|
|
|
"high" => Order::High,
|
|
|
|
"low" => Order::Low,
|
|
|
|
&_ => return Err(format!("Unknown sorting '{}'", s)),
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(order)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 21:23:18 +00:00
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct SellingParams {
|
|
|
|
pub token: String,
|
|
|
|
pub query: String,
|
|
|
|
pub sort: Option<ItemSort>,
|
|
|
|
pub order: Option<Order>,
|
|
|
|
}
|
|
|
|
|
2021-12-01 04:13:56 +00:00
|
|
|
impl SellingParams {
|
|
|
|
pub fn new(query: String, sort: Option<ItemSort>, order: Option<Order>) -> Self {
|
|
|
|
Self {
|
|
|
|
token: Default::default(),
|
|
|
|
query,
|
|
|
|
sort,
|
|
|
|
order,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 21:23:18 +00:00
|
|
|
impl CommandRequest for SellingParams {
|
|
|
|
fn token(&self) -> String {
|
|
|
|
self.token.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn user_id(&self) -> Option<UserID> {
|
|
|
|
None
|
|
|
|
}
|
2021-12-01 04:13:56 +00:00
|
|
|
|
|
|
|
fn set_token(&mut self, token: String) {
|
|
|
|
self.token = token;
|
|
|
|
}
|
2021-11-07 21:23:18 +00:00
|
|
|
}
|