Pārlūkot izejas kodu

Create base of the create game route

Lee Morgan 1 mēnesi atpakaļ
vecāks
revīzija
da8f5a3625

+ 23 - 0
src/controllers/game/create.rs

@@ -0,0 +1,23 @@
+use actix_web::{HttpResponse, HttpRequest, web, post};
+use sqlx::PgPool;
+use serde::Deserialize;
+use crate::{
+    http_error::HttpError,
+    auth::user_auth
+};
+
+#[derive(Deserialize)]
+struct Body {
+    title: String,
+    world_context: String
+}
+
+#[post("/game")]
+pub async fn route(
+    db: web::Data<PgPool>,
+    web::Json(body): web::Json<Body>,
+    req: HttpRequest
+) -> Result<HttpResponse, HttpError> {
+    let user = user_auth(&db, &req).await?;
+    Ok(HttpResponse::Ok().body("something"))
+}

+ 1 - 0
src/controllers/game/mod.rs

@@ -0,0 +1 @@
+pub mod create;

+ 1 - 0
src/controllers/mod.rs

@@ -1,2 +1,3 @@
 pub mod user;
 pub mod webhook;
+pub mod game;

+ 1 - 0
src/main.rs

@@ -65,6 +65,7 @@ async fn main() -> std::io::Result<()> {
             .app_data(web::Data::new(pool.clone()))
             .configure(routes::user::config)
             .configure(routes::webhook::config)
+            .configure(routes::game::config)
     })
         .bind(("0.0.0.0", port))
         .expect("Failed to bind to port")

+ 8 - 0
src/routes/game.rs

@@ -0,0 +1,8 @@
+use actix_web::web::ServiceConfig;
+use crate::controllers::game::{
+    create
+};
+
+pub fn config(cfg: &mut ServiceConfig) {
+    cfg.service(create::route);
+}

+ 1 - 0
src/routes/mod.rs

@@ -1,2 +1,3 @@
 pub mod user;
 pub mod webhook;
+pub mod game;