Skip to content

Implement quote management features: delete, get by ID, and update#6

Merged
WillianSilva51 merged 3 commits intomainfrom
feat/tests
Apr 4, 2026
Merged

Implement quote management features: delete, get by ID, and update#6
WillianSilva51 merged 3 commits intomainfrom
feat/tests

Conversation

@WillianSilva51
Copy link
Copy Markdown
Owner

This pull request introduces significant enhancements to the quote management API, focusing on adding support for retrieving and deleting quotes by ID, improving schema validation, and expanding test coverage. The changes include new endpoints, repository and service methods, stricter request validation, and comprehensive tests for the new functionalities.

API Enhancements:

  • Added new endpoints to retrieve (GET /{id}) and delete (DELETE /{id}) quotes by their unique ID in api/routers/quotes.py, with corresponding OpenAPI YAML definitions for both actions. [1] [2] [3] [4]
  • Updated response models for quote-related endpoints to consistently use QuoteResponse, ensuring proper serialization and validation of API responses. [1] [2] [3] [4] [5]

Repository and Service Layer Improvements:

  • Implemented get_quote_by_id and delete_quote_by_id methods in QuoteRepository, and corresponding logic in QuoteService to handle not-found cases and logging. [1] [2]
  • Began scaffolding for an update_quote method in the repository (not yet implemented).

Schema and Model Validation:

  • Introduced UpdateQuoteRequest schema and added stricter validation for content, author, and source fields using field_validator in api/schemas/quote_schema.py.
  • Added updated_at field to both the model and response schema to track quote modifications. [1] [2]

Testing Improvements:

  • Expanded unit tests in test_quote_service.py to cover getting and deleting quotes by ID, as well as edge cases like not-found errors, ensuring robust error handling and correct repository/service interactions.

General Code Quality and Refactoring:

  • Improved import ordering and consistency in multiple files, and made minor corrections to type hints and field descriptions for better maintainability. [1] [2] [3] [4] [5] [6] [7] [8] [9]

These changes collectively improve the API's functionality, reliability, and maintainability, especially around quote retrieval, deletion, and validation.

@WillianSilva51 WillianSilva51 requested a review from Copilot April 4, 2026 17:20
@WillianSilva51 WillianSilva51 self-assigned this Apr 4, 2026
@WillianSilva51 WillianSilva51 added documentation Improvements or additions to documentation enhancement New feature or request labels Apr 4, 2026
@WillianSilva51 WillianSilva51 merged commit f5adddb into main Apr 4, 2026
3 checks passed
@WillianSilva51 WillianSilva51 deleted the feat/tests branch April 4, 2026 17:21
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the quotes API to support retrieving and deleting quotes by ID, while tightening request/response validation and updating caching/serialization to handle non-list responses.

Changes:

  • Added GET /v1/quotes/{id} and DELETE /v1/quotes/{id} endpoints plus corresponding service/repository methods.
  • Introduced UpdateQuoteRequest and expanded quote schemas/models to include updated_at, with stricter field stripping/empty checks.
  • Updated Redis caching to serialize both list and single-model responses; expanded service-layer tests for get/delete-by-id flows.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
api/routers/quotes.py Adds get/delete-by-id endpoints and standardizes responses to QuoteResponse.
api/services/quote_service.py Implements service logic for get/delete-by-id and not-found behavior.
api/repositories/quote_repository.py Adds repository methods for get/delete-by-id; scaffolds (but does not implement) update.
api/schemas/quote_schema.py Adds UpdateQuoteRequest, field validators, and updated_at on response.
api/models/quote.py Adds updated_at field to the Quote document model.
api/core/cache.py Improves caching serialization to support non-list return types.
api/tests/test_quote_service.py Adds tests for get/delete-by-id and today quote behavior; includes a placeholder update test.
api/tests/conftest.py Minor formatting change.
api/schemas/pagination.py Import formatting only.
api/schemas/error_schema.py Import formatting only.
api/main.py Import ordering only.
api/core/security.py Import ordering only.
api/core/database.py Import ordering only.
api/FinFrases/Quotes/Get Quote By ID.yml Adds HTTP client definition for GET by ID.
api/FinFrases/Quotes/Delete Quote By ID.yml Adds HTTP client definition for DELETE by ID.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +39 to +42
async def update_quote(
self, id: str, quote_data: UpdateQuoteRequest
) -> Quote | None:
pass
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

update_quote() is currently a stub (pass) but the repository exports it and the PR title/description mention update support. This will silently do nothing if invoked and makes the update feature incomplete; implement the update logic (including setting updated_at) or remove the method and any related schemas/tests until it’s supported.

Copilot uses AI. Check for mistakes.
Comment on lines +221 to 226


class TestUpdateQuoteById:
@pytest.mark.asyncio
async def test_update_quote_by_id_sucess(self, service, mock_repo, quote):
pass
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

This test currently contains only pass and will always succeed, which can mask missing update functionality. Either implement the update-by-id behavior assertions (and corresponding service/repo functionality) or remove this placeholder test; also fix the typo in the test name (sucess -> success).

Suggested change
class TestUpdateQuoteById:
@pytest.mark.asyncio
async def test_update_quote_by_id_sucess(self, service, mock_repo, quote):
pass

Copilot uses AI. Check for mistakes.
Comment on lines +141 to +147
async def get_quote_by_id(
id: str,
service: QuoteService = Depends(),
repo: QuoteRepository = Depends(),
) -> QuoteResponse:
quote = await service.get_quote_by_id(id=id, repo=repo)
return QuoteResponse.model_validate(quote.model_dump())
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

id is typed as str here, but the repository converts it to PydanticObjectId without handling invalid values. A non-ObjectId string will raise and be caught by the global exception handler as a 500; prefer validating at the API boundary (e.g., type id as PydanticObjectId or explicitly validate/convert and raise a 422/400) to avoid internal-server errors for bad input.

Copilot uses AI. Check for mistakes.
Comment on lines +158 to +164
async def delete_quote(
id: str,
service: QuoteService = Depends(),
repo: QuoteRepository = Depends(),
_: str = Depends(verify_api_key),
) -> None:
await service.delete_quote_by_id(id=id, repo=repo)
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

Same as the GET endpoint: id is accepted as str but converted to PydanticObjectId later without input validation, so malformed IDs can trigger a 500. Validate/convert id in the router layer (e.g., use PydanticObjectId as the param type) so invalid IDs return a 422/400 instead of an internal error.

Copilot uses AI. Check for mistakes.
Comment on lines +76 to +80
updated_at: datetime = Field(
default_factory=lambda: datetime.now(timezone.utc),
description="A data e hora da última atualização da citação",
)

Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

UpdateQuoteRequest includes an updated_at field with a default value. For an update request payload this allows clients to set a server-managed auditing field (and may conflict with the value the server should enforce). Consider removing updated_at from the request schema and setting it in the service/repository when persisting the update.

Suggested change
updated_at: datetime = Field(
default_factory=lambda: datetime.now(timezone.utc),
description="A data e hora da última atualização da citação",
)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants