feat: UserInteraction table
This commit is contained in:
@@ -13,9 +13,9 @@ pub mod components {
|
||||
|
||||
pub mod button;
|
||||
pub mod header;
|
||||
pub mod icons;
|
||||
pub mod problem;
|
||||
pub mod problem_info;
|
||||
pub mod icons;
|
||||
}
|
||||
|
||||
pub mod resources {
|
||||
|
||||
@@ -15,6 +15,43 @@ pub use v2::Wall;
|
||||
pub use v2::WallDimensions;
|
||||
pub use v2::WallUid;
|
||||
|
||||
pub mod v3 {
|
||||
use super::v2;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
/// Registers user interaction with a problem
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct UserInteraction {
|
||||
pub wall_uid: v2::WallUid,
|
||||
pub problem_uid: v2::ProblemUid,
|
||||
|
||||
/// Climbed problem
|
||||
pub is_completed: bool,
|
||||
|
||||
/// Flashed problem
|
||||
pub is_flashed: bool,
|
||||
|
||||
/// Is among favorite problems
|
||||
pub is_favorite: bool,
|
||||
|
||||
/// Added to personal challenges
|
||||
pub is_challenge: bool,
|
||||
}
|
||||
impl UserInteraction {
|
||||
pub fn new(wall_uid: v2::WallUid, problem_uid: v2::ProblemUid) -> Self {
|
||||
Self {
|
||||
wall_uid,
|
||||
problem_uid,
|
||||
is_completed: false,
|
||||
is_flashed: false,
|
||||
is_favorite: false,
|
||||
is_challenge: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod v2 {
|
||||
use super::v1;
|
||||
use derive_more::Display;
|
||||
|
||||
@@ -23,8 +23,8 @@ pub fn Settings() -> impl IntoView {
|
||||
<div class="min-w-screen min-h-screen bg-neutral-950">
|
||||
<StyledHeader items=header_items />
|
||||
|
||||
<div class="container mx-auto mt-2">// {move || view! { <Import wall_uid=wall_uid.get() /> }}
|
||||
</div>
|
||||
// {move || view! { <Import wall_uid=wall_uid.get() /> }}
|
||||
<div class="container mx-auto mt-2"></div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::codec::ron::RonEncoded;
|
||||
use crate::components::icons;
|
||||
use crate::components::ProblemInfo;
|
||||
use crate::components::button::Button;
|
||||
use crate::components::header::HeaderItem;
|
||||
use crate::components::header::HeaderItems;
|
||||
use crate::components::header::StyledHeader;
|
||||
use crate::components::icons;
|
||||
use crate::models;
|
||||
use crate::models::HoldRole;
|
||||
use leptos::Params;
|
||||
|
||||
@@ -86,6 +86,7 @@ impl Version {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement test
|
||||
#[tracing::instrument(skip_all, err)]
|
||||
pub async fn init_at_current_version(db: &Database) -> Result<(), DatabaseOperationError> {
|
||||
db.write(|txn| {
|
||||
@@ -116,6 +117,13 @@ pub async fn init_at_current_version(db: &Database) -> Result<(), DatabaseOperat
|
||||
let table = txn.open_table(current::TABLE_PROBLEMS)?;
|
||||
assert!(table.is_empty()?);
|
||||
}
|
||||
|
||||
// User table
|
||||
{
|
||||
// Opening the table creates the table
|
||||
let table = txn.open_table(current::TABLE_USER)?;
|
||||
assert!(table.is_empty()?);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -126,7 +134,26 @@ pub async fn init_at_current_version(db: &Database) -> Result<(), DatabaseOperat
|
||||
}
|
||||
|
||||
use crate::models;
|
||||
pub use v2 as current;
|
||||
pub mod current {
|
||||
use super::v2;
|
||||
use super::v3;
|
||||
pub use v2::TABLE_PROBLEMS;
|
||||
pub use v2::TABLE_ROOT;
|
||||
pub use v2::TABLE_WALLS;
|
||||
pub use v3::TABLE_USER;
|
||||
pub use v3::VERSION;
|
||||
}
|
||||
|
||||
pub mod v3 {
|
||||
use crate::models;
|
||||
use crate::server::db::bincode::Bincode;
|
||||
use redb::TableDefinition;
|
||||
|
||||
pub const VERSION: u64 = 3;
|
||||
|
||||
pub const TABLE_USER: TableDefinition<Bincode<(models::v2::WallUid, models::v2::ProblemUid)>, Bincode<models::v3::UserInteraction>> =
|
||||
TableDefinition::new("user");
|
||||
}
|
||||
|
||||
pub mod v2 {
|
||||
use crate::models;
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
use super::db;
|
||||
use super::db::Database;
|
||||
|
||||
#[tracing::instrument(skip_all, err)]
|
||||
pub async fn run_migrations(_db: &Database) -> Result<(), Box<dyn std::error::Error>> {
|
||||
pub async fn run_migrations(db: &Database) -> Result<(), Box<dyn std::error::Error>> {
|
||||
v3(db).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, err)]
|
||||
pub async fn v3(db: &Database) -> Result<(), Box<dyn std::error::Error>> {
|
||||
use redb::ReadableTableMetadata;
|
||||
tracing::warn!("MIGRATING TO VERSION 3");
|
||||
db.write(|txn| {
|
||||
// Opening the table creates the table
|
||||
let table = txn.open_table(db::current::TABLE_USER)?;
|
||||
assert!(table.is_empty()?);
|
||||
Ok(())
|
||||
})
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user