Skip to content

Conversation

@codesungrape
Copy link
Collaborator

@codesungrape codesungrape commented Aug 26, 2025

Description

Summary:

Adds POST /books/{book_id}/reservations to allow authenticated users to create reservations. The route is protected by require_jwt and prevents duplicate reservations by the same user.

Key Changes:

  • New JWT-protected reservation creation endpoint with duplicate prevention
  • JWT configuration separation from general Flask SECRET_KEY
  • Updated OpenAPI specification to reflect JWT protection requirements

Follow-up:

  • Add TTL for reservations.
  • Consider adding a DB-level uniqueness constraint to guard against race conditions.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • Unit & integration tests: /tests/test_reservations.py, updated tests/test_decorators.py, tests/test_auth.py
  • Manual checks: cURL requests, mongosh
  • editor.swagger.io to check openapi.yml
  • CI/CD - 100% test coverage and 100% pylint

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

The decorator unit tests were failing with a
because they created a minimal Flask app without any configuration.

This commit creates a local, file-specific  fixture that
configures the test app with the required .

To ensure perfect isolation, the dummy  route used by the
tests is now defined directly within this new fixture.
Replaced the previous payload-based check with the auth_token
fixture, which generates a proper JWT in the Authorization
header. This ensures tests now align with the current auth
flow and avoids reliance on outdated payload logic.
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 adds a new JWT-protected POST endpoint for creating book reservations, implementing the /books/{book_id}/reservations route with authentication and duplicate prevention logic.

Key Changes:

  • New JWT-protected reservation creation endpoint with duplicate prevention
  • JWT configuration separation from general Flask SECRET_KEY
  • Updated OpenAPI specification to reflect JWT protection requirements

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
app/routes/reservation_routes.py New route handler for POST /books/{book_id}/reservations with JWT protection and business logic
app/utils/decorators.py Updated JWT decorator to use dedicated JWT_SECRET_KEY instead of general SECRET_KEY
app/config.py Added JWT_SECRET_KEY configuration separate from Flask's SECRET_KEY
app/__init__.py Registered new reservations blueprint with the Flask app
app/routes/auth_routes.py Updated login route to use JWT_SECRET_KEY for token generation
tests/test_reservations.py Comprehensive test suite for the new reservation endpoint
tests/conftest.py Added JWT_SECRET_KEY to test configuration and improved user fixture
tests/test_decorators.py Updated decorator tests to align with new JWT configuration
tests/test_auth.py Updated auth tests to use JWT_SECRET_KEY
openapi.yml Updated API specification to reflect JWT protection and new response schemas

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codesungrape codesungrape merged commit 1c89a26 into main Aug 27, 2025
2 checks passed
@codesungrape codesungrape deleted the Add-/books/{book_id}/reservations-POST-endpoint branch August 27, 2025 08:50
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