Skip to content

Refactor objects to use Pydantic models #123

@jbriones1

Description

@jbriones1

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:

  1. GET request -> server
  2. Fetch the entry/entries from the database as SQL table entries <Table>DB
  3. SQL Table model -> (process data) -> Pydantic model created from table model<Model>(<Table>DB)

For requests that take in data, like POST/PATCH/PUT:

  1. POST/PATCH/PUT -> server
  2. [if PATCH/PUT] fetch entries from database -> put in Pydantic model, otherwise create a new Pydantic model
  3. Use Pydantic's validation method to ensure the updated data is good
  4. 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)
  • Ensure Pydantic models can be created from SQL Table models
  • 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)

Metadata

Metadata

Assignees

Type

No fields configured for Update.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions