Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added api notes to docs. Returned image with events api. #1270

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`
Loading