Move setting to bill subroute

This commit is contained in:
Philipp Lang 2022-10-18 14:28:46 +02:00
parent 8a30a71964
commit dd07a68762
5 changed files with 74 additions and 66 deletions

View File

@ -1,7 +1,8 @@
<?php
namespace App\Setting;
namespace App\Bill;
use App\Setting\BillSettings;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
@ -16,14 +17,14 @@ class SettingIndexAction
public function handle(BillSettings $settings): array
{
return [
'bill_from_long' => $settings->from_long,
'bill_from' => $settings->from,
'bill_mobile' => $settings->mobile,
'bill_email' => $settings->email,
'bill_website' => $settings->website,
'bill_address' => $settings->address,
'bill_place' => $settings->place,
'bill_zip' => $settings->zip,
'from_long' => $settings->from_long,
'from' => $settings->from,
'mobile' => $settings->mobile,
'email' => $settings->email,
'website' => $settings->website,
'address' => $settings->address,
'place' => $settings->place,
'zip' => $settings->zip,
];
}

View File

@ -0,0 +1,41 @@
<?php
namespace App\Bill;
use App\Setting\BillSettings;
use Illuminate\Http\RedirectResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingSaveAction
{
use AsAction;
/**
* @param array<string, string> $input
*/
public function handle(array $input): void
{
$settings = app(BillSettings::class);
$settings->fill([
'from_long' => $input['from_long'] ?? '',
'from' => $input['from'] ?? '',
'mobile' => $input['mobile'] ?? '',
'email' => $input['email'] ?? '',
'website' => $input['website'] ?? '',
'address' => $input['address'] ?? '',
'place' => $input['place'] ?? '',
'zip' => $input['zip'] ?? '',
]);
$settings->save();
}
public function asController(ActionRequest $request): RedirectResponse
{
$this->handle($request->all());
return redirect()->back()->success('Einstellungen gespeichert');
}
}

View File

@ -1,34 +0,0 @@
<?php
namespace App\Setting;
use Illuminate\Http\RedirectResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingSaveAction
{
use AsAction;
public function handle(array $input): void
{
$settings = app(BillSettings::class);
$settings->from_long = $input['bill_from_long'] ?? '';
$settings->from = $input['bill_from'] ?? '';
$settings->mobile = $input['bill_mobile'] ?? '';
$settings->email = $input['bill_email'] ?? '';
$settings->website = $input['bill_website'] ?? '';
$settings->address = $input['bill_address'] ?? '';
$settings->place = $input['bill_place'] ?? '';
$settings->zip = $input['bill_zip'] ?? '';
$settings->save();
}
public function asController(ActionRequest $request): RedirectResponse
{
$this->handle($request->all());
return redirect()->back()->success('Einstellungen gespeichert');
}
}

View File

@ -1,5 +1,7 @@
<?php
use App\Bill\SettingIndexAction as BillSettingIndexAction;
use App\Bill\SettingSaveAction as BillSettingSaveAction;
use App\Contribution\ContributionController;
use App\Course\Controllers\CourseController;
use App\Http\Controllers\HomeController;
@ -15,8 +17,6 @@ use App\Payment\SendpaymentController;
use App\Payment\SubscriptionController;
use App\Pdf\MemberEfzController;
use App\Pdf\MemberPdfController;
use App\Setting\SettingIndexAction;
use App\Setting\SettingSaveAction;
Route::group(['namespace' => 'App\\Http\\Controllers'], function (): void {
Auth::routes(['register' => false]);
@ -36,8 +36,8 @@ Route::group(['middleware' => 'auth:web'], function (): void {
Route::get('/sendpayment', [SendpaymentController::class, 'create'])->name('sendpayment.create');
Route::get('/sendpayment/pdf', [SendpaymentController::class, 'send'])->name('sendpayment.pdf');
Route::apiResource('member.membership', MembershipController::class);
Route::get('setting', SettingIndexAction::class);
Route::post('setting', SettingSaveAction::class);
Route::get('setting/bill', BillSettingIndexAction::class);
Route::post('setting/bill', BillSettingSaveAction::class);
Route::resource('member.course', CourseController::class);
Route::get('/member/{member}/efz', MemberEfzController::class)->name('efz');
Route::get('/member/{member}/resync', MemberResyncController::class)->name('member.resync');

View File

@ -24,18 +24,18 @@ class SettingTest extends TestCase
'zip' => '12345',
]);
$response = $this->get('/setting');
$response = $this->get('/setting/bill');
$response->assertOk();
$this->assertInertiaHas([
'bill_from_long' => 'DPSG Stamm Muster',
'bill_from' => 'Stamm Muster',
'bill_mobile' => '+49 176 55555',
'bill_email' => 'max@muster.de',
'bill_website' => 'https://example.com',
'bill_address' => 'Musterstr 4',
'bill_place' => 'Solingen',
'bill_zip' => '12345',
'from_long' => 'DPSG Stamm Muster',
'from' => 'Stamm Muster',
'mobile' => '+49 176 55555',
'email' => 'max@muster.de',
'website' => 'https://example.com',
'address' => 'Musterstr 4',
'place' => 'Solingen',
'zip' => '12345',
], $response, 'data');
}
@ -43,18 +43,18 @@ class SettingTest extends TestCase
{
$this->withoutExceptionHandling()->login()->loginNami();
$response = $this->from('/setting')->post('/setting', [
'bill_from_long' => 'DPSG Stamm Muster',
'bill_from' => 'Stamm Muster',
'bill_mobile' => '+49 176 55555',
'bill_email' => 'max@muster.de',
'bill_website' => 'https://example.com',
'bill_address' => 'Musterstr 4',
'bill_place' => 'Solingen',
'bill_zip' => '12345',
$response = $this->from('/setting/bill')->post('/setting/bill', [
'from_long' => 'DPSG Stamm Muster',
'from' => 'Stamm Muster',
'mobile' => '+49 176 55555',
'email' => 'max@muster.de',
'website' => 'https://example.com',
'address' => 'Musterstr 4',
'place' => 'Solingen',
'zip' => '12345',
]);
$response->assertRedirect('/setting');
$response->assertRedirect('/setting/bill');
$settings = app(BillSettings::class);
$this->assertEquals('DPSG Stamm Muster', $settings->from_long);
}