avatar fixes and implementation to edit
This commit is contained in:
parent
acab2f017d
commit
c3320ddcce
11 changed files with 1417 additions and 37 deletions
|
|
@ -1,13 +1,13 @@
|
|||
//! Avatar API handlers for user UI.
|
||||
//!
|
||||
//! Handles avatar data retrieval.
|
||||
//! Handles avatar data retrieval and slot updates.
|
||||
//! Note: Emotion switching is handled via WebSocket.
|
||||
|
||||
use axum::extract::Path;
|
||||
use axum::Json;
|
||||
|
||||
use chattyness_db::{
|
||||
models::AvatarWithPaths,
|
||||
models::{AssignSlotRequest, AvatarWithPaths, ClearSlotRequest},
|
||||
queries::{avatars, realms},
|
||||
};
|
||||
use chattyness_error::AppError;
|
||||
|
|
@ -40,3 +40,76 @@ pub async fn get_avatar(
|
|||
|
||||
Ok(Json(avatar))
|
||||
}
|
||||
|
||||
/// Assign an inventory item to an avatar slot.
|
||||
///
|
||||
/// PUT /api/realms/{slug}/avatar/slot
|
||||
///
|
||||
/// Assigns the specified inventory item to the given layer and position
|
||||
/// in the user's active avatar.
|
||||
pub async fn assign_slot(
|
||||
rls_conn: RlsConn,
|
||||
AuthUser(user): AuthUser,
|
||||
Path(slug): Path<String>,
|
||||
Json(req): Json<AssignSlotRequest>,
|
||||
) -> Result<Json<AvatarWithPaths>, AppError> {
|
||||
req.validate()?;
|
||||
|
||||
let mut conn = rls_conn.acquire().await;
|
||||
|
||||
// Get realm
|
||||
let realm = realms::get_realm_by_slug(&mut *conn, &slug)
|
||||
.await?
|
||||
.ok_or_else(|| AppError::NotFound(format!("Realm '{}' not found", slug)))?;
|
||||
|
||||
// Update the slot
|
||||
let column_name = req.column_name();
|
||||
avatars::update_avatar_slot(
|
||||
&mut *conn,
|
||||
user.id,
|
||||
realm.id,
|
||||
&column_name,
|
||||
Some(req.inventory_item_id),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Return updated avatar
|
||||
let avatar = avatars::get_avatar_with_paths_conn(&mut *conn, user.id, realm.id)
|
||||
.await?
|
||||
.unwrap_or_default();
|
||||
|
||||
Ok(Json(avatar))
|
||||
}
|
||||
|
||||
/// Clear an avatar slot.
|
||||
///
|
||||
/// DELETE /api/realms/{slug}/avatar/slot
|
||||
///
|
||||
/// Removes any inventory item from the given layer and position
|
||||
/// in the user's active avatar.
|
||||
pub async fn clear_slot(
|
||||
rls_conn: RlsConn,
|
||||
AuthUser(user): AuthUser,
|
||||
Path(slug): Path<String>,
|
||||
Json(req): Json<ClearSlotRequest>,
|
||||
) -> Result<Json<AvatarWithPaths>, AppError> {
|
||||
req.validate()?;
|
||||
|
||||
let mut conn = rls_conn.acquire().await;
|
||||
|
||||
// Get realm
|
||||
let realm = realms::get_realm_by_slug(&mut *conn, &slug)
|
||||
.await?
|
||||
.ok_or_else(|| AppError::NotFound(format!("Realm '{}' not found", slug)))?;
|
||||
|
||||
// Clear the slot
|
||||
let column_name = req.column_name();
|
||||
avatars::update_avatar_slot(&mut *conn, user.id, realm.id, &column_name, None).await?;
|
||||
|
||||
// Return updated avatar
|
||||
let avatar = avatars::get_avatar_with_paths_conn(&mut *conn, user.id, realm.id)
|
||||
.await?
|
||||
.unwrap_or_default();
|
||||
|
||||
Ok(Json(avatar))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue