-
Notifications
You must be signed in to change notification settings - Fork 22
Add Basic JSON API Support to Index Actions in Controllers #164
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
Add Basic JSON API Support to Index Actions in Controllers #164
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @funktionslust, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
Hello! Gemini or gemini-code-assist here, providing a summary of this pull request. This PR, authored by funktionslust, aims to add basic JSON API support to the index()
methods across several controllers. The core idea is to allow consumers to request data in JSON format by including the Accept: application/json
header in their request. When this header is detected, the controller will return the full, unpaginated dataset as a JSON response, rather than rendering the standard HTML view. This is described as a foundational step towards building out more comprehensive API capabilities for the application, while ensuring the existing HTML behavior remains unaffected.
Highlights
- JSON API Support: Introduces the ability for
index
endpoints in various controllers to respond with data in JSON format. - Content Negotiation: Uses the
Request::wantsJson()
method to detect if the client prefers a JSON response based on theAccept
header. - Full Dataset Return: When a JSON response is requested, the full query result is returned, bypassing the standard pagination applied for HTML views.
- Targeted Implementation: The JSON response logic is specifically added to the
index
methods of multiple controllers.
Changelog
Click here to see the changelog
- .gitignore
- Added
.DS_Store
to the ignore list.
- Added
- app/Http/Controllers/ActorController.php
- Added conditional logic in the
index
method to return a JSON response if requested, bypassing pagination.
- Added conditional logic in the
- app/Http/Controllers/CategoryController.php
- Added conditional logic in the
index
method to return a JSON response if requested.
- Added conditional logic in the
- app/Http/Controllers/ClassifierTypeController.php
- Added conditional logic in the
index
method to return a JSON response if requested.
- Added conditional logic in the
- app/Http/Controllers/DefaultActorController.php
- Added conditional logic in the
index
method to return a JSON response if requested.
- Added conditional logic in the
- app/Http/Controllers/DocumentController.php
- Added conditional logic in the
index
method to return a JSON response if requested, bypassing pagination.
- Added conditional logic in the
- app/Http/Controllers/EventNameController.php
- Added conditional logic in the
index
method to return a JSON response if requested, bypassing pagination.
- Added conditional logic in the
- app/Http/Controllers/FeeController.php
- Added conditional logic in the
index
method to return a JSON response if requested, bypassing pagination.
- Added conditional logic in the
- app/Http/Controllers/MatterController.php
- Added conditional logic in the
index
method to return a JSON response if requested, including eager loading ofevents.info
and bypassing pagination. - Slightly reformatted the
$filters
array definition.
- Added conditional logic in the
- app/Http/Controllers/MatterTypeController.php
- Added conditional logic in the
index
method to return a JSON response if requested.
- Added conditional logic in the
- app/Http/Controllers/RenewalController.php
- Added conditional logic in the
index
method to return a JSON response if requested, including fee adjustment logic before returning the data and bypassing pagination. - Fixed indentation for the
appends
andlinks
call.
- Added conditional logic in the
- app/Http/Controllers/RoleController.php
- Added conditional logic in the
index
method to return a JSON response if requested.
- Added conditional logic in the
- app/Http/Controllers/RuleController.php
- Added conditional logic in the
index
method to return a JSON response if requested, bypassing pagination.
- Added conditional logic in the
- app/Http/Controllers/TaskController.php
- Added conditional logic in the
index
method to return a JSON response if requested, bypassing pagination.
- Added conditional logic in the
- app/Http/Controllers/TemplateMemberController.php
- Added conditional logic in the
index
method to return a JSON response if requested, bypassing pagination.
- Added conditional logic in the
- app/Http/Controllers/UserController.php
- Added conditional logic in the
index
method to return a JSON response if requested, bypassing pagination.
- Added conditional logic in the
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
HTML or JSON,
Choose the format you desire,
Data flows freely.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces basic JSON API support for index
actions across several controllers, which is a good step towards broader API functionality. The implementation is largely consistent across the controllers.
There are a few key areas to address:
- Unpaginated JSON Responses: All new JSON endpoints return full, unpaginated datasets. While this is stated in the PR description as a first step, it's important to consider pagination for these endpoints in future iterations to ensure scalability and performance, especially with large datasets.
- Critical Issue in
RenewalController
: There's a variable scope issue within the new JSON response logic that needs to be fixed as it will likely lead to incorrect fee calculations or errors. - Code Duplication in
RenewalController
: The logic for transforming renewal data is duplicated for the new JSON path and the existing HTML path. This should be refactored for better maintainability.
Additionally, while not part of the diffs, adding automated tests for these new API endpoints would be highly beneficial for ensuring their correctness and stability moving forward.
Overall, the changes align with the stated goal, but the identified issues, particularly the critical one, should be addressed before merging.
Summary of Findings
- Unpaginated JSON Responses: All new JSON API endpoints return full, unpaginated datasets. While this is a stated design choice for the initial implementation, it poses a scalability and performance risk for large datasets. Future iterations should consider implementing pagination for these JSON endpoints.
- Critical Bug in RenewalController Fee Calculation: In
app/Http/Controllers/RenewalController.php
, the newly added JSON response logic has a critical variable scope issue in itstransform
closure. Variables$cost
and$fee
are used without proper initialization within the closure's scope, which will likely lead to incorrect fee calculations or runtime errors. - Code Duplication in RenewalController: The data transformation logic for renewals (adjusting fees) in
app/Http/Controllers/RenewalController.php
is duplicated for the new JSON response path and the existing HTML response path. This should be refactored to improve maintainability. - .gitignore Update: The addition of
.DS_Store
to.gitignore
is a good practice for macOS development environments. (Severity: low, not commented inline due to settings)
Merge Readiness
This pull request makes good progress in adding basic JSON API support. However, there is a critical issue in the RenewalController
concerning fee calculation that must be addressed before merging. Additionally, several medium-severity concerns regarding unpaginated JSON responses and code duplication should ideally be considered for improvement, if not in this PR, then in immediate follow-ups.
Due to the critical issue, I recommend that changes be made before this PR is merged. As a reviewer, I am not authorized to approve pull requests; please ensure further review and approval by authorized maintainers after addressing the feedback.
if ($request->wantsJson()) { | ||
return response()->json($query->get()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This endpoint returns all tasks (matching filters) unpaginated for JSON requests. While this fulfills the current requirement for a full dataset, it's important to consider scalability.
Could a large number of tasks lead to performance issues with an unpaginated JSON response? Planning for pagination in future API versions might be beneficial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is true that there can be tens of thousands of tasks, and keeping pagination could be appropriate.
Tell us how you expect to use this. Offer a wiki page PR with an exemplary use case. |
Thanks for merging! My application utilizes the extended API to retrieve Matters, Events and EventNames from phpIPAM, enabling it to calculate and generate events within phpIPAM itself. To ensure consistency, I applied the logic across all index actions. I acknowledge that this unpaginated approach will not scale due to potential timeouts and size limitations. I omitted pagination for now to keep the data retrieval straightforward, planning to implement it when necessary. Given the current lack of comprehensive documentation and endpoints for single record retrieval, updates, additions, and deletions, the API remains incomplete. I’m open to enhancing and cleaning up the implementation if there’s interest in developing a more robust API. However, building an API solely for its own sake makes no sense. For my current requirements, this implementation suffices. Offering a public API also entails considerations for external system regressions. Establishing a dedicated API layer with transformers, versioning, and tests would be essential. I’m willing to contribute to this effort when there’s a clear necessity. |
This adds basic JSON response support to index() methods in several controllers. If the request has an Accept: application/json header, a full unpaginated dataset is returned as JSON. HTML behavior remains unchanged. This is a first step toward API support.