Add API method to get the current event
Diff
app/Http/routes.php | 3 ++-
app/Http/Controllers/Event/TimetableController.php | 28 ++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
@@ -117,6 +117,7 @@
Route::group(['middleware' => 'api', 'as' => 'api::', 'prefix' => 'api'], function () {
Route::get('dj-says', ['as' => 'dj-says', 'uses' => 'DJ\DJSaysController@getSays']);
Route::get('timetable', ['as' => 'timetable', 'uses' => 'DJ\TimetableController@getJSONTimetable']);
Route::get('events', ['as' => 'events', 'uses' => 'Event\TimetableController@getJSONTimetable']);
Route::get('event/all', ['as' => 'events', 'uses' => 'Event\TimetableController@getJSONTimetable']);
Route::get('event/current', ['as' => 'event.current', 'uses' => 'Event\TimetableController@getCurrentEvent']);
Route::post('request', ['as' => 'request', 'uses' => 'DJ\RequestController@request']);
});
@@ -179,6 +179,34 @@
}
/**
* Get the current event.
*
* @return array
*/
public function getCurrentEvent()
{
$event = Event::where('week', Carbon::now()->weekOfYear)
->where('year', Carbon::now()->year)
->where('day', Carbon::now()->format('N'))
->where('hour', Carbon::now()->hour)
->where('approved', true)
->first();
if ($event) {
return [
'id' => $event->user()->first()->userid,
'name' => $event->user()->first()->getDisplayName()->toHtml(),
'type' => $event->type->name,
'booked' => true
];
} else {
return [
'booked' => false
];
}
}
/**
* Get the booked slots for this week in JSON format.
*
* @param bool $raw should we return the user's name in raw html