packs route
This commit is contained in:
parent
a85f0b5d40
commit
12f571d59c
|
@ -1,5 +1,7 @@
|
|||
name: Bloodborne
|
||||
id: bd4f9382-4ec7-4457-ba40-bdf5e5ee7fd0
|
||||
visible: true
|
||||
order: 3
|
||||
|
||||
templates:
|
||||
- 'fear {0}'
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
name: Dark Souls
|
||||
id: d8be51e4-ddce-4c91-9adf-a7a42457da28
|
||||
visible: true
|
||||
order: 4
|
||||
|
||||
templates:
|
||||
- '{0} ahead'
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
name: Elden Ring
|
||||
id: 8169c792-3d7c-44eb-aeee-9823c8521ae6
|
||||
visible: true
|
||||
order: 2
|
||||
|
||||
templates:
|
||||
- '{0} ahead'
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
name: FINAL FANTASY XIV
|
||||
id: 120e0e08-9533-454b-bfab-f8774a5b6d80
|
||||
visible: true
|
||||
order: 1
|
||||
|
||||
templates:
|
||||
- '{0} ahead'
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
name: FINAL FANTASY XIV (v1)
|
||||
id: 7cd9e479-080a-4fec-9511-41a53034c2ad
|
||||
visible: false
|
||||
|
||||
templates:
|
||||
- '{0} ahead'
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
name: FINAL FANTASY XIV (v2)
|
||||
id: 7fe38343-efb5-477b-a17f-71d910ae075b
|
||||
visible: false
|
||||
|
||||
templates:
|
||||
- '{0} ahead'
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
name: FINAL FANTASY XIV (v3)
|
||||
id: 43cf8e42-43fe-42cf-b989-6446e30fa914
|
||||
visible: false
|
||||
|
||||
templates:
|
||||
- '{0} ahead'
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
use serde::Deserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct Pack {
|
||||
pub name: String,
|
||||
pub id: Uuid,
|
||||
#[serde(skip_serializing)]
|
||||
pub visible: bool,
|
||||
#[serde(default, skip_serializing)]
|
||||
pub order: u8,
|
||||
pub templates: Vec<String>,
|
||||
pub conjunctions: Vec<String>,
|
||||
pub words: Vec<WordList>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct WordList {
|
||||
pub name: String,
|
||||
pub words: Vec<String>,
|
||||
|
|
|
@ -18,6 +18,7 @@ mod get_mine;
|
|||
mod get_message;
|
||||
mod claim;
|
||||
mod ping;
|
||||
mod packs;
|
||||
|
||||
pub fn routes(state: Arc<State>) -> BoxedFilter<(impl Reply, )> {
|
||||
register::register(Arc::clone(&state))
|
||||
|
@ -30,6 +31,7 @@ pub fn routes(state: Arc<State>) -> BoxedFilter<(impl Reply, )> {
|
|||
.or(get_mine::get_mine(Arc::clone(&state)))
|
||||
.or(claim::claim(Arc::clone(&state)))
|
||||
.or(ping::ping(Arc::clone(&state)))
|
||||
.or(packs::packs(Arc::clone(&state)))
|
||||
.recover(handle_rejection)
|
||||
.boxed()
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use warp::{Filter, Rejection, Reply};
|
||||
use warp::filters::BoxedFilter;
|
||||
|
||||
use crate::{Pack, State};
|
||||
|
||||
pub fn packs(state: Arc<State>) -> BoxedFilter<(impl Reply, )> {
|
||||
warp::get()
|
||||
.and(warp::path("packs"))
|
||||
.and(warp::path::end())
|
||||
.and_then(move || logic(Arc::clone(&state)))
|
||||
.boxed()
|
||||
}
|
||||
|
||||
async fn logic(state: Arc<State>) -> Result<impl Reply, Rejection> {
|
||||
let mut visible: Vec<Pack> = state.packs.read()
|
||||
.await
|
||||
.values()
|
||||
.filter(|pack| pack.visible)
|
||||
.map(|pack| pack.clone())
|
||||
.collect();
|
||||
visible.sort_unstable_by_key(|pack| pack.order);
|
||||
|
||||
Ok(warp::reply::json(&visible))
|
||||
}
|
Loading…
Reference in New Issue