diff --git a/app/Http/Controllers/Api/EventsController.php b/app/Http/Controllers/Api/EventsController.php index 7582824b..3b2d23f4 100644 --- a/app/Http/Controllers/Api/EventsController.php +++ b/app/Http/Controllers/Api/EventsController.php @@ -15,7 +15,6 @@ use App\Models\Entity; use App\Models\Event; use App\Models\EventResponse; -use App\Models\EventReview; use App\Models\EventType; use App\Models\Follow; use App\Models\OccurrenceDay; @@ -158,6 +157,8 @@ public function index( $events = $query->visible($this->user) ->with('visibility', 'venue') ->paginate($listResultSet->getLimit()); + + // how do I create an event response DTO that includes everything I want return response()->json(new EventCollection($events)); } diff --git a/app/Http/Resources/EventResource.php b/app/Http/Resources/EventResource.php index 6c04ada8..4341a824 100644 --- a/app/Http/Resources/EventResource.php +++ b/app/Http/Resources/EventResource.php @@ -47,7 +47,9 @@ public function toArray($request) 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, - 'updated_at' => $this->updated_at + 'updated_at' => $this->updated_at, + 'primary_photo' => $this->getPrimaryPhotoPath(), + 'primary_photo_thumbnail' => $this->getPrimaryPhotoThumbnailPath(), ]; } } diff --git a/app/Models/Event.php b/app/Models/Event.php index 430d6cd4..270b9d42 100644 --- a/app/Models/Event.php +++ b/app/Models/Event.php @@ -5,6 +5,7 @@ use App\Filters\QueryFilter; use Carbon\Carbon; use DateTime; +use Storage; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -990,4 +991,28 @@ public function getInstagramFormat(): ?string return $format; } + + // returns the actual path to the primary photo + public function getPrimaryPhotoPath(): ?string + { + $photo = $this->getPrimaryPhoto(); + + if ($photo) { + return Storage::disk('external')->url($photo->getStoragePath()); + } + + return null; + } + + // returns the actual path to the thumbnail + public function getPrimaryPhotoThumbnailPath(): ?string + { + $photo = $this->getPrimaryPhoto(); + + if ($photo) { + return Storage::disk('external')->url($photo->getStorageThumbnail()); + } + + return null; + } } \ No newline at end of file diff --git a/app/Models/Photo.php b/app/Models/Photo.php index 38af5366..2d2664af 100644 --- a/app/Models/Photo.php +++ b/app/Models/Photo.php @@ -156,11 +156,11 @@ protected function saveAs(string $name): Photo } - public function makeThumbnail(): Photo + public function makeThumbnail(?int $size = 200): Photo { // builds an image given the path of the file on the external disk, then creates a version $image = Image::make(Storage::disk('external')->url($this->path)) - ->fit(200) + ->fit($size) ->save('storage/'.$this->thumbnail); $saved_image_uri = $image->basePath(); diff --git a/docs/api_notes.md b/docs/api_notes.md new file mode 100644 index 00000000..32f8e793 --- /dev/null +++ b/docs/api_notes.md @@ -0,0 +1,10 @@ +# API Notes + +## Filtering Lists +You can apply filters to routes using the following: + + +- To filter by a specific field, use the field name as the key and the value as the value. + - Example: `GET /api/events?filters[name]=Event Name` +- To order by a specific field, use the field name as the key and the value as the value. + - Example: `GET /api/events?sort=model.property&direction=asc` \ No newline at end of file