Skip to content

Issue #3 — Workspace Management (Admin-Only) #600

@yusuftomilola

Description

@yusuftomilola

Background

Admins need to register workspaces and manage their availability and pricing. This issue implements the three workspace-management write functions and the two workspace query functions.

Task

Building on Issue #2, add the following public functions:

  1. pub fn register_workspace(env, caller, id, name, workspace_type, capacity, hourly_rate) -> Result<(), Error>

    • Call Self::require_admin(&env, &caller)?.
    • Return Error::InvalidCapacity if capacity == 0.
    • Return Error::InvalidRate if hourly_rate <= 0.
    • Return Error::WorkspaceAlreadyExists if DataKey::Workspace(id.clone()) exists in persistent storage.
    • Build a Workspace struct with is_available: true and created_at: env.ledger().timestamp().
    • Save to DataKey::Workspace(id.clone()) in persistent storage.
    • Append id to the WorkspaceList in instance storage.
    • Emit event: topic (symbol_short!("ws_reg"), id), data (name, workspace_type, capacity, hourly_rate).
  2. pub fn set_workspace_availability(env, caller, workspace_id, is_available) -> Result<(), Error>

    • Require admin. Load workspace, return Error::WorkspaceNotFound if missing.
    • Toggle workspace.is_available, save back.
    • Emit event: topic (symbol_short!("ws_avail"), workspace_id), data (is_available,).
  3. pub fn set_workspace_rate(env, caller, workspace_id, hourly_rate) -> Result<(), Error>

    • Require admin. Return Error::InvalidRate if hourly_rate <= 0.
    • Load workspace, return Error::WorkspaceNotFound if missing.
    • Update workspace.hourly_rate, save back.
    • Emit event: topic (symbol_short!("ws_rate"), workspace_id), data (hourly_rate,).
  4. pub fn get_workspace(env: Env, workspace_id: String) -> Result<Workspace, Error>

    • Read DataKey::Workspace(workspace_id) from persistent storage, return Error::WorkspaceNotFound if absent.
  5. pub fn get_all_workspaces(env: Env) -> Vec<String>

    • Read DataKey::WorkspaceList from instance storage, return an empty Vec if absent.

Files to modify

  • contracts/workspace_booking/src/lib.rs

Acceptance criteria

  • cargo check -p workspace_booking and cargo clippy -p workspace_booking -- -D warnings pass.
  • Non-admin callers are rejected with Error(Contract, #2) (Unauthorized).
  • Registering a duplicate workspace ID returns Error(Contract, #7) (WorkspaceAlreadyExists).
  • capacity == 0 returns Error(Contract, #9) (InvalidCapacity).
  • hourly_rate <= 0 returns Error(Contract, #10) (InvalidRate).
  • get_workspace returns the correct struct after registration.
  • get_all_workspaces returns IDs in registration order.
  • Rate change via set_workspace_rate is reflected in the stored workspace.

Technical notes

  • WorkspaceList lives in instance storage (contract-wide index); workspace records live in persistent storage.
  • Rate changes apply only to future bookings — existing bookings already recorded amount_paid.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions