-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Currently, a lot of the tables.py files hold classes that have their own patching and serialization functions (see OfficerTerm in src/officers/tables.py. We should just let Pydantic's built in features handle that since it can handle serialization, patching, and validation. The data flow would look something like:
- GET request -> server
- Fetch the entry/entries from the database as SQL table entries
<Table>DB - SQL Table Model -> (process data) -> Pydantic Model
<Model>.model_validate(<TableDB>) - Use Pydantic's serialize
<Model>.model_dump_json()-> Send reponse
For requests that take in data, like POST/PATCH/PUT:
- POST/PATCH/PUT -> server
- [if PATCH/PUT] fetch entry(ies) from database -> put in Pydantic model, otherwise create a new Pydantic model
- update the edited/new entry with the data, using Pydantic's function to do it
- Use Pydantic's validation method to ensure the data is good
- Convert to a SQL Table Model and send it to the database
To do this we'd need to:
- Create a valid Pydantic model that covers all of the CRUD operations with proper validation fields that match the SQL table models (sort of done)
- Remove the validation, serialization, and patching functions from each of the SQL table models
- Update all the URL endpoints with the Pydantic models (sort of done)