-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ Homestead.yaml | |
.env | ||
/nbproject/private/ | ||
/config/renewal.php | ||
.DS_Store |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,25 +38,31 @@ public function index(Request $request) | |
{ | ||
$filters = $request->except( | ||
[ | ||
'display_with', | ||
'page', | ||
'filter', | ||
'value', | ||
'sortkey', | ||
'sortdir', | ||
'tab', | ||
'include_dead', | ||
] | ||
); | ||
'display_with', | ||
'page', | ||
'filter', | ||
'value', | ||
'sortkey', | ||
'sortdir', | ||
'tab', | ||
'include_dead', | ||
]); | ||
|
||
$matters = Matter::filter( | ||
$query = Matter::filter( | ||
$request->input('sortkey', 'id'), | ||
$request->input('sortdir', 'desc'), | ||
$filters, | ||
$request->display_with, | ||
$request->include_dead | ||
)->simplePaginate(25); | ||
$matters->withQueryString()->links(); // Keep URL parameters in the paginator links | ||
); | ||
|
||
if ($request->wantsJson()) { | ||
$matters = $query->with('events.info')->get(); | ||
return response()->json($matters); | ||
} | ||
Comment on lines
+59
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The JSON response for matters is unpaginated and includes However, as the number of matters can be substantial, returning all of them at once might lead to performance or memory issues. For future enhancements, would it be beneficial to implement pagination for the JSON API, similar to how the HTML view is paginated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There can be thousands of matters. It might be appropriate to keep pagination. |
||
|
||
$matters = $query->simplePaginate(25); | ||
$matters->withQueryString()->links(); // Keep URL parameters in the paginator links | ||
|
||
return view('matter.index', compact('matters')); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,17 @@ public function index(Request $request) | |
$renewals->orderByDesc('due_date'); | ||
} | ||
|
||
if ($request->wantsJson()) { | ||
$renewals = $renewals->get(); | ||
$renewals->transform(function ($ren) { | ||
$this->adjustFees($ren, $cost, $fee); | ||
$ren->cost = $cost; | ||
$ren->fee = $fee; | ||
return $ren; | ||
}); | ||
jjdejong marked this conversation as resolved.
Show resolved
Hide resolved
jjdejong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return response()->json($renewals); | ||
} | ||
Comment on lines
+99
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
$renewals = $renewals->simplePaginate(config('renewal.general.paginate', 25)); | ||
|
||
// Adjust the cost and fee of each renewal based on customized settings | ||
|
@@ -106,7 +117,7 @@ public function index(Request $request) | |
return $ren; | ||
}); | ||
|
||
$renewals->appends($request->input())->links(); // Keep URL parameters in the paginator links | ||
$renewals->appends($request->input())->links(); // Keep URL parameters in the paginator links | ||
return view('renewals.index', compact('renewals', 'step', 'invoice_step')); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,13 @@ public function index(Request $request) | |
}); | ||
} | ||
|
||
$tasks = $tasks->orderBy('due_date')->simplePaginate(18) | ||
$query = $tasks->orderBy('due_date'); | ||
|
||
if ($request->wantsJson()) { | ||
return response()->json($query->get()); | ||
} | ||
Comment on lines
+52
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
|
||
$tasks = $query->simplePaginate(18) | ||
->appends($request->input()); | ||
|
||
return view('task.index', compact('tasks', 'isrenewals')); | ||
|
Uh oh!
There was an error while loading. Please reload this page.