|
|
@@ -0,0 +1,54 @@
|
|
|
+use actix_web::{HttpResponse, HttpRequest, web, post};
|
|
|
+use sqlx::PgPool;
|
|
|
+use uuid::Uuid;
|
|
|
+use crate::{
|
|
|
+ http_error::HttpError,
|
|
|
+ auth::user_auth,
|
|
|
+ models::{
|
|
|
+ game::Game,
|
|
|
+ character::Character,
|
|
|
+ session::Session
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+#[post("/game/{game_id}/session")]
|
|
|
+pub async fn route(
|
|
|
+ db: web::Data<PgPool>,
|
|
|
+ path: web::Path<String>,
|
|
|
+ req: HttpRequest
|
|
|
+) -> Result<HttpResponse, HttpError> {
|
|
|
+ let user = user_auth(&db, &req, true).await?;
|
|
|
+ let game_id = Uuid::parse_str(&path.into_inner())?;
|
|
|
+ let (game, mut characters, sessions) = Game::get_full_game(&db, game_id, Some(user.id)).await?;
|
|
|
+ let text = new_session_text(game.game_context.clone(), characters.remove(0), sessions);
|
|
|
+
|
|
|
+ Ok(HttpResponse::Ok().json(game))
|
|
|
+}
|
|
|
+
|
|
|
+fn new_session_text(
|
|
|
+ game_context: String,
|
|
|
+ character: Character,
|
|
|
+ sessions: Vec<Session>
|
|
|
+) -> String {
|
|
|
+ let mut text = "".to_string();
|
|
|
+
|
|
|
+ text += "You are acting as a game master for an RPG and running the game.\n";
|
|
|
+ text += &format!("Here is the context for the world: {}\n", game_context);
|
|
|
+ text += &format!(
|
|
|
+ "Character name is {}, here is a description of the character: {}\n",
|
|
|
+ character.name,
|
|
|
+ character.description
|
|
|
+ );
|
|
|
+
|
|
|
+ if sessions.len() == 0 {
|
|
|
+ text += "This is the first session in this game, there have been no previous sessions\n";
|
|
|
+ } else {
|
|
|
+ for (i, session) in sessions.iter().enumerate() {
|
|
|
+ text += &format!("Summary of session {}: {}\n", i, session.summary);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ text += "Start off a new session for the player";
|
|
|
+
|
|
|
+ text
|
|
|
+}
|