]> git.localhorst.tv Git - alttp.git/blobdiff - app/Http/Controllers/EventController.php
random chat buttons
[alttp.git] / app / Http / Controllers / EventController.php
index bfe9efd82eaa854f0f4836637f711264dfb0e379..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,11 +30,28 @@ 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();
        }
 
        public function single(Request $request, Event $event) {
                $this->authorize('view', $event);
+               $event->load('description');
                return $event->toJson();
        }