add activity store
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
ea6e3f4766
commit
b303373b73
|
@ -38,6 +38,6 @@ class ActivityStoreAction
|
|||
{
|
||||
$this->handle($request->validated());
|
||||
|
||||
return redirect()->back();
|
||||
return redirect()->route('activity.index');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Activity\Actions;
|
||||
|
||||
use App\Activity;
|
||||
use App\Activity\Resources\ActivityResource;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
||||
class CreateAction
|
||||
{
|
||||
use AsAction;
|
||||
|
||||
public function handle(): Response
|
||||
{
|
||||
return Inertia::render('activity/VForm', [
|
||||
'meta' => ActivityResource::meta(),
|
||||
'data' => [
|
||||
'name' => '',
|
||||
'subactivities' => [],
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -28,6 +28,9 @@ class IndexAction
|
|||
|
||||
return Inertia::render('activity/VIndex', [
|
||||
'data' => $this->handle($filter),
|
||||
'toolbar' => [
|
||||
['href' => route('activity.create'), 'label' => 'Tätigkeit erstellen', 'color' => 'primary', 'icon' => 'plus'],
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ export default {
|
|||
data: function () {
|
||||
return {
|
||||
inner: {...this.data},
|
||||
mode: this.data.name === '' ? 'create' : 'edit',
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -28,7 +29,9 @@ export default {
|
|||
|
||||
methods: {
|
||||
submit() {
|
||||
this.$inertia.patch(`/activity/${this.inner.id}`, this.inner);
|
||||
this.mode === 'create'
|
||||
? this.$inertia.post('/activity', this.inner)
|
||||
: this.$inertia.patch(`/activity/${this.inner.id}`, this.inner);
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use App\Activity\Actions\ActivityStoreAction;
|
||||
use App\Activity\Actions\ActivityUpdateAction;
|
||||
use App\Activity\Actions\IndexAction as ActivityIndexAction;
|
||||
use App\Activity\Actions\CreateAction as ActivityCreateAction;
|
||||
use App\Activity\Actions\EditAction as ActivityEditAction;
|
||||
use App\Activity\Actions\DestroyAction as ActivityDestroyAction;
|
||||
use App\Contribution\Actions\FormAction as ContributionFormAction;
|
||||
|
@ -53,6 +54,7 @@ Route::group(['middleware' => 'auth:web'], function (): void {
|
|||
Route::get('/contribution/generate', [ContributionController::class, 'generate'])->name('contribution.generate');
|
||||
Route::get('/activity', ActivityIndexAction::class)->name('activity.index');
|
||||
Route::get('/activity/{activity}/edit', ActivityEditAction::class)->name('activity.edit');
|
||||
Route::get('/activity/create', ActivityCreateAction::class)->name('activity.create');
|
||||
Route::post('/activity', ActivityStoreAction::class)->name('activity.store');
|
||||
Route::patch('/activity/{activity}', ActivityUpdateAction::class)->name('activity.update');
|
||||
Route::delete('/activity/{activity}', ActivityDestroyAction::class)->name('activity.destroy');
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Activity;
|
||||
|
||||
use App\Subactivity;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function testItCreatesAnActivity(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
Subactivity::factory()->name('Pupu')->create();
|
||||
|
||||
$response = $this->get(route('activity.create'));
|
||||
|
||||
$this->assertInertiaHas([
|
||||
'name' => '',
|
||||
'subactivities' => [],
|
||||
], $response, 'data');
|
||||
$this->assertInertiaHas([
|
||||
'id' => Subactivity::first()->id,
|
||||
'name' => 'Pupu',
|
||||
], $response, 'meta.subactivities.0');
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,7 @@ class StoreTest extends TestCase
|
|||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
|
||||
$response = $this->from('/activity')->post(route('activity.store'), [
|
||||
$response = $this->post(route('activity.store'), [
|
||||
'name' => 'Lorem',
|
||||
'subactivities' => [],
|
||||
]);
|
||||
|
|
Loading…
Reference in New Issue