added server and realm tabs to inventory screen
This commit is contained in:
parent
ee425e224e
commit
acab2f017d
12 changed files with 647 additions and 151 deletions
|
|
@ -3,7 +3,7 @@
|
|||
use sqlx::PgExecutor;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::models::InventoryItem;
|
||||
use crate::models::{InventoryItem, PublicProp};
|
||||
use chattyness_error::AppError;
|
||||
|
||||
/// List all inventory items for a user.
|
||||
|
|
@ -91,3 +91,67 @@ pub async fn drop_inventory_item<'e>(
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// List all public server props.
|
||||
///
|
||||
/// Returns props that are:
|
||||
/// - Active (`is_active = true`)
|
||||
/// - Public (`is_public = true`)
|
||||
/// - Currently available (within availability window if set)
|
||||
pub async fn list_public_server_props<'e>(
|
||||
executor: impl PgExecutor<'e>,
|
||||
) -> Result<Vec<PublicProp>, AppError> {
|
||||
let props = sqlx::query_as::<_, PublicProp>(
|
||||
r#"
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
asset_path,
|
||||
description
|
||||
FROM server.props
|
||||
WHERE is_active = true
|
||||
AND is_public = true
|
||||
AND (available_from IS NULL OR available_from <= now())
|
||||
AND (available_until IS NULL OR available_until > now())
|
||||
ORDER BY name ASC
|
||||
"#,
|
||||
)
|
||||
.fetch_all(executor)
|
||||
.await?;
|
||||
|
||||
Ok(props)
|
||||
}
|
||||
|
||||
/// List all public realm props for a specific realm.
|
||||
///
|
||||
/// Returns props that are:
|
||||
/// - In the specified realm
|
||||
/// - Active (`is_active = true`)
|
||||
/// - Public (`is_public = true`)
|
||||
/// - Currently available (within availability window if set)
|
||||
pub async fn list_public_realm_props<'e>(
|
||||
executor: impl PgExecutor<'e>,
|
||||
realm_id: Uuid,
|
||||
) -> Result<Vec<PublicProp>, AppError> {
|
||||
let props = sqlx::query_as::<_, PublicProp>(
|
||||
r#"
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
asset_path,
|
||||
description
|
||||
FROM realm.props
|
||||
WHERE realm_id = $1
|
||||
AND is_active = true
|
||||
AND is_public = true
|
||||
AND (available_from IS NULL OR available_from <= now())
|
||||
AND (available_until IS NULL OR available_until > now())
|
||||
ORDER BY name ASC
|
||||
"#,
|
||||
)
|
||||
.bind(realm_id)
|
||||
.fetch_all(executor)
|
||||
.await?;
|
||||
|
||||
Ok(props)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue