Add Factory for contribution documents
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
db79f4dc17
commit
9109721d4a
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Contribution\Actions;
|
||||
|
||||
use App\Contribution\ContributionFactory;
|
||||
use App\Country;
|
||||
use App\Member\Member;
|
||||
use App\Member\MemberResource;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
||||
class FormAction
|
||||
{
|
||||
use AsAction;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -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<SolingenDocument> */
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Contribution;
|
||||
|
||||
use App\Contribution\Documents\ContributionDocument;
|
||||
use App\Contribution\Documents\DvDocument;
|
||||
use App\Contribution\Documents\SolingenDocument;
|
||||
|
||||
class ContributionFactory
|
||||
{
|
||||
/**
|
||||
* @var array<int, class-string<ContributionDocument>>
|
||||
*/
|
||||
private array $documents = [
|
||||
DvDocument::class,
|
||||
SolingenDocument::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @return array<int, array{id: string, name: string}>
|
||||
*/
|
||||
public function compilerSelect(): array
|
||||
{
|
||||
return collect($this->documents)->map(fn ($document) => [
|
||||
'title' => $document::getName(),
|
||||
'class' => $document,
|
||||
])->toArray();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Contribution\Documents;
|
||||
|
||||
use Zoomyboy\Tex\Document;
|
||||
|
||||
abstract class ContributionDocument extends Document
|
||||
{
|
||||
abstract public static function getName(): string;
|
||||
}
|
|
@ -1,17 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Contribution;
|
||||
namespace App\Contribution\Documents;
|
||||
|
||||
use App\Country;
|
||||
use App\Member\Member;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Http\Request;
|
||||
use Zoomyboy\Tex\Document;
|
||||
use Zoomyboy\Tex\Engine;
|
||||
use Zoomyboy\Tex\Template;
|
||||
|
||||
class DvDocument extends Document
|
||||
class DvDocument extends ContributionDocument
|
||||
{
|
||||
public function __construct(
|
||||
public string $dateFrom,
|
||||
|
@ -102,4 +101,9 @@ class DvDocument extends Document
|
|||
{
|
||||
return Engine::PDFLATEX;
|
||||
}
|
||||
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'Für DV erstellen';
|
||||
}
|
||||
}
|
|
@ -1,17 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Contribution;
|
||||
namespace App\Contribution\Documents;
|
||||
|
||||
use App\Member\Member;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Zoomyboy\Tex\Document;
|
||||
use Zoomyboy\Tex\Engine;
|
||||
use Zoomyboy\Tex\Template;
|
||||
|
||||
class SolingenDocument extends Document
|
||||
class SolingenDocument extends ContributionDocument
|
||||
{
|
||||
final private function __construct(
|
||||
public string $dateFrom,
|
||||
|
@ -87,4 +86,9 @@ class SolingenDocument extends Document
|
|||
{
|
||||
return Engine::PDFLATEX;
|
||||
}
|
||||
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'Für Stadt Solingen erstellen';
|
||||
}
|
||||
}
|
|
@ -54,23 +54,14 @@
|
|||
</div>
|
||||
|
||||
<button
|
||||
v-for="(compiler, index) in compilers"
|
||||
target="_BLANK"
|
||||
type="submit"
|
||||
name="type"
|
||||
value="\App\Contribution\SolingenDocument"
|
||||
:value="compiler.class"
|
||||
class="btn btn-primary mt-3 inline-block"
|
||||
>
|
||||
Für Stadt erstellen
|
||||
</button>
|
||||
<button
|
||||
target="_BLANK"
|
||||
type="submit"
|
||||
name="type"
|
||||
value="\App\Contribution\DvDocument"
|
||||
class="btn btn-primary mt-3 inline-block"
|
||||
>
|
||||
Für DV erstellen
|
||||
</button>
|
||||
v-text="compiler.title"
|
||||
></button>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
|
@ -93,6 +84,7 @@ export default {
|
|||
countries: {},
|
||||
defaultCountry: {},
|
||||
allMembers: {},
|
||||
compilers: {},
|
||||
},
|
||||
computed: {
|
||||
memberResults() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use App\Contribution\Actions\FormAction as ContributionFormAction;
|
||||
use App\Contribution\ContributionController;
|
||||
use App\Course\Controllers\CourseController;
|
||||
use App\Efz\ShowEfzDocumentAction;
|
||||
|
@ -39,6 +40,6 @@ Route::group(['middleware' => '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');
|
||||
});
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Contribution;
|
||||
|
||||
use App\Contribution\Documents\DvDocument;
|
||||
use App\Country;
|
||||
use App\Member\Member;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class IndexTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function testItHasContributionIndex(): void
|
||||
{
|
||||
$this->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');
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
namespace Tests\Feature\Contribution;
|
||||
|
||||
use App\Country;
|
||||
use App\Member\Member;
|
||||
|
@ -8,13 +8,13 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|||
use Tests\TestCase;
|
||||
use Zoomyboy\Tex\Tex;
|
||||
|
||||
class ContributionTest extends TestCase
|
||||
class StoreTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* @testWith ["App\\Contribution\\SolingenDocument", ["Super tolles Lager", "Max Muster", "Jane Muster", "15.06.1991"]]
|
||||
* ["App\\Contribution\\DvDocument", ["Muster, Max", "Muster, Jane", "15.06.1991", "42777 SG"]]
|
||||
* @testWith ["App\\Contribution\\Documents\\SolingenDocument", ["Super tolles Lager", "Max Muster", "Jane Muster", "15.06.1991"]]
|
||||
* ["App\\Contribution\\Documents\\DvDocument", ["Muster, Max", "Muster, Jane", "15.06.1991", "42777 SG"]]
|
||||
*
|
||||
* @param array<int, string> $bodyChecks
|
||||
*/
|
Loading…
Reference in New Issue