Bladeren bron

Create outline of character creation route

Lee Morgan 1 maand geleden
bovenliggende
commit
3250bfec48

+ 24 - 0
src/controllers/game/character/create.rs

@@ -0,0 +1,24 @@
+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 {
+    name: String,
+    description: String
+}
+
+#[post("/game/{game_id}/character")]
+pub async fn route(
+    db: web::Data<PgPool>,
+    game_id: web::Path<String>,
+    web::Json(body): web::Json<Body>,
+    req: HttpRequest
+) -> Result<HttpResponse, HttpError> {
+    let user = user_auth(&db, &req, true).await?;
+    Ok(HttpResponse::Ok().body("something"))
+}

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

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

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

@@ -1 +1,2 @@
 pub mod create;
+pub mod character;

+ 2 - 1
src/main.rs

@@ -65,7 +65,8 @@ 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)
+            .configure(routes::game::game::config)
+            .configure(routes::game::character::config)
     })
         .bind(("0.0.0.0", port))
         .expect("Failed to bind to port")

+ 0 - 0
src/routes/game.rs → src/routes/game/character.rs


+ 8 - 0
src/routes/game/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);
+}

+ 2 - 0
src/routes/game/mod.rs

@@ -0,0 +1,2 @@
+pub mod game;
+pub mod character;