- add: money is now sent with the character data sent to the client

This commit is contained in:
2025-03-09 13:53:26 -04:00
parent 8ba8fce20b
commit dfd98e96d2
7 changed files with 52 additions and 43 deletions

View File

@@ -10,6 +10,7 @@ pub struct Character {
pub id: i32,
pub user_id: i32,
pub name: String,
pub money: i64,
pub inventory: serde_json::Value,
pub stats: serde_json::Value,
pub skills: serde_json::Value,
@@ -48,7 +49,7 @@ impl CharacterRepository {
// Fetch from database
let character = sqlx::query_as::<_, Character>(
"SELECT id, user_id, name, inventory, stats, skills, looks, position, \
"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",
)
@@ -77,11 +78,12 @@ impl CharacterRepository {
) -> Result<i32, sqlx::Error> {
let default_skills = "[{\"id\": 11, \"level\": 1}, {\"id\": 12, \"level\": 1}, {\"id\": 16, \"level\": 1}, {\"id\": 19, \"level\": 1}, {\"id\": 20, \"level\": 1}, {\"id\": 21, \"level\": 1}, {\"id\": 26, \"level\": 1}, {\"id\": 41, \"level\": 1}, {\"id\": 42, \"level\": 1}, {\"id\": 43, \"level\": 1}, {\"id\": 46, \"level\": 1}, {\"id\": 47, \"level\": 1}, {\"id\": 48, \"level\": 1}, {\"id\": 49, \"level\": 1}, {\"id\": 50, \"level\": 1}]";
let result = sqlx::query(
"INSERT INTO characters (user_id, name, inventory, stats, skills, looks, position, created_at, updated_at, is_active) \
VALUES ($1, $2, $3, $4, $5, $6, $7, NOW(), NOW(), true) RETURNING id",
"INSERT INTO characters (user_id, name, money, inventory, stats, skills, looks, position, created_at, updated_at, is_active) \
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, NOW(), NOW(), true) RETURNING id",
)
.bind(user_id)
.bind(name)
.bind(0)
.bind(inventory)
.bind(stats)
.bind(default_skills)
@@ -153,7 +155,7 @@ impl CharacterRepository {
// Fetch from database
let characters = sqlx::query_as::<_, Character>(
"SELECT id, user_id, name, 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, 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",
)
.bind(user_id)
.fetch_all(&self.pool)

View File

@@ -30,6 +30,7 @@ impl CharacterDbService for MyDatabaseService {
id: character.id,
user_id: character.user_id,
name: character.name,
money: character.money,
inventory: character.inventory.to_string(),
stats: character.stats.to_string(),
skills: character.skills.to_string(),
@@ -67,6 +68,7 @@ impl CharacterDbService for MyDatabaseService {
id: character.id,
user_id: character.user_id,
name: character.name,
money: character.money,
inventory: character.inventory.to_string(),
stats: character.stats.to_string(),
skills: character.skills.to_string(),