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 Mar 23, 2026
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It removes the old reset endpoint and introduces a new
/products/seedendpoint 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:
seed.pymodule with a/products/seedendpoint that drops, recreates, and seeds theproducttable using all columns from a CSV file, supporting a more complex schema. (app/api/products/seed.py)products.pyto fetch all columns from the new schema and return results as dictionaries keyed by column name. (app/api/products/products.py)reset.pymodule and its endpoint, which previously handled table reset and basic seeding. (app/api/products/reset.py)API routing updates:
seed_routerinstead of the removedreset_router, ensuring the new seeding logic is active. (app/api/products/__init__.py,app/api/routes.py) [1] [2]Test cleanup:
tests/test_routes.py)