]> git.localhorst.tv Git - alttp.git/blobdiff - app/Http/Controllers/EventController.php
events overview
[alttp.git] / app / Http / Controllers / EventController.php
index a0dce45abb908bbd3202753f57b36f6957ed6af6..c9a1a4190fb0e2c2c9b713879e98d826ec81d000 100644 (file)
@@ -13,6 +13,9 @@ class EventController extends Controller
                $validatedData = $request->validate([
                        'after' => 'nullable|date',
                        'before' => 'nullable|date',
+                       'order' => 'nullable|string',
+                       'with' => 'nullable|array',
+                       'with.*' => 'string',
                ]);
                $events = Event::where('visible', '=', true);
                if (isset($validatedData['before'])) {
@@ -27,6 +30,22 @@ class EventController extends Controller
                                $query->orWhere('end', '>', $validatedData['after']);
                        });
                }
+               if (isset($validatedData['order'])) {
+                       switch ($validatedData['order']) {
+                               case 'recency':
+                                       $events->orderByRaw('start IS NOT NULL');
+                                       $events->orderByRaw('end IS NOT NULL');
+                                       $events->orderBy('end', 'DESC');
+                                       $events->orderBy('start', 'DESC');
+                                       $events->orderBy('name', 'ASC');
+                                       break;
+                       }
+               }
+               if (isset($validatedData['with'])) {
+                       if (in_array('description', $validatedData['with'])) {
+                               $events->with('description');
+                       }
+               }
                return $events->get()->toJson();
        }