Skip to content

feat: added put endpoint to update api status by api_group #1167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: dev
Choose a base branch
from

Conversation

Mukeli3
Copy link

@Mukeli3 Mukeli3 commented Feb 28, 2025

Description

This pull request introduces a new PUT /api-status/{api_group} endpoint to allow updating an existing API status record identified by api_group. The implementation includes:

  • A new update method in APIStatusService that fetches an existing APIStatus record by api_group, updates it with the provided data, and handles partial updates by only modifying fields that are present in the request.
  • A PUT route in the api_status router that accepts an APIStatusUpdate schema and returns a success response with the updated record or a 404 error if the api_group doesn’t exist.
  • Adjustments to the APIStatusUpdate schema to support optional fields and handle response_time as either a Decimal or a string (e.g., "200ms"), with parsing logic in the service.
  • The changes ensure clients can dynamically modify API status details without creating duplicates, aligning with the project’s goal of precise API status management.

Related Issue (Link to issue ticket)

#1063

Motivation and Context

This change is required to enhance the API status management system by allowing clients to update existing records rather than creating new ones. It solves the problem of duplicate entries cluttering the database and provides a more precise way to manage API status data. The feature is particularly useful for maintaining up-to-date status information (e.g., status, response_time, details, last_checked) for specific API groups, which is critical for monitoring and diagnostics.

How Has This Been Tested?

I tested the changes in a local development environment with the following setup:

Environment:

Ubuntu 20.04 (Vagrant), Python 3.10, FastAPI, SQLAlchemy, Supabase.

Steps:

  • Started the FastAPI app with uvicorn main:app --reload.
  • Populated the api_status table with a test record (api_group="user").
  • Ran the following curl commands:

curl -X PUT http://localhost:8000/api-status/user \ -H "Content-Type: application/json" \ -d '{"apiGroup": "user", "status": "active", "response_time": "200ms", "details": "API is running fine"}'

Got: 200 OK with updated data.

Partial update:
curl -X PUT http://localhost:8000/api-status/user \ -H "Content-Type: application/json" \ -d '{"status": "inactive"}'

Got: 200 OK with only status updated.

Non-existent api_group:
curl -X PUT http://localhost:8000/api-status/nonexistent \ -H "Content-Type: application/json" \ -d '{"status": "active"}'

Got: 404 Not Found.

Screenshots (if appropriate - Postman, etc):

test1 test2

Verified database updates using a SQL client (e.g., psql).
Results: All tests passed, with responses matching the specified formats (200 OK for success, 404 for not found).

Types of changes

  • New feature (non-breaking change which adds functionality)​

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@Mukeli3 Mukeli3 changed the title initial commit [FEAT]: Added PUT Endpoint to Update API Status by api_group Feb 28, 2025
@Mukeli3 Mukeli3 changed the title [FEAT]: Added PUT Endpoint to Update API Status by api_group feat: Added PUT Endpoint to Update API Status by api_group Mar 1, 2025
@samuelogboye
Copy link
Contributor

Drop a screenshot confirming your tests are passing including past tests

@Mukeli3 Mukeli3 changed the title feat: Added PUT Endpoint to Update API Status by api_group feat: added put endpoint to update api status by api_group Mar 1, 2025
@Mukeli3
Copy link
Author

Mukeli3 commented Mar 1, 2025

I'm on it

Copy link
Contributor

@joboy-dev joboy-dev left a comment

Choose a reason for hiding this comment

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

Attend to the comment

@samuelogboye samuelogboye requested a review from joboy-dev March 2, 2025 16:19
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