Files
crewli/api/app/Http/Resources/Api/V1/CrowdListResource.php
bert.hausmans cae2242502 feat: crowd lists audit, enum, factory, service and tests
Audit and complete the Crowd Lists module:
- Add CrowdListType enum (internal/external) with proper casts
- Create CrowdListService for business logic (add/remove person,
  max_persons enforcement, auto_approve, activity logging)
- Create CrowdListFactory with Dutch names and states
- Create AddPersonToCrowdListRequest form request
- Fix FormRequests to use Rule::enum instead of hardcoded strings
- Fix CrowdListResource to use enum->value and add is_full field
- Refactor controller to be thin (delegates to service)
- Add eager loading for crowdType and recipientCompany
- Write 18 comprehensive tests (CRUD, auth, edge cases)
- Update API.md with request/response documentation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 13:53:57 +02:00

33 lines
1007 B
PHP

<?php
declare(strict_types=1);
namespace App\Http\Resources\Api\V1;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
final class CrowdListResource extends JsonResource
{
public function toArray(Request $request): array
{
$personsCount = $this->whenCounted('persons');
return [
'id' => $this->id,
'event_id' => $this->event_id,
'crowd_type_id' => $this->crowd_type_id,
'name' => $this->name,
'type' => $this->type->value,
'recipient_company_id' => $this->recipient_company_id,
'auto_approve' => $this->auto_approve,
'max_persons' => $this->max_persons,
'is_full' => $this->max_persons !== null && isset($this->persons_count)
? $this->persons_count >= $this->max_persons
: false,
'created_at' => $this->created_at->toIso8601String(),
'persons_count' => $personsCount,
];
}
}