Files
landing-api/app/Http/Controllers/Api/PublicApi/V1/CallController.php
Josep Piguillem 3897113313 Initial commit: Pireon Admin — headless admin panel and public API
Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer
collective, backed by the Pireon OAuth identity server. The public site is a
separate, server-rendered application consuming /api/public/v1.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-19 17:55:27 +02:00

51 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api\PublicApi\V1;
use App\Http\Resources\PublicApi\PublicCallResource;
use App\Models\Call;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
/**
* Open calls for contributors — the conversion point of the whole site.
*/
class CallController extends PublicController
{
public function index(Request $request): AnonymousResourceCollection
{
$calls = Call::query()
->with(['technologies', 'project.coverMedia'])
->unless($this->isPreview($request), fn (Builder $q) => $q->open())
// A call attached to an unpublished project must not leak it.
->where(fn (Builder $q) => $q
->whereNull('project_id')
->orWhereHas('project', fn (Builder $p) => $p->published()))
->when($request->filled('technology'), fn (Builder $q) => $q
->whereHas('technologies', fn (Builder $t) => $t
->whereIn('slug', (array) $request->input('technology'))))
// "I have four hours a week" is the real filter people apply.
->when($request->filled('max_hours_per_week'), fn (Builder $q) => $q
->where('hours_per_week', '<=', $request->integer('max_hours_per_week')))
->orderByRaw('hours_per_week is null, hours_per_week asc')
->paginate($this->perPage($request))
->withQueryString();
return PublicCallResource::collection($calls);
}
public function show(Request $request, string $slug): PublicCallResource
{
$call = Call::query()
->with(['technologies', 'project.technologies', 'project.coverMedia'])
->whereSlug($slug)
->unless($this->isPreview($request), fn (Builder $q) => $q->open())
->firstOrFail();
return PublicCallResource::make($call);
}
}