Skip to content

This pull request refactors the product seeding and retrieval logic in the API to support a more flexible, CSV-driven schema for the product table.#21

Merged
goldlabelapps merged 3 commits intomasterfrom
staging
Mar 23, 2026
Merged

This pull request refactors the product seeding and retrieval logic in the API to support a more flexible, CSV-driven schema for the product table.#21
goldlabelapps merged 3 commits intomasterfrom
staging

Conversation

@goldlabelapps
Copy link
Copy Markdown
Owner

It removes the old reset endpoint and introduces a new /products/seed endpoint that initializes the database from a CSV file. The product retrieval logic is updated to use the new schema, and the API routing is updated accordingly. Additionally, some obsolete tests are removed.

Product API refactor and CSV-based seeding:

  • Added a new seed.py module with a /products/seed endpoint that drops, recreates, and seeds the product table using all columns from a CSV file, supporting a more complex schema. (app/api/products/seed.py)
  • Updated the product retrieval endpoint in products.py to fetch all columns from the new schema and return results as dictionaries keyed by column name. (app/api/products/products.py)
  • Removed the old reset.py module and its endpoint, which previously handled table reset and basic seeding. (app/api/products/reset.py)

API routing updates:

  • Changed API router imports and route inclusion to use the new seed_router instead of the removed reset_router, ensuring the new seeding logic is active. (app/api/products/__init__.py, app/api/routes.py) [1] [2]

Test cleanup:

  • Removed obsolete echo endpoint tests from the test suite. (tests/test_routes.py)

Replace direct psycopg2/dotenv usage with the shared get_db_connection helper; product listing now SELECTs * and builds dicts from cursor.description to return the full CSV-derived schema. The reset endpoint now recreates a product table matching the CSV columns and seeds rows from tests/csv/small.csv using csv.DictReader with parameterized INSERTs. Updated docstrings and response messages accordingly and removed the previous hardcoded sample seed data.
Rename products/reset.py to products/seed.py and update API to seed the product table from an in-package CSV. Change endpoint from POST /products/reset to GET /products/seed, move CSV to app/api/products/start_data.csv and resolve its absolute path. Map CSV 'desc' field to DB 'title' on insert, update SQL to use title, and guard against empty query results (handle cur.description None). Update imports and router includes to use products_router/seed_router names. Remove legacy product-list root logic and clean up tests by deleting obsolete echo tests.
@goldlabelapps goldlabelapps self-assigned this Mar 23, 2026
@goldlabelapps goldlabelapps merged commit 7cb2006 into master Mar 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant