Add participants count for form index
This commit is contained in:
parent
de76e195e7
commit
48383b25da
|
@ -20,7 +20,7 @@ class FormIndexAction
|
|||
*/
|
||||
public function handle(string $filter): LengthAwarePaginator
|
||||
{
|
||||
return FilterScope::fromRequest($filter)->getQuery()->paginate(15);
|
||||
return FilterScope::fromRequest($filter)->getQuery()->query(fn ($query) => $query->withCount('participants'))->paginate(15);
|
||||
}
|
||||
|
||||
public function asController(ActionRequest $request): Response
|
||||
|
|
|
@ -40,6 +40,7 @@ class FormResource extends JsonResource
|
|||
'registration_from' => $this->registration_from?->format('Y-m-d H:i:s'),
|
||||
'registration_until' => $this->registration_until?->format('Y-m-d H:i:s'),
|
||||
'config' => $this->config,
|
||||
'participants_count' => $this->participants_count,
|
||||
'links' => [
|
||||
'update' => route('form.update', ['form' => $this->getModel()]),
|
||||
'destroy' => route('form.destroy', ['form' => $this->getModel()]),
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories\Form\Models;
|
||||
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Participant;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Tests\Feature\Form\FormtemplateSectionRequest;
|
||||
|
||||
/**
|
||||
* @extends Factory<Participant>
|
||||
*/
|
||||
class ParticipantFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var class-string<Form>
|
||||
*/
|
||||
protected $model = Participant::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, FormtemplateSectionRequest> $sections
|
||||
*/
|
||||
public function sections(array $sections): self
|
||||
{
|
||||
return $this->state(['config' => ['sections' => array_map(fn ($section) => $section->create(), $sections)]]);
|
||||
}
|
||||
}
|
|
@ -90,6 +90,7 @@
|
|||
<th>Name</th>
|
||||
<th>Von</th>
|
||||
<th>Bis</th>
|
||||
<th>Anzahl TN</th>
|
||||
<th></th>
|
||||
</thead>
|
||||
|
||||
|
@ -103,6 +104,9 @@
|
|||
<td>
|
||||
<div v-text="form.to_human"></div>
|
||||
</td>
|
||||
<td>
|
||||
<div v-text="form.participants_count"></div>
|
||||
</td>
|
||||
<td>
|
||||
<a v-tooltip="`Bearbeiten`" href="#" class="ml-2 inline-flex btn btn-warning btn-sm" @click.prevent="edit(form)"><ui-sprite src="pencil"></ui-sprite></a>
|
||||
<a v-tooltip="`Löschen`" href="#" class="ml-2 inline-flex btn btn-danger btn-sm" @click.prevent="deleting = form"><ui-sprite src="trash"></ui-sprite></a>
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Tests\EndToEnd\Form;
|
|||
use App\Form\Fields\TextField;
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Formtemplate;
|
||||
use App\Form\Models\Participant;
|
||||
use Carbon\Carbon;
|
||||
use Tests\EndToEndTestCase;
|
||||
use Tests\Feature\Form\FormtemplateFieldRequest;
|
||||
|
@ -29,6 +30,7 @@ class FormIndexActionTest extends EndToEndTestCase
|
|||
->registrationFrom('2023-05-06 04:00:00')
|
||||
->registrationUntil('2023-04-01 05:00:00')
|
||||
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([FormtemplateFieldRequest::type(TextField::class)])])
|
||||
->has(Participant::factory()->count(5))
|
||||
->create();
|
||||
|
||||
sleep(1);
|
||||
|
@ -44,6 +46,7 @@ class FormIndexActionTest extends EndToEndTestCase
|
|||
->assertInertiaPath('data.data.0.from_human', '05.05.2023')
|
||||
->assertInertiaPath('data.data.0.to_human', '07.06.2023')
|
||||
->assertInertiaPath('data.data.0.from', '2023-05-05')
|
||||
->assertInertiaPath('data.data.0.participants_count', 5)
|
||||
->assertInertiaPath('data.data.0.to', '2023-06-07')
|
||||
->assertInertiaPath('data.data.0.registration_from', '2023-05-06 04:00:00')
|
||||
->assertInertiaPath('data.data.0.registration_until', '2023-04-01 05:00:00')
|
||||
|
|
Loading…
Reference in New Issue