Skip to content

[Price Compare] Step 12: Price check API endpoint #83

@frankieboxx

Description

@frankieboxx

Step 12 — Price Check API Endpoint

Add a REST API endpoint to cijene-api that accepts a product code (sifra) and chain name, and returns current prices across Dubrovnik stores.

Endpoint:

GET /api/v1/price-check?code={sifra}&chain={chain_code}

Parameters:

Param Type Required Description
code string yes Product code (Metro sifra, Konzum code, etc.)
chain string no Chain filter: metro, konzum, tommy, etc. If omitted, search all chains
city string no City filter (default: Dubrovnik)

Response:

{
  "query": { "code": "224155", "chain": null, "city": "Dubrovnik" },
  "product": {
    "name": "180G ARO TEK.JOGURT 2,8%",
    "code": "224155",
    "category": "Mliječni proizvodi"
  },
  "prices": [
    {
      "chain": "metro",
      "store": "Metro Dubrovnik",
      "price": 0.30,
      "unit_price": 1.67,
      "unit": "€/kg",
      "date": "2026-03-01",
      "quantity": "180 G"
    }
  ],
  "cheapest": {
    "chain": "metro",
    "unit_price": 1.67,
    "savings_vs_most_expensive": "33.2%"
  }
}

Implementation:

  • Add to service/routers/v1.py (or new service/routers/price_check.py)
  • Reuse existing db connection from settings.get_db()
  • SQL: lookup chain_products.code → join prices → filter by store city/chain
  • Requires auth (existing RequireAuth dependency)
  • Also support fuzzy name search: GET /api/v1/price-check?name=jogurt&chain=metro

Use cases:

  • Atrium ERP integration — when creating purchase order, check real-time prices
  • Manual spot-check from terminal
  • Future: Atrium UI "check alternatives" button

Files: service/routers/v1.py or service/routers/price_check.py
Priority: P2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions