Add backend for update
This commit is contained in:
parent
c05434a7fb
commit
a603aca80c
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Form\Actions;
|
||||
|
||||
use App\Form\Models\Participant;
|
||||
use App\Lib\Events\Succeeded;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Lorisleiva\Actions\ActionRequest;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
||||
class ParticipantUpdateAction
|
||||
{
|
||||
use AsAction;
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'data' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
public function handle(Participant $participant, ActionRequest $request): JsonResponse
|
||||
{
|
||||
$participant->update(['data' => [...$participant->data, ...$request->validated('data')]]);
|
||||
|
||||
Succeeded::message('Teilnehmer*in bearbeitet.')->dispatch();
|
||||
return response()->json([]);
|
||||
}
|
||||
}
|
|
@ -33,6 +33,7 @@ class ParticipantResource extends JsonResource
|
|||
'destroy' => route('participant.destroy', ['participant' => $this->getModel()]),
|
||||
'children' => route('form.participant.index', ['form' => $this->form, 'parent' => $this->id]),
|
||||
'fields' => route('participant.fields', ['participant' => $this->getModel()]),
|
||||
'update' => route('participant.update', ['participant' => $this->getModel()]),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ use App\Form\Actions\ParticipantAssignAction;
|
|||
use App\Form\Actions\ParticipantDestroyAction;
|
||||
use App\Form\Actions\ParticipantFieldsAction;
|
||||
use App\Form\Actions\ParticipantIndexAction;
|
||||
use App\Form\Actions\ParticipantUpdateAction;
|
||||
use App\Initialize\Actions\InitializeAction;
|
||||
use App\Initialize\Actions\InitializeFormAction;
|
||||
use App\Initialize\Actions\NamiGetSearchLayerAction;
|
||||
|
@ -174,6 +175,7 @@ Route::group(['middleware' => 'auth:web'], function (): void {
|
|||
Route::delete('/participant/{participant}', ParticipantDestroyAction::class)->name('participant.destroy');
|
||||
Route::post('/participant/{participant}/assign', ParticipantAssignAction::class)->name('participant.assign');
|
||||
Route::get('/participant/{participant}/fields', ParticipantFieldsAction::class)->name('participant.fields');
|
||||
Route::patch('/participant/{participant}', ParticipantUpdateAction::class)->name('participant.update');
|
||||
|
||||
// ------------------------------------ fileshare -----------------------------------
|
||||
Route::post('/fileshare', FileshareStoreAction::class)->name('fileshare.store');
|
||||
|
|
|
@ -49,6 +49,7 @@ class ParticipantIndexActionTest extends FormTestCase
|
|||
->assertJsonPath('data.0.links.destroy', route('participant.destroy', ['participant' => $form->participants->first()]))
|
||||
->assertJsonPath('data.0.links.assign', route('participant.assign', ['participant' => $form->participants->first()]))
|
||||
->assertJsonPath('data.0.links.fields', route('participant.fields', ['participant' => $form->participants->first()]))
|
||||
->assertJsonPath('data.0.links.update', route('participant.update', ['participant' => $form->participants->first()]))
|
||||
->assertJsonPath('meta.columns.0.name', 'Vorname')
|
||||
->assertJsonPath('meta.columns.0.base_type', class_basename(TextField::class))
|
||||
->assertJsonPath('meta.columns.0.id', 'vorname')
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Form;
|
||||
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Participant;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class ParticipantUpdateActionTest extends FormTestCase
|
||||
{
|
||||
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function testItUpdatesParticipant(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$participant = Participant::factory()->data(['vorname' => 'Max', 'select' => ['A', 'B']])
|
||||
->for(Form::factory()->sections([
|
||||
FormtemplateSectionRequest::new()->name('Sektion')->fields([
|
||||
$this->textField('vorname')->name('Vorname'),
|
||||
$this->checkboxesField('select')->options(['A', 'B', 'C']),
|
||||
])
|
||||
]))
|
||||
->create();
|
||||
|
||||
$this->patchJson(route('participant.update', ['participant' => $participant->id]), ['data' => ['vorname' => 'Jane']])
|
||||
->assertOk();
|
||||
|
||||
$this->assertEquals('Jane', $participant->fresh()->data['vorname']);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue