Add payload for ContributionController
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
7ee1102a5d
commit
8069e2b4dd
|
@ -5,6 +5,7 @@ namespace App\Contribution;
|
||||||
use App\Contribution\Documents\SolingenDocument;
|
use App\Contribution\Documents\SolingenDocument;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Zoomyboy\Tex\BaseCompiler;
|
use Zoomyboy\Tex\BaseCompiler;
|
||||||
use Zoomyboy\Tex\Tex;
|
use Zoomyboy\Tex\Tex;
|
||||||
|
|
||||||
|
@ -12,9 +13,22 @@ class ContributionController extends Controller
|
||||||
{
|
{
|
||||||
public function generate(Request $request): BaseCompiler
|
public function generate(Request $request): BaseCompiler
|
||||||
{
|
{
|
||||||
/** @var class-string<SolingenDocument> */
|
$payload = json_decode(base64_decode($request->input('payload', '')), true);
|
||||||
$type = $request->query('type');
|
|
||||||
|
|
||||||
return Tex::compile($type::fromRequest($request));
|
$validated = Validator::make($payload, [
|
||||||
|
'dateFrom' => 'required|date|date_format:Y-m-d',
|
||||||
|
'dateUntil' => 'required|date|date_format:Y-m-d',
|
||||||
|
'country' => 'required|exists:countries,id',
|
||||||
|
'eventName' => 'required|max:100',
|
||||||
|
'members' => 'array',
|
||||||
|
'members.*' => 'integer|exists:members,id',
|
||||||
|
'type' => 'required|string',
|
||||||
|
'zipLocation' => 'required|string',
|
||||||
|
])->validate();
|
||||||
|
|
||||||
|
/** @var class-string<SolingenDocument> */
|
||||||
|
$type = $validated['type'];
|
||||||
|
|
||||||
|
return Tex::compile($type::fromRequest($validated));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ use App\Country;
|
||||||
use App\Member\Member;
|
use App\Member\Member;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Zoomyboy\Tex\Engine;
|
use Zoomyboy\Tex\Engine;
|
||||||
use Zoomyboy\Tex\Template;
|
use Zoomyboy\Tex\Template;
|
||||||
|
|
||||||
|
@ -33,14 +32,17 @@ class DvDocument extends ContributionDocument
|
||||||
.Carbon::parse($this->dateUntil)->format('d.m.Y');
|
.Carbon::parse($this->dateUntil)->format('d.m.Y');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromRequest(Request $request): self
|
/**
|
||||||
|
* @param array<string, string|int> $request
|
||||||
|
*/
|
||||||
|
public static function fromRequest(array $request): self
|
||||||
{
|
{
|
||||||
return new self(
|
return new self(
|
||||||
dateFrom: $request->dateFrom,
|
dateFrom: $request['dateFrom'],
|
||||||
dateUntil: $request->dateUntil,
|
dateUntil: $request['dateUntil'],
|
||||||
zipLocation: $request->zipLocation,
|
zipLocation: $request['zipLocation'],
|
||||||
country: Country::where('id', $request->country)->firstOrFail(),
|
country: Country::where('id', $request['country'])->firstOrFail(),
|
||||||
members: Member::whereIn('id', $request->members)->orderByRaw('lastname, firstname')->get()->toBase()->chunk(17),
|
members: Member::whereIn('id', $request['members'])->orderByRaw('lastname, firstname')->get()->toBase()->chunk(17),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ use App\Country;
|
||||||
use App\Member\Member;
|
use App\Member\Member;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Zoomyboy\Tex\Engine;
|
use Zoomyboy\Tex\Engine;
|
||||||
use Zoomyboy\Tex\Template;
|
use Zoomyboy\Tex\Template;
|
||||||
|
|
||||||
|
@ -38,15 +37,18 @@ class RemscheidDocument extends ContributionDocument
|
||||||
return Carbon::parse($this->dateUntil)->format('d.m.Y');
|
return Carbon::parse($this->dateUntil)->format('d.m.Y');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromRequest(Request $request): self
|
/**
|
||||||
|
* @param array<string, string|int> $request
|
||||||
|
*/
|
||||||
|
public static function fromRequest(array $request): self
|
||||||
{
|
{
|
||||||
[$leaders, $children] = Member::whereIn('id', $request->members)->orderByRaw('lastname, firstname')->get()->partition(fn ($member) => $member->isLeader());
|
[$leaders, $children] = Member::whereIn('id', $request['members'])->orderByRaw('lastname, firstname')->get()->partition(fn ($member) => $member->isLeader());
|
||||||
|
|
||||||
return new self(
|
return new self(
|
||||||
dateFrom: $request->dateFrom,
|
dateFrom: $request['dateFrom'],
|
||||||
dateUntil: $request->dateUntil,
|
dateUntil: $request['dateUntil'],
|
||||||
zipLocation: $request->zipLocation,
|
zipLocation: $request['zipLocation'],
|
||||||
country: Country::where('id', $request->country)->firstOrFail(),
|
country: Country::where('id', $request['country'])->firstOrFail(),
|
||||||
leaders: $leaders->values()->toBase()->chunk(6),
|
leaders: $leaders->values()->toBase()->chunk(6),
|
||||||
children: $children->values()->toBase()->chunk(20),
|
children: $children->values()->toBase()->chunk(20),
|
||||||
);
|
);
|
||||||
|
|
|
@ -5,7 +5,6 @@ namespace App\Contribution\Documents;
|
||||||
use App\Member\Member;
|
use App\Member\Member;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Zoomyboy\Tex\Engine;
|
use Zoomyboy\Tex\Engine;
|
||||||
use Zoomyboy\Tex\Template;
|
use Zoomyboy\Tex\Template;
|
||||||
|
@ -25,14 +24,17 @@ class SolingenDocument extends ContributionDocument
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromRequest(Request $request): static
|
/**
|
||||||
|
* @param array<string, mixed|int> $request
|
||||||
|
*/
|
||||||
|
public static function fromRequest(array $request): static
|
||||||
{
|
{
|
||||||
return new static(
|
return new static(
|
||||||
dateFrom: $request->dateFrom,
|
dateFrom: $request['dateFrom'],
|
||||||
dateUntil: $request->dateUntil,
|
dateUntil: $request['dateUntil'],
|
||||||
zipLocation: $request->zipLocation,
|
zipLocation: $request['zipLocation'],
|
||||||
members: $request->members,
|
members: $request['members'],
|
||||||
eventName: $request->eventName,
|
eventName: $request['eventName'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,11 @@
|
||||||
<template>
|
<template>
|
||||||
<form action="/contribution/generate" target="_BLANK" class="max-w-4xl w-full mx-auto gap-6 grid-cols-2 grid p-6">
|
<form target="_BLANK" class="max-w-4xl w-full mx-auto gap-6 grid-cols-2 grid p-6">
|
||||||
<f-text
|
<f-text id="eventName" name="eventName" class="col-span-2" v-model="values.eventName" label="Veranstaltungs-Name" required></f-text>
|
||||||
id="eventName"
|
|
||||||
name="eventName"
|
|
||||||
class="col-span-2"
|
|
||||||
v-model="values.eventName"
|
|
||||||
label="Veranstaltungs-Name"
|
|
||||||
required
|
|
||||||
></f-text>
|
|
||||||
<f-text id="dateFrom" name="dateFrom" type="date" v-model="values.dateFrom" label="Datum von" required></f-text>
|
<f-text id="dateFrom" name="dateFrom" type="date" v-model="values.dateFrom" label="Datum von" required></f-text>
|
||||||
<f-text
|
<f-text id="dateUntil" name="dateUntil" type="date" v-model="values.dateUntil" label="Datum bis" required></f-text>
|
||||||
id="dateUntil"
|
|
||||||
name="dateUntil"
|
|
||||||
type="date"
|
|
||||||
v-model="values.dateUntil"
|
|
||||||
label="Datum bis"
|
|
||||||
required
|
|
||||||
></f-text>
|
|
||||||
|
|
||||||
<f-text id="zipLocation" name="zipLocation" v-model="values.zipLocation" label="PLZ / Ort" required></f-text>
|
<f-text id="zipLocation" name="zipLocation" v-model="values.zipLocation" label="PLZ / Ort" required></f-text>
|
||||||
<f-select
|
<f-select id="country" :options="countries" name="country" v-model="values.country" label="Land" required></f-select>
|
||||||
id="country"
|
|
||||||
:options="countries"
|
|
||||||
name="country"
|
|
||||||
v-model="values.country"
|
|
||||||
label="Land"
|
|
||||||
required
|
|
||||||
></f-select>
|
|
||||||
|
|
||||||
<div class="border-gray-200 shadow shadow-primary-700 p-3 shadow-[0_0_4px_gray] col-span-2">
|
<div class="border-gray-200 shadow shadow-primary-700 p-3 shadow-[0_0_4px_gray] col-span-2">
|
||||||
<f-text
|
<f-text
|
||||||
|
@ -57,10 +36,10 @@
|
||||||
|
|
||||||
<button
|
<button
|
||||||
v-for="(compiler, index) in compilers"
|
v-for="(compiler, index) in compilers"
|
||||||
target="_BLANK"
|
@click.prevent="
|
||||||
type="submit"
|
values.type = compiler.class;
|
||||||
name="type"
|
submit();
|
||||||
:value="compiler.class"
|
"
|
||||||
class="btn btn-primary mt-3 inline-block"
|
class="btn btn-primary mt-3 inline-block"
|
||||||
v-text="compiler.title"
|
v-text="compiler.title"
|
||||||
></button>
|
></button>
|
||||||
|
@ -78,6 +57,7 @@ export default {
|
||||||
results: [],
|
results: [],
|
||||||
},
|
},
|
||||||
values: {
|
values: {
|
||||||
|
type: null,
|
||||||
members: [],
|
members: [],
|
||||||
event_name: '',
|
event_name: '',
|
||||||
dateFrom: '',
|
dateFrom: '',
|
||||||
|
@ -108,6 +88,10 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
submit() {
|
||||||
|
var payload = btoa(JSON.stringify(this.values));
|
||||||
|
window.open(`/contribution/generate?payload=${payload}`);
|
||||||
|
},
|
||||||
onSubmitMemberResult(selected) {
|
onSubmitMemberResult(selected) {
|
||||||
if (this.values.members.find((m) => m === selected.id) !== undefined) {
|
if (this.values.members.find((m) => m === selected.id) !== undefined) {
|
||||||
this.values.members = this.values.members.filter((m) => m === selected.id);
|
this.values.members = this.values.members.filter((m) => m === selected.id);
|
||||||
|
@ -127,6 +111,5 @@ export default {
|
||||||
this.onSubmitMemberResult(this.search.results[0]);
|
this.onSubmitMemberResult(this.search.results[0]);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Contribution;
|
namespace Tests\Feature\Contribution;
|
||||||
|
|
||||||
|
use App\Contribution\Documents\SolingenDocument;
|
||||||
use App\Country;
|
use App\Country;
|
||||||
use App\Member\Member;
|
use App\Member\Member;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
@ -29,6 +30,7 @@ class StoreTest extends TestCase
|
||||||
$member2 = Member::factory()->defaults()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Jane', 'lastname' => 'Muster']);
|
$member2 = Member::factory()->defaults()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Jane', 'lastname' => 'Muster']);
|
||||||
|
|
||||||
$response = $this->call('GET', '/contribution/generate', [
|
$response = $this->call('GET', '/contribution/generate', [
|
||||||
|
'payload' => base64_encode(json_encode([
|
||||||
'country' => $country->id,
|
'country' => $country->id,
|
||||||
'dateFrom' => '1991-06-15',
|
'dateFrom' => '1991-06-15',
|
||||||
'dateUntil' => '1991-06-16',
|
'dateUntil' => '1991-06-16',
|
||||||
|
@ -36,10 +38,32 @@ class StoreTest extends TestCase
|
||||||
'members' => [$member1->id, $member2->id],
|
'members' => [$member1->id, $member2->id],
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'zipLocation' => '42777 SG',
|
'zipLocation' => '42777 SG',
|
||||||
|
])),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertSessionDoesntHaveErrors();
|
$response->assertSessionDoesntHaveErrors();
|
||||||
$response->assertOk();
|
$response->assertOk();
|
||||||
Tex::assertCompiled($type, fn ($document) => $document->hasAllContent($bodyChecks));
|
Tex::assertCompiled($type, fn ($document) => $document->hasAllContent($bodyChecks));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItValidatesInput(): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami();
|
||||||
|
$country = Country::factory()->create();
|
||||||
|
$member1 = Member::factory()->defaults()->create();
|
||||||
|
|
||||||
|
$response = $this->call('GET', '/contribution/generate', [
|
||||||
|
'payload' => base64_encode(json_encode([
|
||||||
|
'country' => $country->id,
|
||||||
|
'dateFrom' => '',
|
||||||
|
'dateUntil' => '1991-06-16',
|
||||||
|
'eventName' => 'Super tolles Lager',
|
||||||
|
'members' => [$member1->id],
|
||||||
|
'type' => SolingenDocument::class,
|
||||||
|
'zipLocation' => '42777 SG',
|
||||||
|
])),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertSessionHasErrors('dateFrom');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue