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:
Currently, a lot of the
tables.pyfiles hold classes that have their own patching and serialization functions (seeOfficerTerminsrc/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:<Table>DB<Model>.model_validate(<TableDB>)<Model>.model_dump_json()-> Send reponseFor requests that take in data, like POST/PATCH/PUT:
To do this we'd need to: