feat: add the ability to resync props
This commit is contained in:
parent
8447fdef5d
commit
e57323ff3f
5 changed files with 180 additions and 36 deletions
|
|
@ -164,6 +164,99 @@ pub async fn create_server_prop<'e>(
|
|||
Ok(prop)
|
||||
}
|
||||
|
||||
/// Upsert a server prop (insert or update on slug conflict).
|
||||
///
|
||||
/// If a prop with the same slug already exists, it will be updated.
|
||||
/// Otherwise, a new prop will be created.
|
||||
pub async fn upsert_server_prop<'e>(
|
||||
executor: impl PgExecutor<'e>,
|
||||
req: &CreateServerPropRequest,
|
||||
asset_path: &str,
|
||||
created_by: Option<Uuid>,
|
||||
) -> Result<ServerProp, AppError> {
|
||||
let slug = req.slug_or_generate();
|
||||
|
||||
// Positioning: either content layer OR emotion layer OR neither (all NULL)
|
||||
// Database constraint enforces mutual exclusivity
|
||||
let (default_layer, default_emotion, default_position) =
|
||||
if req.default_layer.is_some() {
|
||||
// Content layer prop
|
||||
(
|
||||
req.default_layer.map(|l| l.to_string()),
|
||||
None,
|
||||
Some(req.default_position.unwrap_or(4)), // Default to center position
|
||||
)
|
||||
} else if req.default_emotion.is_some() {
|
||||
// Emotion layer prop
|
||||
(
|
||||
None,
|
||||
req.default_emotion.map(|e| e.to_string()),
|
||||
Some(req.default_position.unwrap_or(4)), // Default to center position
|
||||
)
|
||||
} else {
|
||||
// Non-avatar prop
|
||||
(None, None, None)
|
||||
};
|
||||
|
||||
let prop = sqlx::query_as::<_, ServerProp>(
|
||||
r#"
|
||||
INSERT INTO server.props (
|
||||
name, slug, description, tags, asset_path,
|
||||
default_layer, default_emotion, default_position,
|
||||
created_by
|
||||
)
|
||||
VALUES (
|
||||
$1, $2, $3, $4, $5,
|
||||
$6::props.avatar_layer, $7::props.emotion_state, $8,
|
||||
$9
|
||||
)
|
||||
ON CONFLICT (slug) DO UPDATE SET
|
||||
name = EXCLUDED.name,
|
||||
description = EXCLUDED.description,
|
||||
tags = EXCLUDED.tags,
|
||||
asset_path = EXCLUDED.asset_path,
|
||||
default_layer = EXCLUDED.default_layer,
|
||||
default_emotion = EXCLUDED.default_emotion,
|
||||
default_position = EXCLUDED.default_position,
|
||||
updated_at = now()
|
||||
RETURNING
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
description,
|
||||
tags,
|
||||
asset_path,
|
||||
thumbnail_path,
|
||||
default_layer,
|
||||
default_emotion,
|
||||
default_position,
|
||||
is_unique,
|
||||
is_transferable,
|
||||
is_portable,
|
||||
is_droppable,
|
||||
is_active,
|
||||
available_from,
|
||||
available_until,
|
||||
created_by,
|
||||
created_at,
|
||||
updated_at
|
||||
"#,
|
||||
)
|
||||
.bind(&req.name)
|
||||
.bind(&slug)
|
||||
.bind(&req.description)
|
||||
.bind(&req.tags)
|
||||
.bind(asset_path)
|
||||
.bind(&default_layer)
|
||||
.bind(&default_emotion)
|
||||
.bind(default_position)
|
||||
.bind(created_by)
|
||||
.fetch_one(executor)
|
||||
.await?;
|
||||
|
||||
Ok(prop)
|
||||
}
|
||||
|
||||
/// Delete a server prop.
|
||||
pub async fn delete_server_prop<'e>(
|
||||
executor: impl PgExecutor<'e>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue