This commit was merged in pull request #373.
This commit is contained in:
@@ -36,7 +36,8 @@ members = [
|
||||
# "tree",
|
||||
"visions/server",
|
||||
# "visions/types",
|
||||
"visions/ui", "visions/visions-core",
|
||||
"visions/ui",
|
||||
"visions/core",
|
||||
# "bike-lights/bike",
|
||||
]
|
||||
|
||||
|
||||
@@ -32,53 +32,6 @@ pub struct CharacterFilter {
|
||||
pub user_id: Option<UserId>,
|
||||
}
|
||||
|
||||
/*
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DatabaseError {
|
||||
#[error("Cannot find object: {0:?}")]
|
||||
CannotFind(#[from] SqlCannotFindObject),
|
||||
|
||||
#[error("Cannot save object: {0:?}")]
|
||||
CannotSave(#[from] serde_json::Error),
|
||||
|
||||
#[error("Connection to database lost")]
|
||||
ConnectionLost,
|
||||
}
|
||||
|
||||
impl From<DatabaseError> for CannotFind {
|
||||
fn from(value: DatabaseError) -> Self {
|
||||
match value {
|
||||
DatabaseError::CannotFind(val) => Self::CannotFind(val),
|
||||
DatabaseError::ConnectionLost => Self::ConnectionLost,
|
||||
DatabaseError::CannotSave(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DatabaseError> for ConnectionLost {
|
||||
fn from(value: DatabaseError) -> Self {
|
||||
match value {
|
||||
DatabaseError::ConnectionLost => ConnectionLost,
|
||||
DatabaseError::CannotFind(_) | DatabaseError::CannotSave(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ConnectionLost> for DatabaseError {
|
||||
fn from(_: ConnectionLost) -> Self {
|
||||
DatabaseError::ConnectionLost
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
#[derive(Debug)]
|
||||
struct DatabaseRequest {
|
||||
tx: Sender<ResultExt<Response, DatabaseError, Fatal>>,
|
||||
req: Request,
|
||||
}
|
||||
*/
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Fatal {
|
||||
// #[error("Response does not match request: {0:?}, {1:?}.")]
|
||||
@@ -143,20 +96,6 @@ pub enum CannotDelete {
|
||||
CannotOpen(#[from] CannotOpen),
|
||||
}
|
||||
|
||||
/*
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CreateSessionError {
|
||||
#[error("Cannot find user")]
|
||||
CannotFindUser,
|
||||
|
||||
#[error("Cannot open database")]
|
||||
CannotOpen(#[from] CannotOpen),
|
||||
|
||||
#[error("Cannot write to database")]
|
||||
WriteError(#[from] rusqlite::Error),
|
||||
}
|
||||
*/
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CannotSave {
|
||||
#[error("Cannot save object")]
|
||||
@@ -166,44 +105,6 @@ pub enum CannotSave {
|
||||
CannotOpen(#[from] CannotOpen),
|
||||
}
|
||||
|
||||
/*
|
||||
#[derive(Debug, Error)]
|
||||
#[error("The object with ID {0} was expected to exist but could not be found.")]
|
||||
pub struct SqlCannotFindObject(String);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CannotOpen {
|
||||
#[error("{0}")]
|
||||
CannotOpen(#[from] SqlCannotOpen),
|
||||
#[error("connection to database lost")]
|
||||
ConnectionLost,
|
||||
}
|
||||
|
||||
impl From<ConnectionLost> for CannotOpen {
|
||||
fn from(_: ConnectionLost) -> Self {
|
||||
Self::ConnectionLost
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CannotFind {
|
||||
#[error("{0}")]
|
||||
CannotFind(#[from] SqlCannotFindObject),
|
||||
#[error("connection to database lost")]
|
||||
ConnectionLost,
|
||||
}
|
||||
|
||||
impl From<ConnectionLost> for CannotFind {
|
||||
fn from(_: ConnectionLost) -> Self {
|
||||
Self::ConnectionLost
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[error("Lost the connection to the database")]
|
||||
pub struct ConnectionLost;
|
||||
*/
|
||||
|
||||
const MIGRATIONS_LIST: &[M<'_>] = &[M::up(
|
||||
"CREATE TABLE users (id TEXT PRIMARY KEY NOT NULL,
|
||||
email TEXT NOT NULL,
|
||||
@@ -272,7 +173,7 @@ const MIGRATIONS_LIST: &[M<'_>] = &[M::up(
|
||||
DROP TABLE games;
|
||||
DROP TABLE sessions;
|
||||
DROP TABLE users;
|
||||
",
|
||||
",
|
||||
)];
|
||||
|
||||
const MIGRATIONS: Migrations<'_> = Migrations::from_slice(MIGRATIONS_LIST);
|
||||
@@ -856,101 +757,12 @@ impl DbHandle {
|
||||
game: GameId::from(row.get::<usize, String>(1)?),
|
||||
title: row.get::<usize, String>(2)?,
|
||||
background: row.get::<usize, String>(3)?,
|
||||
desktop_image: row.get::<usize, Option<String>>(4)?,
|
||||
desktop_image: None,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(scenes)
|
||||
}
|
||||
|
||||
/*
|
||||
async fn handler(mut self, mut requester: Receiver<DatabaseRequest>) {
|
||||
while let Some(DatabaseRequest { tx, req }) = requester.recv().await {
|
||||
let result = match req {
|
||||
Request::Session(session_id) => tx.send(ResultExt::promote_fatal(
|
||||
self.session_info(&session_id).map(Response::Session),
|
||||
)),
|
||||
|
||||
Request::SessionCreate(user_id) => tx.send(ResultExt::promote_fatal(
|
||||
self.new_session(&user_id).map(Response::SessionCreate),
|
||||
)),
|
||||
Request::SessionDelete(session_id) => tx.send(
|
||||
self.delete_session(&session_id)
|
||||
.map(|_| Response::SessionDelete)
|
||||
.map_err(DatabaseError::CannotFind),
|
||||
),
|
||||
// Request::SessionTouch(_session_id) => todo!(),
|
||||
Request::CardSave(card) => tx.send(
|
||||
self.save_card(card)
|
||||
.map(|_| Response::CardSave)
|
||||
.map_err(|err| err.into()),
|
||||
),
|
||||
|
||||
Request::CardDelete(card_id) => tx.send(
|
||||
self.delete_card(&card_id)
|
||||
.map(|_| Response::CardDelete)
|
||||
.map_err(DatabaseError::CannotFind),
|
||||
),
|
||||
Request::Card(card_id) => tx.send(ResultExt::promote_fatal(
|
||||
self.card(&card_id).map(Response::Card),
|
||||
)),
|
||||
Request::Cards(game_id) => tx.send(ResultExt::promote_fatal(
|
||||
self.cards(&game_id).map(Response::Cards),
|
||||
)),
|
||||
Request::CharacterSave(charsheet) => tx.send(ResultExt::promote_fatal(
|
||||
self.save_character(charsheet)
|
||||
.map(|_| Response::CharacterSave),
|
||||
)),
|
||||
Request::Character(character_id) => tx.send(ResultExt::promote_fatal(
|
||||
self.character(&character_id).map(Response::Character),
|
||||
)),
|
||||
Request::Characters(filter) => tx.send(ResultExt::promote_fatal(
|
||||
self.characters(filter).map(Response::Characters),
|
||||
)),
|
||||
Request::CharacterDelete(id) => tx.send(
|
||||
self.delete_character(&id)
|
||||
.map(|_| Response::CardDelete)
|
||||
.map_err(|err| err.into()),
|
||||
),
|
||||
Request::Game(game_id) => tx.send(ResultExt::promote_fatal(
|
||||
self.game(&game_id).map(Response::Game),
|
||||
)),
|
||||
Request::Games => {
|
||||
tx.send(ResultExt::promote_fatal(self.games().map(Response::Games)))
|
||||
}
|
||||
Request::GameSave(game) => tx.send(ResultExt::promote_fatal(
|
||||
self.save_game(game).map(|_| Response::GameSave),
|
||||
)),
|
||||
Request::Tabletop(game_id) => tx.send(ResultExt::promote_fatal(
|
||||
self.tabletop(&game_id).map(Response::Tabletop),
|
||||
)),
|
||||
Request::User(user_id) => tx.send(ResultExt::promote_fatal(
|
||||
self.user(&user_id).map(Response::User),
|
||||
)),
|
||||
Request::Users => {
|
||||
tx.send(ResultExt::promote_fatal(self.users().map(Response::Users)))
|
||||
}
|
||||
Request::UserSave(user) => tx.send(ResultExt::promote_fatal(
|
||||
self.save_user(user).map(|_| Response::UserSave),
|
||||
)),
|
||||
Request::UserByEmail(email) => tx.send(ResultExt::promote_fatal(
|
||||
self.user_by_email(&email).map(Response::User),
|
||||
)),
|
||||
Request::ScenesInGame(game_id) => tx.send(ResultExt::promote_fatal(
|
||||
self.scenes_in_game(&game_id).map(Response::Scenes),
|
||||
)),
|
||||
}
|
||||
.await;
|
||||
|
||||
match result {
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
eprintln!("Connection back to the app lost: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
fn user_by_session(
|
||||
@@ -964,25 +776,6 @@ fn user_by_session(
|
||||
WHERE sessions.id = ?1",
|
||||
)?;
|
||||
|
||||
/*
|
||||
match stmt
|
||||
.query_one(
|
||||
rusqlite::params![session_id.as_str()],
|
||||
user_row_and_expiration,
|
||||
)
|
||||
.optional()
|
||||
{
|
||||
Ok(Some((user_row, expiration))) => {
|
||||
let user = User::try_from(user_row)?;
|
||||
let expiration = expiration.parse::<u64>().map(|s| Duration::new(s, 0));
|
||||
let expiration = SystemTime::UNIX_EPOCH + expiration;
|
||||
|
||||
Ok(Some((user, expiration)))
|
||||
}
|
||||
Ok(None) => Ok(None),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
*/
|
||||
stmt.query_one(
|
||||
rusqlite::params![session_id.as_str()],
|
||||
user_row_and_expiration,
|
||||
@@ -1265,9 +1058,9 @@ fn read_scene(tx: &Transaction, id: &SceneId) -> Result<Option<Scene>, rusqlite:
|
||||
.query_one([id.as_str()], |row| {
|
||||
Ok(Scene {
|
||||
id: id.clone(),
|
||||
game: GameId::from(row.get::<usize, String>(2)?),
|
||||
title: row.get::<usize, String>(3)?,
|
||||
background: row.get::<usize, String>(4)?,
|
||||
game: GameId::from(row.get::<usize, String>(1)?),
|
||||
title: row.get::<usize, String>(2)?,
|
||||
background: row.get::<usize, String>(3)?,
|
||||
desktop_image: None,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use cool_asserts::assert_matches;
|
||||
use result_extended::ResultExt;
|
||||
use visions_types::*;
|
||||
|
||||
use crate::{
|
||||
|
||||
@@ -12,14 +12,14 @@ rusqlite = "0.37.0"
|
||||
rusqlite_migration = "2.3.0"
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
tempfile = "3.23.0"
|
||||
tempfile = "3.23.0"
|
||||
thiserror = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
tower-http = { workspace = true, features = ["trace"] }
|
||||
tracing = { version = "0.1.41" }
|
||||
tracing-subscriber = { version = "0.3.19" }
|
||||
uuid = { workspace = true }
|
||||
visions-core = { path = "../visions-core" }
|
||||
visions-core = { path = "../core" }
|
||||
visions-types = { path = "../types" }
|
||||
|
||||
[lib]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{future::IntoFuture, path::PathBuf, time::Duration};
|
||||
use std::{future::IntoFuture, time::Duration};
|
||||
|
||||
use axum::http::StatusCode;
|
||||
use axum_test::{TestResponse, TestServer, TestWebSocket};
|
||||
@@ -15,10 +15,10 @@ use visions_types::*;
|
||||
|
||||
pub const WINTER_SOLSTICE_ID: &str = "winter-solstice-id";
|
||||
pub const WINTER_SOLSTICE_TITLE: &str = "Circle of the Winter Solstice";
|
||||
pub const VAKARIAN_ID: &str = "vakarian-id";
|
||||
// pub const VAKARIAN_ID: &str = "vakarian-id";
|
||||
pub const VAKARIAN_USERNAME: &str = "vakarian@nowhere.com";
|
||||
pub const VAKARIAN_PASSWORD: &str = "aoeu";
|
||||
pub const TSONI_ID: &str = "tsoni-id";
|
||||
// pub const TSONI_ID: &str = "tsoni-id";
|
||||
pub const TSONI_USERNAME: &str = "tsoni@nowhere.com";
|
||||
pub const TSONI_PASSWORD: &str = "aoeu";
|
||||
pub const SILVER_ID: &str = "silver-id";
|
||||
@@ -27,9 +27,9 @@ pub const MISSING_LIBRARIANS_ID: &str = "missing-librarians-id";
|
||||
pub const MISSING_LIBRARIANS_TITLE: &str = "The Missing Librarians";
|
||||
pub const JOKER_USERNAME: &str = "joker@nowhere.com";
|
||||
pub const JOKER_PASSWORD: &str = "aoeu";
|
||||
pub const ALENKO_ID: &str = "alenko-id";
|
||||
pub const ALENKO_USERNAME: &str = "alenko@nowhere.com";
|
||||
pub const ALENKO_PASSWORD: &str = "aoeu";
|
||||
// pub const ALENKO_ID: &str = "alenko-id";
|
||||
// pub const ALENKO_USERNAME: &str = "alenko@nowhere.com";
|
||||
// pub const ALENKO_PASSWORD: &str = "aoeu";
|
||||
pub const TALI_USERNAME: &str = "tali@nowhere.com";
|
||||
pub const TALI_PASSWORD: &str = "aoeu";
|
||||
|
||||
@@ -66,6 +66,12 @@ impl TempDatabase {
|
||||
.expect("character initialization to succeed");
|
||||
}
|
||||
|
||||
for scene in scenes() {
|
||||
db.save_scene(scene)
|
||||
.expect("fatal error accessing the database")
|
||||
.expect("scene initialization to succeed");
|
||||
}
|
||||
|
||||
Ok(Ok(db))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user