- update: auth system to work with the website auth

This commit is contained in:
2025-03-16 01:35:44 -04:00
parent cbd71d1ab1
commit cf9efc9866
11 changed files with 93 additions and 219 deletions

View File

@@ -8,7 +8,7 @@ use utils::redis_cache::{Cache, RedisCache};
#[derive(Debug, FromRow, Serialize, Deserialize)]
pub struct Character {
pub id: i32,
pub user_id: i32,
pub user_id: String,
pub name: String,
pub money: i64,
pub inventory: serde_json::Value,
@@ -49,9 +49,9 @@ impl CharacterRepository {
// Fetch from database
let character = sqlx::query_as::<_, Character>(
"SELECT id, user_id, name, money, inventory, stats, skills, looks, position, \
created_at, updated_at, extract(epoch from (deleted_at - now()))::BIGINT as deleted_at, is_active \
FROM characters WHERE id = $1 AND is_active = true",
"SELECT id, userId as user_id, name, money, inventory, stats, skills, looks, position, \
createdAt as created_at, updatedAt as updated_at, extract(epoch from (deletedAt - now()))::BIGINT as deleted_at, isActive as is_active \
FROM character WHERE id = $1 AND isActive = true",
)
.bind(character_id)
.fetch_one(&self.pool)
@@ -69,7 +69,7 @@ impl CharacterRepository {
pub async fn create_character(
&self,
user_id: i32,
user_id: String,
name: &str,
inventory: serde_json::Value,
skills: serde_json::Value,
@@ -78,10 +78,10 @@ impl CharacterRepository {
position: serde_json::Value,
) -> Result<i32, sqlx::Error> {
let result = sqlx::query(
"INSERT INTO characters (user_id, name, inventory, stats, skills, looks, position, created_at, updated_at, is_active) \
"INSERT INTO character (userId, name, inventory, stats, skills, looks, position, createdAt, updatedAt, isActive) \
VALUES ($1, $2, $3, $4, $5, $6, $7, NOW(), NOW(), true) RETURNING id",
)
.bind(user_id)
.bind(&user_id)
.bind(name)
.bind(inventory)
.bind(stats)
@@ -107,9 +107,9 @@ impl CharacterRepository {
character_id: i32,
delete_type: i32,
) -> Result<i64, sqlx::Error> {
let mut query = "UPDATE characters SET updated_at = NOW(), deleted_at = NOW() + '24 hours' WHERE id = $1 RETURNING user_id, extract(epoch from (deleted_at - now()))::BIGINT as deleted_at";
let mut query = "UPDATE character SET updatedAt = NOW(), deletedAt = NOW() + '24 hours' WHERE id = $1 RETURNING userId, extract(epoch from (deletedAt - now()))::BIGINT as deletedAt";
if 0 == delete_type {
query = "UPDATE characters SET updated_at = NOW(), deleted_at = null WHERE id = $1 RETURNING user_id, 0::BIGINT as deleted_at";
query = "UPDATE character SET updatedAt = NOW(), deletedAt = null WHERE id = $1 RETURNING userId, 0::BIGINT as deletedAt";
}
let result = sqlx::query(query)
.bind(character_id)
@@ -154,7 +154,7 @@ impl CharacterRepository {
// Fetch from database
let characters = sqlx::query_as::<_, Character>(
"SELECT id, user_id, name, money, inventory, stats, skills, looks, position, created_at, updated_at, extract(epoch from (deleted_at - now()))::BIGINT as deleted_at, is_active FROM characters WHERE user_id = $1 AND is_active = true",
"SELECT id, userId as user_id, name, money, inventory, stats, skills, looks, position, createdAt as created_at, updatedAt as updated_at, extract(epoch from (deletedAt - now()))::BIGINT as deleted_at, isActive as is_active FROM character WHERE userId = $1 AND isActive = true",
)
.bind(user_id)
.fetch_all(&self.pool)