support aquiring server props and test dropping them

This commit is contained in:
Evan Carroll 2026-01-20 18:33:15 -06:00
parent 3e1afb82c8
commit 7852790a1e
9 changed files with 858 additions and 150 deletions

View file

@ -8,6 +8,30 @@ use uuid::Uuid;
use crate::models::{InventoryItem, LooseProp};
use chattyness_error::AppError;
/// Ensure an instance exists for a scene.
///
/// In this system, scenes are used directly as instances (channel_id = scene_id).
/// This creates an instance record if one doesn't exist, using the scene_id as the instance_id.
/// This is needed for loose_props foreign key constraint.
pub async fn ensure_scene_instance<'e>(
executor: impl PgExecutor<'e>,
scene_id: Uuid,
) -> Result<(), AppError> {
sqlx::query(
r#"
INSERT INTO scene.instances (id, scene_id, instance_type)
SELECT $1, $1, 'public'::scene.instance_type
WHERE EXISTS (SELECT 1 FROM realm.scenes WHERE id = $1)
ON CONFLICT (id) DO NOTHING
"#,
)
.bind(scene_id)
.execute(executor)
.await?;
Ok(())
}
/// List all loose props in a channel (excluding expired).
pub async fn list_channel_loose_props<'e>(
executor: impl PgExecutor<'e>,
@ -106,8 +130,8 @@ pub async fn drop_prop_to_canvas<'e>(
instance_id as channel_id,
server_prop_id,
realm_prop_id,
ST_X(position) as position_x,
ST_Y(position) as position_y,
ST_X(position)::real as position_x,
ST_Y(position)::real as position_y,
dropped_by,
expires_at,
created_at