Skip to content

Implement agents CRUD endpoints (DEV-70)#20

Open
sonya-q wants to merge 10 commits intomainfrom
feature/DEV-70/agents-crud
Open

Implement agents CRUD endpoints (DEV-70)#20
sonya-q wants to merge 10 commits intomainfrom
feature/DEV-70/agents-crud

Conversation

@sonya-q
Copy link

@sonya-q sonya-q commented Mar 4, 2026

Jira ticket link

Jira ticket

Implementation description

  • get_agent_or_404(): looks up an agent by ID and automatically returns 404 if not found.
  • validate_agency_exists(): checks that a given agency_id refers to a real agency before saving.
    On PUT specifically, agency_id is only validated if it's actually included in the request body; no need to re-validate if not changing.

Steps to test

Navigate to: this link

  1. Create an agency first via POST /api/agencies; need a real agency_id to create agents (copy id)
  2. POST /api/agents with that agency_id, a first name, and last name
  3. GET /api/agents: list should containing your new agent, ordered by last name
  4. GET /api/agents/{id}
  5. PUT /api/agents/{id}
  6. DELETE /api/agents/{id}

What should reviewers focus on?

  • Testing all APIs
  • Whether the validate_agency_exists() helper is the right approach

Checklist

Format for branch, commit, and PR title: docs/GIT.md.

  • My branch name includes the Jira ticket key
  • My PR name is descriptive and in imperative tense
  • My PR name includes the Jira ticket key
  • My commit messages are descriptive and in imperative tense. My commits are atomic and trivial commits are squashed or fixup'd into non-trivial commits
  • My commit messages include the Jira ticket key
  • I have run the appropriate linter(s)
  • I have requested a review from the PL, as well as other devs who have background knowledge on this PR or who will be building on top of this PR

@sonya-q sonya-q requested review from ivymxu and kenzysoror March 4, 2026 22:04
@sonya-q sonya-q changed the title Implement agents CRUD endpoints (DEV-71) Implement agents CRUD endpoints (DEV-70) Mar 4, 2026
@kenzysoror
Copy link
Member

hey hey👋 have you run

cd backend
black .

already?

Copy link
Member

@kenzysoror kenzysoror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job on the endpoints, sonya!!🙌

before we dive into the review, it would be great if you could move the database logic into the services/ layer rather than keeping it directly in the router!

we want to try to keep routers focused on request/response handling, while the services layer contains the actual business logic and DB operations. this helps keep the API layer lightweight, makes the logic easier to reuse, and makes things simpler to test.

i know this wasn't originally implemented with agencies.py, so for the "structural" reference, you can take a look at: #15 and #17. they follow the pattern i'm talking about by putting the DB logic in services/<entity>.py and calling it from the router + you can see my comments on suggested changes.

@kenzysoror kenzysoror requested review from kenzysoror and sowmya314 and removed request for ivymxu March 8, 2026 01:20
from ..database import get_db
from ..models import Agency, Agent
from ..schemas import AgentCreate, AgentUpdate, Agent as AgentSchema

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include from ..services import agents as agent_service

@sonya-q sonya-q requested a review from sowmya314 March 10, 2026 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants