Remove member create and edit routes

This commit is contained in:
philipp lang 2024-08-28 22:12:05 +02:00
parent 2e6c27b8f1
commit a56c0d815e
5 changed files with 111 additions and 134 deletions

View File

@ -4,38 +4,24 @@ namespace App\Member\Actions;
use App\Member\Member; use App\Member\Member;
use App\Member\MemberResource; use App\Member\MemberResource;
use Inertia\Inertia; use Illuminate\Http\JsonResponse;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction; use Lorisleiva\Actions\Concerns\AsAction;
class MemberShowAction class MemberShowAction
{ {
use AsAction; use AsAction;
/** public function asController(Member $member): JsonResponse
* @return array{data: MemberResource}
*/
public function handle(Member $member): array
{ {
return [ return response()->json([
'data' => new MemberResource( 'data' => new MemberResource($member
$member ->load('memberships')
->load('memberships') ->load('invoicePositions.invoice')
->load('invoicePositions.invoice') ->load('nationality')
->load('nationality') ->load('region')
->load('region') ->load('subscription')
->load('subscription') ->load('courses.course')),
->load('courses.course')
),
'meta' => MemberResource::meta(), 'meta' => MemberResource::meta(),
]; ]);
}
public function asController(Member $member): Response
{
session()->put('menu', 'member');
session()->put('title', 'Mitglied ' . $member->fullname);
return Inertia::render('member/ShowView', $this->handle($member));
} }
} }

View File

@ -27,17 +27,6 @@ class MemberController extends Controller
]); ]);
} }
public function create(): Response
{
session()->put('menu', 'member');
session()->put('title', 'Mitglied erstellen');
return Inertia::render('member/VForm', [
'mode' => 'create',
'meta' => MemberResource::meta(),
]);
}
public function store(MemberRequest $request, NamiSettings $settings): RedirectResponse public function store(MemberRequest $request, NamiSettings $settings): RedirectResponse
{ {
$request->persistCreate($settings); $request->persistCreate($settings);
@ -45,19 +34,6 @@ class MemberController extends Controller
return redirect()->route('member.index'); return redirect()->route('member.index');
} }
public function edit(Member $member, Request $request): Response
{
session()->put('menu', 'member');
session()->put('title', "Mitglied {$member->firstname} {$member->lastname} bearbeiten");
return Inertia::render('member/VForm', [
'data' => new MemberResource($member),
'mode' => 'edit',
'conflict' => '1' === $request->query('conflict', '0'),
'meta' => MemberResource::meta(),
]);
}
public function update(Member $member, MemberRequest $request): RedirectResponse public function update(Member $member, MemberRequest $request): RedirectResponse
{ {
try { try {

View File

@ -90,7 +90,7 @@ Route::group(['middleware' => 'auth:web'], function (): void {
Route::post('/nami/search', NamiSearchAction::class)->name('nami.search'); Route::post('/nami/search', NamiSearchAction::class)->name('nami.search');
Route::get('/initialize', InitializeFormAction::class)->name('initialize.form'); Route::get('/initialize', InitializeFormAction::class)->name('initialize.form');
Route::post('/initialize', InitializeAction::class)->name('initialize.store'); Route::post('/initialize', InitializeAction::class)->name('initialize.store');
Route::resource('member', MemberController::class)->except('show', 'destroy'); Route::resource('member', MemberController::class)->except('show', 'destroy', 'edit', 'create');
Route::delete('/member/{member}', MemberDeleteAction::class); Route::delete('/member/{member}', MemberDeleteAction::class);
Route::get('/member/{member}', MemberShowAction::class)->name('member.show'); Route::get('/member/{member}', MemberShowAction::class)->name('member.show');
Route::resource('subscription', SubscriptionController::class); Route::resource('subscription', SubscriptionController::class);

View File

@ -36,9 +36,11 @@ class MemberIndexTest extends EndToEndTestCase
->assertInertiaCount('data.data', 1); ->assertInertiaCount('data.data', 1);
} }
public function testItGetsDefaultCountryFromDefaultModel(): void public function testItGetsDefault(): void
{ {
$this->callFilter('member.index', [])->assertInertiaPath('data.meta.default.country_id', Country::firstWhere('name', 'Deutschland')->id); $this->callFilter('member.index', [])
->assertInertiaPath('data.meta.default.country_id', Country::firstWhere('name', 'Deutschland')->id)
->assertInertiaPath('data.meta.default.address', '');
} }
public function testItHandlesAddress(): void public function testItHandlesAddress(): void
@ -264,4 +266,24 @@ class MemberIndexTest extends EndToEndTestCase
$this->callFilter('member.index', ['hasBirthday' => false, 'exclude' => [$member->id]]) $this->callFilter('member.index', ['hasBirthday' => false, 'exclude' => [$member->id]])
->assertInertiaCount('data.data', 0); ->assertInertiaCount('data.data', 0);
} }
public function testItDisplaysActivityMeta(): void
{
$activity = Activity::factory()->inNami(5)->hasAttached(Subactivity::factory()->inNami(23)->name('Biber'))->name('€ Mitglied')->create();
$subactivity = $activity->subactivities->first();
$this->callFilter('member.index', [])
->assertInertiaPath("data.meta.formSubactivities.{$activity->id}.{$subactivity->id}", 'Biber')
->assertInertiaPath("data.meta.formActivities.{$activity->id}", '€ Mitglied')
->assertInertiaPath('data.meta.billKinds.0', ['id' => 'E-Mail', 'name' => 'E-Mail']);
}
public function testItDoesntDisplayActivitiesAndSubactivitiesNotInNami(): void
{
Activity::factory()->hasAttached(Subactivity::factory()->name('Biber'))->name('€ Mitglied')->create();
$this->callFilter('member.index', [])
->assertInertiaCount('data.meta.formCreateSubactivities', 0)
->assertInertiaCount('data.meta.formCreateActivities', 0);
}
} }

View File

@ -2,6 +2,7 @@
namespace Tests\Feature\Member; namespace Tests\Feature\Member;
use App\Activity;
use App\Country; use App\Country;
use App\Course\Models\Course; use App\Course\Models\Course;
use App\Course\Models\CourseMember; use App\Course\Models\CourseMember;
@ -14,6 +15,7 @@ use App\Member\Membership;
use App\Nationality; use App\Nationality;
use App\Payment\Subscription; use App\Payment\Subscription;
use App\Region; use App\Region;
use App\Subactivity;
use Carbon\Carbon; use Carbon\Carbon;
use Generator; use Generator;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
@ -75,70 +77,58 @@ class ShowTest extends TestCase
'mitgliedsnr' => 998, 'mitgliedsnr' => 998,
'lon' => 19.05, 'lon' => 19.05,
'lat' => 14.053, 'lat' => 14.053,
'comment' => 'Lorem bla'
]); ]);
$response = $this->get("/member/{$member->id}"); $this->getJson(route('member.show', ['member' => $member]))
->assertJsonPath('data.firstname', 'Max')
$this->assertInertiaHas([ ->assertJsonPath('data.birthday_human', '20.04.1991')
'birthday_human' => '20.04.1991', ->assertJsonPath('data.age', 14)
'age' => 14, ->assertJsonPath('data.group_name', 'Stamm Beispiel')
'group_name' => 'Stamm Beispiel', ->assertJsonPath('data.full_address', 'Itterstr 3, 42719 Solingen')
'full_address' => 'Itterstr 3, 42719 Solingen', ->assertJsonPath('data.region.name', 'NRW')
'region' => ['name' => 'NRW'], ->assertJsonPath('data.other_country', 'other')
'other_country' => 'other', ->assertJsonPath('data.main_phone', '+49 212 1266775')
'main_phone' => '+49 212 1266775', ->assertJsonPath('data.mobile_phone', '+49 212 1266776')
'mobile_phone' => '+49 212 1266776', ->assertJsonPath('data.work_phone', '+49 212 1266777')
'work_phone' => '+49 212 1266777', ->assertJsonPath('data.children_phone', '+49 212 1266778')
'children_phone' => '+49 212 1266778', ->assertJsonPath('data.email', 'a@b.de')
'email' => 'a@b.de', ->assertJsonPath('data.email_parents', 'b@c.de')
'email_parents' => 'b@c.de', ->assertJsonPath('data.fax', '+49 212 1255674')
'fax' => '+49 212 1255674', ->assertJsonPath('data.fullname', 'Herr Max Muster')
'fullname' => 'Herr Max Muster', ->assertJsonPath('data.efz_human', '20.09.2022')
'efz_human' => '20.09.2022', ->assertJsonPath('data.ps_at_human', '20.04.2022')
'ps_at_human' => '20.04.2022', ->assertJsonPath('data.more_ps_at_human', '02.06.2022')
'more_ps_at_human' => '02.06.2022', ->assertJsonPath('data.without_education_at_human', '03.06.2022')
'without_education_at_human' => '03.06.2022', ->assertJsonPath('data.without_efz_at_human', '04.06.2022')
'without_efz_at_human' => '04.06.2022', ->assertJsonPath('data.recertified_at_human', '13.06.2022')
'recertified_at_human' => '13.06.2022', ->assertJsonPath('data.has_vk', true)
'has_vk' => true, ->assertJsonPath('data.has_svk', true)
'has_svk' => true, ->assertJsonPath('data.multiply_pv', true)
'multiply_pv' => true, ->assertJsonPath('data.multiply_more_pv', true)
'multiply_more_pv' => true, ->assertJsonPath('data.has_nami', true)
'has_nami' => true, ->assertJsonPath('data.nami_id', 123)
'nami_id' => 123, ->assertJsonPath('data.send_newspaper', true)
'send_newspaper' => true, ->assertJsonPath('data.joined_at_human', '11.06.2022')
'joined_at_human' => '11.06.2022', ->assertJsonPath('data.bill_kind_name', 'Post')
'bill_kind_name' => 'Post', ->assertJsonPath('data.mitgliedsnr', 998)
'mitgliedsnr' => 998, ->assertJsonPath('data.lon', 19.05)
'lon' => 19.05, ->assertJsonPath('data.lat', 14.053)
'lat' => 14.053, ->assertJsonPath('data.subscription.name', 'Sub')
'subscription' => [ ->assertJsonPath('data.comment', 'Lorem bla')
'name' => 'Sub', ->assertJsonPath('data.memberships.0.activity_name', '€ LeiterIn')
], ->assertJsonPath('data.memberships.0.subactivity_name', 'Jungpfadfinder')
], $response, 'data'); ->assertJsonPath('data.memberships.0.id', $member->memberships->first()->id)
$this->assertInertiaHas([ ->assertJsonPath('data.memberships.0.human_date', '19.11.2022')
'activity_name' => '€ LeiterIn', ->assertJsonPath('data.memberships.0.promised_at', now()->format('Y-m-d'))
'subactivity_name' => 'Jungpfadfinder', ->assertJsonPath('data.courses.0.organizer', 'DPSG')
'id' => $member->memberships->first()->id, ->assertJsonPath('data.courses.0.event_name', 'Wochenende')
'human_date' => '19.11.2022', ->assertJsonPath('data.courses.0.completed_at_human', '03.03.2022')
'promised_at' => now()->format('Y-m-d'), ->assertJsonPath('data.courses.0.course.name', ' Baustein 2e - Gewalt gegen Kinder und Jugendliche: Vertiefung, Prävention ')
], $response, 'data.memberships.0'); ->assertJsonPath('data.courses.0.course.short_name', '2e')
$this->assertInertiaHas([ ->assertJsonPath('data.invoicePositions.0.description', 'uu')
'organizer' => 'DPSG', ->assertJsonPath('data.invoicePositions.0.price_human', '10,50 €')
'event_name' => 'Wochenende', ->assertJsonPath('data.invoicePositions.0.invoice.status', 'Neu');
'completed_at_human' => '03.03.2022',
'course' => [
'name' => ' Baustein 2e - Gewalt gegen Kinder und Jugendliche: Vertiefung, Prävention ',
'short_name' => '2e',
],
], $response, 'data.courses.0');
$this->assertInertiaHas([
'description' => 'uu',
'price_human' => '10,50 €',
'invoice' => [
'status' => 'Neu',
]
], $response, 'data.invoicePositions.0');
} }
public function testItShowsMinimalSingleMember(): void public function testItShowsMinimalSingleMember(): void
@ -150,24 +140,14 @@ class ShowTest extends TestCase
->for(Subscription::factory()->forFee()) ->for(Subscription::factory()->forFee())
->create(['firstname' => 'Max', 'lastname' => 'Muster']); ->create(['firstname' => 'Max', 'lastname' => 'Muster']);
$response = $this->get("/member/{$member->id}"); $this->get(route('member.show', ['member' => $member]))
->assertJsonPath('data.has_vk', false)
$this->assertInertiaHas([ ->assertJsonPath('data.has_svk', false)
'region' => ['name' => '-- kein --'], ->assertJsonPath('data.multiply_pv', false)
'fullname' => 'Max Muster', ->assertJsonPath('data.multiply_more_pv', false)
'nationality' => [ ->assertJsonPath('data.nationality.name', 'deutsch')
'name' => 'deutsch', ->assertJsonPath('data.region.name', '-- kein --')
], ->assertJsonPath('data.fullname', 'Max Muster');
'efz_human' => null,
'ps_at_human' => null,
'more_ps_at_human' => null,
'without_education_at_human' => null,
'without_efz_at_human' => null,
'has_vk' => false,
'has_svk' => false,
'multiply_pv' => false,
'multiply_more_pv' => false,
], $response, 'data');
} }
public function membershipDataProvider(): Generator public function membershipDataProvider(): Generator
@ -188,8 +168,21 @@ class ShowTest extends TestCase
->has(Membership::factory()->in('€ LeiterIn', 455, 'Pfadfinder', 15)->state(['from' => $from, 'to' => $to])) ->has(Membership::factory()->in('€ LeiterIn', 455, 'Pfadfinder', 15)->state(['from' => $from, 'to' => $to]))
->create(); ->create();
$response = $this->get("/member/{$member->id}"); $this->get(route('member.show', ['member' => $member]))
->assertJsonPath('data.memberships.0.is_active', $isActive);
}
$this->assertInertiaHas($isActive, $response, 'data.memberships.0.is_active'); public function testItDisplaysMeta(): void
{
$this->withoutExceptionHandling();
$this->login()->loginNami();
$member = Member::factory()->defaults()->create(['salutation' => 'Doktor', 'firstname' => 'Max', 'comment' => 'Lorem bla']);
$activity = Activity::factory()->inNami(66)->hasAttached(Subactivity::factory()->inNami(56)->name('Biber'))->name('€ Mitglied')->create();
$subactivity = $activity->subactivities->first();
$this->get(route('member.show', ['member' => $member]))
->assertJsonPath("meta.formActivities.{$activity->id}", '€ Mitglied')
->assertJsonPath("meta.formSubactivities.{$activity->id}.{$subactivity->id}", 'Biber')
->assertJsonPath("meta.billKinds.0", ['id' => 'E-Mail', 'name' => 'E-Mail']);
} }
} }