days: refactor for better typing

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/877/head
Varun Patil 2023-10-14 17:46:54 -07:00
parent cb12398893
commit 1752396bf8
2 changed files with 9 additions and 11 deletions

View File

@ -52,8 +52,8 @@ return [
// API Routes
['name' => 'Days#days', 'url' => '/api/days', 'verb' => 'GET'],
['name' => 'Days#day', 'url' => '/api/days/{id}', 'verb' => 'GET'],
['name' => 'Days#dayPost', 'url' => '/api/days', 'verb' => 'POST'],
['name' => 'Days#day', 'url' => '/api/days', 'verb' => 'POST'],
['name' => 'Days#dayGet', 'url' => '/api/days/{id}', 'verb' => 'GET'],
['name' => 'Folders#sub', 'url' => '/api/folders/sub', 'verb' => 'GET'],
['name' => 'Clusters#list', 'url' => '/api/clusters/{backend}', 'verb' => 'GET'],

View File

@ -61,13 +61,12 @@ class DaysController extends GenericApiController
* @NoAdminRequired
*
* @PublicPage
*
* @param int[] $dayIds
*/
public function day(string $id): Http\Response
public function day(array $dayIds): Http\Response
{
return Util::guardEx(function () use ($id) {
// Split at commas and convert all parts to int
$dayIds = array_map(static fn ($p) => (int) $p, explode(',', $id));
return Util::guardEx(function () use ($dayIds) {
// Run actual query
$list = $this->tq->getDay(
$dayIds,
@ -91,12 +90,11 @@ class DaysController extends GenericApiController
* @NoAdminRequired
*
* @PublicPage
*
* @param int[] $dayIds
*/
public function dayPost(array $dayIds): Http\Response
public function dayGet(string $id): Http\Response
{
return $this->day(implode(',', $dayIds));
// Split at commas and convert all parts to int
return $this->day(array_map(static fn ($p) => (int) $p, explode(',', $id)));
}
/**