Skip to content

API Reference parrot_formdesigner.services.venue_service

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.services.venue_service

View source

VenueService — CRUD sobre fieldsync.sites / fieldsync.locations.

Implementa la sub-estructura de tienda de FieldSync (FEAT-330): Store → Site → Location. Store es geografía read-only (networkninja.*, propiedad de FEAT-302); Site y Location son entidades propiedad de FieldSync.

  • Una Site agrupa uno o más Location dentro de un Store (p. ej. una zona de vending).
  • Una Location es un kiosk o cualquier punto/spot dentro de la tienda. Lleva los parámetros de geofence (latitude / longitude / geofence_radius_m) — el system of record del geofence per-location (movido fuera de Event.meta; ver FEAT-303 §8 y FEAT-318 D5.7). Un geofence_radius_m = NULL significa geofence deshabilitado en ese punto.

Diseño (idéntico a ProjectService — FEAT-302):

  • Pool inyectado en el constructor → testable sin DB real.
  • SQL 100% parametrizado ($1, $2…); nombres de tabla fijados en constantes.
  • Hard tenant isolation: todo query filtra org_id explícitamente.
  • Pydantic v2 para modelos de datos.

Uso::

svc = VenueService(pool)
site = await svc.create_site(
    store_id="store-501", client_id=42, org_id=7,
    name="Pokémon Vending Zone", tenant="acme",
)
loc = await svc.create_location(
    site_id=site.site_id, client_id=42, org_id=7, name="Kiosk A-12",
    location_type="kiosk", latitude=34.0522, longitude=-118.2437,
    geofence_radius_m=50, tenant="acme",
)

Class DuplicateVenueError

Raised when a UNIQUE constraint on a site/location is violated.

Parameter Type Default Description
kind str
name str

Attributes:

Attribute Type Description
kind "site" or "location".
name The duplicate name.

Class Location

A concrete work point inside a Site — a kiosk or any spot in the store.

Carries the geofence parameters used to validate a Visit/Assignment check-in. A geofence_radius_m of None means geofence is disabled for this location.

Fields:

Field Type Default Description
location_id int Auto-incremented serial PK.
site_id int FK to fieldsync.sites.
client_id int Client this location belongs to.
org_id int Organization identifier (hard-isolation key).
name str Human-readable location name.
location_type str 'kiosk' One of kiosk | endcap | gondola | backroom | other (free-form; default "kiosk").
latitude float | None None Geofence center latitude (optional).
longitude float | None None Geofence center longitude (optional).
geofence_radius_m int | None None Geofence radius in metres; None ⇒ disabled.
is_active bool True Whether the location is currently active.
tenant str | None None Tenant slug (metadata, not stored in the table directly).

Class LocationNotFoundError

Raised when a location lookup returns no row.

Parameter Type Default Description
location_id int

Attributes:

Attribute Type Description
location_id The missing location identifier.

Class Site

An intermediate work-area grouping inside a Store.

A Store may contain multiple Sites; a Site groups one or more Locations. Owned by FieldSync (fieldsync.sites); tenant-isolated by org_id.

Fields:

Field Type Default Description
site_id int Auto-incremented serial PK.
store_id str Identifier of the parent store (networkninja geography). Kept as str for parity with OrgNode.node_id.
client_id int Client this site belongs to.
org_id int Organization identifier (hard-isolation key).
name str Human-readable site name.
is_active bool True Whether the site is currently active.
tenant str | None None Tenant slug (metadata, not stored in the table directly).

Class SiteNotFoundError

Raised when a site lookup returns no row.

Parameter Type Default Description
site_id int

Attributes:

Attribute Type Description
site_id The missing site identifier.

Class VenueService

CRUD service for fieldsync.sites and fieldsync.locations.

Example::

svc = VenueService(pool)
site = await svc.create_site(
    store_id="store-501", client_id=42, org_id=7,
    name="Vending Zone", tenant="acme",
)
Parameter Type Default Description
pool Any asyncpg pool (or fake pool for tests).

Method VenueService.create_site

Create a new site under a store.

create_site(*, store_id: str, client_id: int, org_id: int, name: str, tenant: str | None = None) -> Site

Parameter Type Default Description
store_id str Parent store identifier (networkninja geography).
client_id int Client this site belongs to.
org_id int Organization identifier (hard-isolation key).
name str Site name (UNIQUE per (store_id, client_id)).
tenant str | None None Tenant slug (stored in the returned model only).

Returns: Site — The newly created Site with its DB-assigned site_id.

Raises:

  • DuplicateVenueError — If (store_id, client_id, name) exists.

Method VenueService.get_site

Retrieve a site by PK, scoped to org_id (hard isolation).

get_site(site_id: int, *, org_id: int, tenant: str | None = None) -> Site

Parameter Type Default Description
site_id int Primary key of the site.
org_id int Organization the caller is scoped to.
tenant str | None None Optional tenant slug (stored in returned model).

Returns: Site — Site populated from the DB row.

Raises:

  • SiteNotFoundError — If no site with site_id exists in org_id.

Method VenueService.list_sites

List sites under a store within org_id (hard isolation).

list_sites(*, store_id: str, org_id: int, tenant: str | None = None) -> list[Site]

Parameter Type Default Description
store_id str Parent store identifier.
org_id int Organization the caller is scoped to (REQUIRED — every query is filtered by it; there is no cross-tenant path).
tenant str | None None Tenant slug stored in returned models.

Returns: list[Site] — List of Site instances (empty if none match).

Method VenueService.create_location

Create a new location under a site.

create_location(*, site_id: int, client_id: int, org_id: int, name: str, location_type: str = 'kiosk', latitude: float | None = None, longitude: float | None = None, geofence_radius_m: int | None = None, tenant: str | None = None) -> Location

Parameter Type Default Description
site_id int FK to fieldsync.sites.
client_id int Client this location belongs to.
org_id int Organization identifier (hard-isolation key).
name str Location name (UNIQUE per site_id).
location_type str 'kiosk' Kind of location (default "kiosk").
latitude float | None None Geofence center latitude (optional).
longitude float | None None Geofence center longitude (optional).
geofence_radius_m int | None None Geofence radius in metres; None ⇒ disabled.
tenant str | None None Tenant slug (stored in the returned model only).

Returns: Location — The newly created Location with its DB-assigned location_id.

Raises:

  • DuplicateVenueError — If (site_id, name) already exists.

Method VenueService.get_location

Retrieve a location by PK, scoped to org_id (hard isolation).

get_location(location_id: int, *, org_id: int, tenant: str | None = None) -> Location

Parameter Type Default Description
location_id int Primary key of the location.
org_id int Organization the caller is scoped to.
tenant str | None None Optional tenant slug (stored in returned model).

Returns: Location — Location populated from the DB row (includes geofence params).

Raises:

  • LocationNotFoundError — If no location with location_id exists within org_id.

Method VenueService.list_locations

List locations under a site within org_id (hard isolation).

list_locations(*, site_id: int, org_id: int, tenant: str | None = None) -> list[Location]

Parameter Type Default Description
site_id int Parent site identifier.
org_id int Organization the caller is scoped to (REQUIRED).
tenant str | None None Tenant slug stored in returned models.

Returns: list[Location] — List of Location instances (empty if none match).

Alias is_unique_violation

Re-exported from parrot_formdesigner.services._db_utils.is_unique_violation.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally