routing the rest of implemented features, hits response problem
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use actix_cors::Cors;
|
||||
use actix_files as fs;
|
||||
use actix_web::{web, middleware, App, Error, HttpResponse, HttpServer};
|
||||
use futures::Future;
|
||||
use futures::{Future, IntoFuture};
|
||||
use std::env;
|
||||
|
||||
use lootalot_db as db;
|
||||
@@ -12,6 +12,12 @@ type PlayerId = web::Path<i32>;
|
||||
type ItemId = web::Json<i32>;
|
||||
type ItemListWithMods = web::Json<Vec<(i32, Option<f64>)>>;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct NewGroupLoot {
|
||||
source_name: String,
|
||||
items: Vec<db::Item>,
|
||||
}
|
||||
|
||||
/// Wraps call to the database query and convert its result as a async HttpResponse
|
||||
pub fn db_call(
|
||||
pool: AppPool,
|
||||
@@ -44,6 +50,9 @@ fn configure_app(config: &mut web::ServiceConfig) {
|
||||
.route("/", web::get().to_async(|pool, player: PlayerId| {
|
||||
db_call(pool, Q::FetchPlayer(*player))
|
||||
}))
|
||||
.route("/notifications", web::get().to_async(|pool, player: PlayerId| {
|
||||
db_call(pool, Q::FetchNotifications(*player))
|
||||
}))
|
||||
.service(
|
||||
web::resource("/claims")
|
||||
//.route(web::get().to_async(endpoints::player_claims))
|
||||
@@ -83,6 +92,14 @@ fn configure_app(config: &mut web::ServiceConfig) {
|
||||
db_call(pool, Q::BuyItems(*player, data.into_inner()))
|
||||
},
|
||||
))
|
||||
.route(web::post().to_async(
|
||||
move |pool, (player, data): (PlayerId, web::Json<NewGroupLoot>)| {
|
||||
match *player {
|
||||
0 => db_call(pool, Q::AddLoot(data.items.clone())),
|
||||
_ => HttpResponse::Forbidden().finish().into_future(),
|
||||
}
|
||||
},
|
||||
))
|
||||
.route(web::delete().to_async(
|
||||
move |pool, (player, data): (PlayerId, ItemListWithMods)| {
|
||||
db_call(pool, Q::SellItems(*player, data.into_inner()))
|
||||
|
||||
Reference in New Issue
Block a user