Skip to content

Commit

Permalink
Added api notes to docs. Returned image with events api.
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-maddock committed Nov 21, 2024
1 parent 765e427 commit 0269df4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/Api/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Resources/EventResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}
}
25 changes: 25 additions & 0 deletions app/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions app/Models/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions docs/api_notes.md
Original file line number Diff line number Diff line change
@@ -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`

0 comments on commit 0269df4

Please sign in to comment.