HSLG Media

WordPressOrderDraftRepository.php

WordPressOrderDraftRepository.php

Source file: wordpress/hslg-app-api/src/database/WordPressOrderDraftRepository.php

Module: wordpress-hslg-app-api

Size: 84 lines

SHA-256: b1e714caef3b05d65d015e6fa595100e450c2e66ceb6ecfb72484e9c9ad04eba

Responsibility

Hosts independently deployable HSLG-owned API endpoints and schema operations on WordPress/MariaDB.

Declared entry points

  • WordPressOrderDraftRepository — source line 11.
  • __construct — source line 13.
  • row — source line 14.
  • create — source line 20.
  • findByKey — source line 60.
  • find — source line 67.
  • present — source line 74.

Imports and dependencies

  • Line 4: use Hslg\Backend\Database\TableNames;

Behaviour and audit locations

  • Line 23: throw new \InvalidArgumentException('Persist a UUIDv4 idempotency key locally before submitting.');
  • Line 49: $written=$this->db->query($this->db->prepare('INSERT INTO %i (order_id,customer_id,venue_id,table_number,idempotency_key,request_hash,basket_json) VALUES (%s,%s,%s,%d,%s,
  • Line 52: $existing=$this->row($this->db->prepare('SELECT order_id,customer_id,venue_id,table_number,idempotency_key,request_hash,basket_json,state,created_at FROM %i WHERE custome
  • Line 56: throw new \UnexpectedValueException('Idempotency key conflict.');
  • Line 63: $row=$this->row($this->db->prepare('SELECT order_id,customer_id,venue_id,table_number,idempotency_key,request_hash,basket_json,state,created_at FROM %i WHERE customer_id
  • Line 70: $row=$this->row($this->db->prepare('SELECT order_id,customer_id,venue_id,table_number,idempotency_key,request_hash,basket_json,state,created_at FROM %i WHERE order_id = %

Draft idempotency and ownership

The repository stores draft requests associated with authenticated customer, venue and table, keyed by a stable idempotency value. Reuse of the same key with differing contents is a conflict rather than permission to overwrite a previous order. The stored state is a draft only: not priced, authorized, accepted by a kitchen or paid. Before retries after uncertain network outcomes, the client should read by that same key and reconcile. Test against MariaDB for uniqueness under concurrent requests.

Relationship to the system

This page is the file-level source reference, not the architecture rationale. Read the module explanation, the corresponding architecture decision and user guide before changing behaviour. Names and line locations above are extracted from this exact source version; they are reference points, not proof that an external service or a phone feature works.

Change verification

Review the entry points and errors in this file, then run the module’s associated tests, source dependency gate, history gate and documentation coverage check. If the file changes an API response, user interaction, data model, deployment or third-party dependency, revise those human explanations and disaster recovery/licensing when relevant. Do not infer actual native or external API operation from source presence.