diff --git a/app/Contribution/Actions/FormAction.php b/app/Contribution/Actions/FormAction.php new file mode 100644 index 00000000..bf3dab25 --- /dev/null +++ b/app/Contribution/Actions/FormAction.php @@ -0,0 +1,37 @@ + + */ + public function handle(): array + { + return [ + 'allMembers' => MemberResource::collection(Member::slangOrdered()->get()), + 'countries' => Country::pluck('name', 'id'), + 'defaultCountry' => Country::firstWhere('name', 'Deutschland')->id, + 'compilers' => app(ContributionFactory::class)->compilerSelect(), + ]; + } + + public function asController(): Response + { + session()->put('menu', 'contribution'); + session()->put('title', 'Zuschüsse'); + + return Inertia::render('contribution/VIndex', $this->handle()); + } +} diff --git a/app/Contribution/ContributionController.php b/app/Contribution/ContributionController.php index b1eb2da9..5c30147d 100644 --- a/app/Contribution/ContributionController.php +++ b/app/Contribution/ContributionController.php @@ -2,30 +2,14 @@ namespace App\Contribution; -use App\Country; +use App\Contribution\Documents\SolingenDocument; use App\Http\Controllers\Controller; -use App\Member\Member; -use App\Member\MemberResource; use Illuminate\Http\Request; -use Inertia\Inertia; -use Inertia\Response; use Zoomyboy\Tex\BaseCompiler; use Zoomyboy\Tex\Tex; class ContributionController extends Controller { - public function form(): Response - { - session()->put('menu', 'contribution'); - session()->put('title', 'Zuschüsse'); - - return Inertia::render('contribution/VIndex', [ - 'allMembers' => MemberResource::collection(Member::slangOrdered()->get()), - 'countries' => Country::pluck('name', 'id'), - 'defaultCountry' => Country::firstWhere('name', 'Deutschland')->id, - ]); - } - public function generate(Request $request): BaseCompiler { /** @var class-string */ diff --git a/app/Contribution/ContributionFactory.php b/app/Contribution/ContributionFactory.php new file mode 100644 index 00000000..c99d30f0 --- /dev/null +++ b/app/Contribution/ContributionFactory.php @@ -0,0 +1,29 @@ +> + */ + private array $documents = [ + DvDocument::class, + SolingenDocument::class, + ]; + + /** + * @return array + */ + public function compilerSelect(): array + { + return collect($this->documents)->map(fn ($document) => [ + 'title' => $document::getName(), + 'class' => $document, + ])->toArray(); + } +} diff --git a/app/Contribution/Documents/ContributionDocument.php b/app/Contribution/Documents/ContributionDocument.php new file mode 100644 index 00000000..c40c1852 --- /dev/null +++ b/app/Contribution/Documents/ContributionDocument.php @@ -0,0 +1,10 @@ + - + v-text="compiler.title" + > @@ -93,6 +84,7 @@ export default { countries: {}, defaultCountry: {}, allMembers: {}, + compilers: {}, }, computed: { memberResults() { diff --git a/routes/web.php b/routes/web.php index e6e4e294..7ad9db53 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ 'auth:web'], function (): void { Route::resource('member.course', CourseController::class); Route::get('/member/{member}/efz', ShowEfzDocumentAction::class)->name('efz'); Route::get('/member/{member}/resync', MemberResyncController::class)->name('member.resync'); - Route::get('/contribution', [ContributionController::class, 'form'])->name('contribution.form'); + Route::get('/contribution', ContributionFormAction::class)->name('contribution.form'); Route::get('/contribution/generate', [ContributionController::class, 'generate'])->name('contribution.generate'); }); diff --git a/tests/Feature/Contribution/IndexTest.php b/tests/Feature/Contribution/IndexTest.php new file mode 100644 index 00000000..790943d5 --- /dev/null +++ b/tests/Feature/Contribution/IndexTest.php @@ -0,0 +1,30 @@ +withoutExceptionHandling()->login()->loginNami(); + $country = Country::factory()->create(['name' => 'Deutschland']); + $member1 = Member::factory()->defaults()->create(['firstname' => 'Max', 'lastname' => 'Muster']); + $member2 = Member::factory()->defaults()->create(['firstname' => 'Jane', 'lastname' => 'Muster']); + + $response = $this->get('/contribution'); + + $this->assertInertiaHas('Jane', $response, 'allMembers.0.firstname'); + $this->assertInertiaHas([ + 'class' => DvDocument::class, + 'title' => 'Für DV erstellen', + ], $response, 'compilers.0'); + } +} diff --git a/tests/Feature/ContributionTest.php b/tests/Feature/Contribution/StoreTest.php similarity index 79% rename from tests/Feature/ContributionTest.php rename to tests/Feature/Contribution/StoreTest.php index 428ccabb..0e88b072 100644 --- a/tests/Feature/ContributionTest.php +++ b/tests/Feature/Contribution/StoreTest.php @@ -1,6 +1,6 @@ $bodyChecks */