Skip to content

Conversation

@codesungrape
Copy link
Collaborator

Description

Trello ticket: https://trello.com/c/O9jraVyM

This change finalizes the transition of the GET /books/{id} endpoint. The endpoint now uses the delete_book_by_id() helper function with find_one_and_update() to performa. soft delete.

  • It includes an updated, comprehensive test suite to achieve 100% test coverage for the new logic.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Code refactor (improving code quality without changing functionality)
  • Performance improvement
  • Other (please describe):

How Has This Been Tested?

Automated tests, manual testing, cURL, CI/CD pipeline

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My individual commit messages are descriptive and follow our commit guidelines
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Copy link

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 completes the MongoDB integration for the DELETE /books/{id} endpoint by replacing in-memory book operations with MongoDB soft delete functionality. The implementation now uses the new delete_book_by_id() helper function with find_one_and_update() to perform soft deletions.

  • Introduces the delete_book_by_id() helper function for MongoDB soft delete operations
  • Updates the DELETE endpoint to use MongoDB instead of in-memory data structures
  • Adds comprehensive test coverage including edge cases and error handling
  • Updates OpenAPI specification to reflect new error responses

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
app/datastore/mongo_helper.py Adds new delete_book_by_id() function for MongoDB soft delete operations
app/routes.py Updates DELETE endpoint to use MongoDB helper function with proper error handling
tests/test_mongo_helper.py Adds comprehensive unit tests for the new MongoDB helper function
tests/test_app.py Updates integration tests to work with MongoDB instead of in-memory data
tests/test_api_security.py Updates security tests to work with the new MongoDB implementation
openapi.yml Updates API documentation to include new 400 error response for invalid IDs
Comments suppressed due to low confidence (1)

tests/test_mongo_helper.py:115

  • Function name should be consistent with the actual function being tested. Consider renaming to 'test_delete_book_by_id_already_deleted_returns_none' to match the function name pattern used in other tests.
def test_soft_delete_already_deleted_book_returns_none():


def delete_book_by_id(book_collection, book_id):
"""
Soft delete book with given id
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

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

The docstring should use proper capitalization and punctuation: 'Soft delete book with given ID.'

Suggested change
Soft delete book with given id
Soft delete a book with the given ID.

Copilot uses AI. Check for mistakes.
Fix comment for clarity

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codesungrape codesungrape merged commit 4b98e55 into main Jul 31, 2025
2 checks passed
@codesungrape codesungrape deleted the Complete-MongoDB-Integration-for-DELETE-/books/{id} branch July 31, 2025 15:14
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