Skip to content

[Chore] Refactor shared/api_utils.py to use penguin-libs #72

@PenguinzTech

Description

@PenguinzTech

User Story

As a maintainer, I want to refactor shared/api_utils.py to leverage penguin-libs utilities so that common API patterns use the shared library instead of local implementations.

Background

shared/api_utils.py provides ~150 lines of generic REST API helpers:

  • paginate(query, page, per_page) — SQLAlchemy query pagination
  • get_pagination_params() — Extract page/per_page from request args
  • validate_request(schema_class, data) — Marshmallow validation
  • make_error_response(message, status_code) — Error response formatting
  • make_success_response(data, message, status_code) — Success response formatting
  • apply_filters(query, model, filters) — Query filtering
  • get_or_404(model, id) — Fetch or abort

Elder already uses penguin_libs.pydantic.flask_integration.validated_request for request validation in 12+ endpoint files, partially overlapping with validate_request().

Acceptance Criteria

  • Audit which api_utils functions are still used vs replaced by penguin-libs
  • Remove functions superseded by penguin-libs (e.g., validate_requestvalidated_request)
  • Keep Elder-specific helpers that have no penguin-libs equivalent
  • If penguin-libs gains pagination/response utils, migrate to those
  • All API endpoints continue working
  • Tests pass (unit + integration)
  • Linting passes

Notes

  • Low effort — mostly removing dead code and consolidating imports
  • Some functions may need to stay as Elder-specific thin wrappers
  • Consider contributing generic pagination/response utilities back to penguin-libs

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions