Skip to content

Feat/painreportlist endpoint - #315

Merged
littlecoffe8 merged 4 commits into
mainfrom
feat/painreportlist-endpoint
May 15, 2026
Merged

Feat/painreportlist endpoint#315
littlecoffe8 merged 4 commits into
mainfrom
feat/painreportlist-endpoint

Conversation

@littlecoffe8

Copy link
Copy Markdown
Collaborator

Description

Add a new batch knowledge panel endpoint supporting one or multiple barcodes in a single request.

The new route:

GET /off/v1/knowledge-panel/?code=123,456

accepts comma-separated barcodes and returns a response indexed by barcode, with:

  • panels for successful results
  • errors for per-barcode failures

The existing single-product endpoint:

/off/v1/knowledge-panel/{barcode}

is preserved for backward compatibility.

The implementation follows the API format discussed in the October GitHub mobile/Dart discussion:

  • singular /knowledge-panel/ route
  • code query parameter
  • comma-separated barcode format

lang handling is unchanged and still managed through the existing middleware.

country query parameters are currently ignored server-side (FastAPI ignores undeclared params), so there is no impact on the suffering calculation logic at the moment.


Code changes

  • Added batch endpoint:

    GET /off/v1/knowledge-panel/?code=123,456
    
  • Added parallel processing using asyncio

  • Added batch response format:

    {
      "panels": {
        "123": {...}
      },
      "errors": {
        "456": {...}
      }
    }
  • Preserved existing single-barcode endpoint

  • Added unit tests covering:

    • single barcode batch requests
    • multiple barcode batch requests
    • partial failures
    • cache reuse behavior
  • Refactored OFF HTTP calls to reuse a shared httpx.AsyncClient
    instead of creating a new client per request

  • Added retry handling for transient OFF API failures (429, network issues, etc.)


How to test

You can test either through the OFF app or directly with curl.

Existing endpoint regression test

curl "http://127.0.0.1:8000/off/v1/knowledge-panel/3017620422003?lang=fr"

New batch endpoint with a single barcode

curl "http://127.0.0.1:8000/off/v1/knowledge-panel/?code=3017620422003&lang=fr"

New batch endpoint with multiple barcodes

curl "http://127.0.0.1:8000/off/v1/knowledge-panel/?code=3017620422003,3228857000166&lang=fr"

Batch endpoint with mixed success/failure cases

curl "http://127.0.0.1:8000/off/v1/knowledge-panel/?code=3017620422003,3450970045360&lang=fr"

@littlecoffe8
littlecoffe8 merged commit fadf606 into main May 15, 2026
2 of 3 checks passed
@littlecoffe8
littlecoffe8 deleted the feat/painreportlist-endpoint branch May 15, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants