forked from Roflin/gamenight
Started working on a cli frontend.
This commit is contained in:
@@ -3,6 +3,7 @@ pub mod schema;
|
||||
pub mod util;
|
||||
|
||||
use actix_cors::Cors;
|
||||
use actix_web::middleware::Logger;
|
||||
use actix_web::HttpServer;
|
||||
use actix_web::App;
|
||||
use actix_web::http;
|
||||
@@ -12,6 +13,7 @@ use diesel::r2d2::{ConnectionManager, Pool};
|
||||
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
|
||||
use request::{login, register, gamenights, gamenight_post, gamenight_get};
|
||||
use util::GetConnection;
|
||||
use tracing_actix_web::TracingLogger;
|
||||
|
||||
pub(crate) type DbPool = Pool<ConnectionManager<PgConnection>>;
|
||||
|
||||
@@ -35,6 +37,8 @@ async fn main() -> std::io::Result<()> {
|
||||
let mut conn = pool.get_conn();
|
||||
run_migration(&mut conn);
|
||||
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
HttpServer::new(move || {
|
||||
let cors = Cors::default()
|
||||
.allowed_origin("0.0.0.0")
|
||||
@@ -46,6 +50,8 @@ async fn main() -> std::io::Result<()> {
|
||||
|
||||
App::new()
|
||||
.wrap(cors)
|
||||
.wrap(Logger::default())
|
||||
.wrap(TracingLogger::default())
|
||||
.app_data(web::Data::new(pool.clone()))
|
||||
.service(login)
|
||||
.service(register)
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::schema::{self};
|
||||
use crate::schema::user::User;
|
||||
use crate::request::requests::GamenightGet;
|
||||
use crate::request::requests::GamenightPost;
|
||||
use crate::request::responses::GameNightResponse;
|
||||
use crate::request::responses::GameNightsResponse;
|
||||
use crate::request::error::ApiError;
|
||||
use crate::DbPool;
|
||||
use crate::util::GetConnection;
|
||||
@@ -31,11 +31,11 @@ impl Into<Uuid> for GamenightGet {
|
||||
#[get("/gamenights")]
|
||||
pub async fn gamenights(pool: web::Data<DbPool>, _user: User) -> Result<impl Responder, ApiError> {
|
||||
let mut conn = pool.get_conn();
|
||||
let gamenights = schema::gamenights(&mut conn)?;
|
||||
let gamenights: GameNightsResponse = schema::gamenights(&mut conn)?;
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type(ContentType::json())
|
||||
.body(serde_json::to_string(&GameNightResponse { gamenights })?)
|
||||
.body(serde_json::to_string(&gamenights)?)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,4 @@ impl LoginResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct GameNightResponse {
|
||||
pub gamenights: Vec::<Gamenight>
|
||||
}
|
||||
pub type GameNightsResponse = Vec<Gamenight>;
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
use actix_web::http::header::ContentType;
|
||||
use actix_web::{web, post, HttpResponse, Responder};
|
||||
use actix_web::{web, get, post, HttpResponse, Responder};
|
||||
use validator::ValidateArgs;
|
||||
use crate::DbPool;
|
||||
use crate::request::requests::{Login, Register, RegisterContext};
|
||||
@@ -30,7 +30,7 @@ impl Into<schema::user::Register> for Register {
|
||||
}
|
||||
}
|
||||
|
||||
#[post("/token")]
|
||||
#[get("/token")]
|
||||
pub async fn login(pool: web::Data<DbPool>, login_data: web::Json<Login>) -> Result<impl Responder, ApiError> {
|
||||
let data = login_data.into_inner();
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ diesel::table! {
|
||||
diesel::table! {
|
||||
registration_tokens (id) {
|
||||
id -> Uuid,
|
||||
#[max_length = 32]
|
||||
token -> Bpchar,
|
||||
single_use -> Bool,
|
||||
expires -> Nullable<Timestamptz>,
|
||||
@@ -65,7 +66,9 @@ diesel::table! {
|
||||
}
|
||||
|
||||
diesel::joinable!(gamenight -> users (owner_id));
|
||||
diesel::joinable!(gamenight_gamelist -> gamenight (gamenight_id));
|
||||
diesel::joinable!(gamenight_gamelist -> known_games (game_id));
|
||||
diesel::joinable!(gamenight_participants -> gamenight (gamenight_id));
|
||||
diesel::joinable!(gamenight_participants -> users (user_id));
|
||||
diesel::joinable!(pwd -> users (user_id));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user