learning how to test

This commit is contained in:
2019-07-12 15:56:16 +02:00
parent caa8d3fad6
commit 5d54d40bec
13 changed files with 2956 additions and 130 deletions

View File

@@ -1,6 +1,6 @@
extern crate actix_web;
extern crate dotenv;
extern crate env_logger;
extern crate actix_web;
extern crate lootalot_db;
mod server;

View File

@@ -1,9 +1,9 @@
use std::env;
use futures::Future;
use actix_files as fs;
use actix_web::{web, App, HttpServer, HttpResponse, Error};
use actix_cors::Cors;
use lootalot_db::{Pool, DbApi, QueryResult};
use actix_files as fs;
use actix_web::{web, App, Error, HttpResponse, HttpServer};
use futures::Future;
use lootalot_db::{DbApi, Pool, QueryResult};
use std::env;
type AppPool = web::Data<Pool>;
@@ -61,17 +61,17 @@ pub(crate) fn serve() -> std::io::Result<()> {
Cors::new()
.allowed_origin("http://localhost:8080")
.allowed_methods(vec!["GET", "POST"])
.max_age(3600)
.max_age(3600),
)
.route(
"/api/players",
web::get().to_async(move |pool: AppPool| {
db_call(pool, move |api| api.fetch_players())
}),
web::get()
.to_async(move |pool: AppPool| db_call(pool, move |api| api.fetch_players())),
)
.route(
"/api/claims",
web::get().to_async(move |pool: AppPool| db_call(pool, move |api| api.fetch_claims())),
web::get()
.to_async(move |pool: AppPool| db_call(pool, move |api| api.fetch_claims())),
)
.route(
"/api/{player_id}/update-wealth/{amount}",
@@ -89,13 +89,13 @@ pub(crate) fn serve() -> std::io::Result<()> {
"/api/{player_id}/claim/{item_id}",
web::get().to_async(move |pool: AppPool, data: web::Path<(i32, i32)>| {
db_call(pool, move |api| api.as_player(data.0).claim(data.1))
})
}),
)
.route(
"/api/{player_id}/unclaim/{item_id}",
web::get().to_async(move |pool: AppPool, data: web::Path<(i32, i32)>| {
db_call(pool, move |api| api.as_player(data.0).unclaim(data.1))
})
}),
)
.route(
"/api/admin/resolve-claims",
@@ -106,7 +106,9 @@ pub(crate) fn serve() -> std::io::Result<()> {
.route(
"/api/admin/add-player/{name}/{wealth}",
web::get().to_async(move |pool: AppPool, data: web::Path<(String, f32)>| {
db_call(pool, move |api| api.as_admin().add_player(data.0.clone(), data.1))
db_call(pool, move |api| {
api.as_admin().add_player(data.0.clone(), data.1)
})
}),
)
.service(fs::Files::new("/", www_root.clone()).index_file("index.html"))