refactor(cqs): complete Fo/PageController, BO FormRequest input mappings, and decouple Directories
This commit is contained in:
parent
aad9586ca9
commit
9ebf712170
33 changed files with 472 additions and 224 deletions
|
|
@ -5,11 +5,9 @@ declare(strict_types=1);
|
|||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Actions\Discounts\CreateDiscount;
|
||||
use App\Actions\Discounts\CreateDiscountInput;
|
||||
use App\Actions\Discounts\DeleteDiscount;
|
||||
use App\Actions\Discounts\DeleteDiscountInput;
|
||||
use App\Actions\Discounts\UpdateDiscount;
|
||||
use App\Actions\Discounts\UpdateDiscountInput;
|
||||
use App\Contracts\Executor;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Discounts\StoreDiscountRequest;
|
||||
|
|
@ -69,13 +67,7 @@ class DiscountsController extends Controller
|
|||
|
||||
$discount = $this->executor->execute(
|
||||
$action,
|
||||
new CreateDiscountInput(
|
||||
type: $request->toDiscountType(),
|
||||
value: $request->toDiscountValue(),
|
||||
is_old_price_displayed: $request->boolean('is_old_price_displayed'),
|
||||
period: $request->toDatePeriod(),
|
||||
associatedProductsIds: $request->toAssociatedProductsIds(),
|
||||
),
|
||||
$request->toCreateDiscountInput(),
|
||||
);
|
||||
|
||||
return to_route('bo.discounts.edit', $discount)
|
||||
|
|
@ -107,14 +99,7 @@ class DiscountsController extends Controller
|
|||
|
||||
$this->executor->execute(
|
||||
$action,
|
||||
new UpdateDiscountInput(
|
||||
discount: $discount,
|
||||
type: $request->toDiscountType(),
|
||||
value: $request->toDiscountValue(),
|
||||
is_old_price_displayed: $request->boolean('is_old_price_displayed'),
|
||||
period: $request->toDatePeriod(),
|
||||
associatedProductsIds: $request->toAssociatedProductsIds(),
|
||||
),
|
||||
$request->toUpdateDiscountInput($discount),
|
||||
);
|
||||
|
||||
return to_route('bo.discounts.edit', $discount)
|
||||
|
|
|
|||
|
|
@ -5,11 +5,9 @@ declare(strict_types=1);
|
|||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Actions\Faqs\CreateFaq;
|
||||
use App\Actions\Faqs\CreateFaqInput;
|
||||
use App\Actions\Faqs\DeleteFaq;
|
||||
use App\Actions\Faqs\DeleteFaqInput;
|
||||
use App\Actions\Faqs\UpdateFaq;
|
||||
use App\Actions\Faqs\UpdateFaqInput;
|
||||
use App\Contracts\Executor;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Faqs\StoreFaqRequest;
|
||||
|
|
@ -60,10 +58,7 @@ class FaqsController extends Controller
|
|||
|
||||
$faq = $this->executor->execute(
|
||||
$action,
|
||||
new CreateFaqInput(
|
||||
question: $request->string('question')->value(),
|
||||
answer: $request->string('answer')->value(),
|
||||
),
|
||||
$request->toCreateFaqInput(),
|
||||
);
|
||||
|
||||
return to_route('bo.faqs.edit', $faq)
|
||||
|
|
@ -85,11 +80,7 @@ class FaqsController extends Controller
|
|||
|
||||
$this->executor->execute(
|
||||
$action,
|
||||
new UpdateFaqInput(
|
||||
faq: $faq,
|
||||
question: $request->string('question')->value(),
|
||||
answer: $request->string('answer')->value(),
|
||||
),
|
||||
$request->toUpdateFaqInput($faq),
|
||||
);
|
||||
|
||||
return to_route('bo.faqs.edit', $faq)
|
||||
|
|
|
|||
|
|
@ -5,13 +5,11 @@ declare(strict_types=1);
|
|||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Actions\Pages\UpdatePage;
|
||||
use App\Actions\Pages\UpdatePageInput;
|
||||
use App\Contracts\Executor;
|
||||
use App\Dto\PageDto;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Pages\UpdatePageRequest as PagesUpdatePageRequest;
|
||||
use App\Models\Page;
|
||||
use Domain\Models\ValueObjects\SeoMetadata;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Str;
|
||||
|
|
@ -38,15 +36,7 @@ class PageController extends Controller
|
|||
|
||||
$this->executor->execute(
|
||||
$action,
|
||||
new UpdatePageInput(
|
||||
page: $page,
|
||||
seo: new SeoMetadata(
|
||||
title: $request->string('seo_title')->value(),
|
||||
description: $request->string('seo_description')->value(),
|
||||
),
|
||||
title: $request->filled('title') ? $request->string('title')->value() : null,
|
||||
content: $request->string('content')->value(),
|
||||
),
|
||||
$request->toUpdatePageInput($page),
|
||||
);
|
||||
|
||||
return to_route('bo.pages.edit', $page->slug->value())
|
||||
|
|
|
|||
|
|
@ -5,11 +5,9 @@ declare(strict_types=1);
|
|||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Actions\PickupExceptions\CreatePickupException;
|
||||
use App\Actions\PickupExceptions\CreatePickupExceptionInput;
|
||||
use App\Actions\PickupExceptions\DeletePickupException;
|
||||
use App\Actions\PickupExceptions\DeletePickupExceptionInput;
|
||||
use App\Actions\PickupExceptions\UpdatePickupException;
|
||||
use App\Actions\PickupExceptions\UpdatePickupExceptionInput;
|
||||
use App\Contracts\Executor;
|
||||
use App\Dto\PickupExceptionDto;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
|
@ -57,12 +55,7 @@ class PickupExceptionsController extends Controller
|
|||
|
||||
$pickupException = $this->executor->execute(
|
||||
$action,
|
||||
new CreatePickupExceptionInput(
|
||||
date: $request->string('date')->value(),
|
||||
label: $request->string('label')->value(),
|
||||
repeatable: $request->boolean('repeatable'),
|
||||
repeat_frequency: $request->toRepeatFrequency(),
|
||||
),
|
||||
$request->toCreatePickupExceptionInput(),
|
||||
);
|
||||
|
||||
return to_route('bo.pickup-exceptions.edit', $pickupException)
|
||||
|
|
@ -86,13 +79,7 @@ class PickupExceptionsController extends Controller
|
|||
|
||||
$this->executor->execute(
|
||||
$action,
|
||||
new UpdatePickupExceptionInput(
|
||||
pickupException: $pickupException,
|
||||
date: $request->string('date')->value(),
|
||||
label: $request->string('label')->value(),
|
||||
repeatable: $request->boolean('repeatable'),
|
||||
repeat_frequency: $request->toRepeatFrequency(),
|
||||
),
|
||||
$request->toUpdatePickupExceptionInput($pickupException),
|
||||
);
|
||||
|
||||
return to_route('bo.pickup-exceptions.edit', $pickupException)
|
||||
|
|
|
|||
|
|
@ -5,11 +5,9 @@ declare(strict_types=1);
|
|||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Actions\Ranges\CreateRange;
|
||||
use App\Actions\Ranges\CreateRangeInput;
|
||||
use App\Actions\Ranges\DeleteRange;
|
||||
use App\Actions\Ranges\DeleteRangeInput;
|
||||
use App\Actions\Ranges\UpdateRange;
|
||||
use App\Actions\Ranges\UpdateRangeInput;
|
||||
use App\Contracts\Executor;
|
||||
use App\Dto\RangeDto;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
|
@ -20,7 +18,6 @@ use App\Queries\Ranges\GetPaginatedRangesQuery;
|
|||
use App\Queries\Ranges\GetPaginatedRangesQueryInput;
|
||||
use App\Traits\Controllers\ChangesModelOrder;
|
||||
use App\Traits\Controllers\TogglesModelStatus;
|
||||
use Domain\Models\ValueObjects\PictureMetadata;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -63,21 +60,9 @@ class RangesController extends Controller
|
|||
{
|
||||
$this->authorize('create', Range::class);
|
||||
|
||||
$pictureAlt = $request->filled('picture_alt') ? $request->string('picture_alt')->value() : null;
|
||||
$pictureTitle = $request->filled('picture_title') ? $request->string('picture_title')->value() : null;
|
||||
|
||||
$range = $this->executor->execute(
|
||||
$action,
|
||||
new CreateRangeInput(
|
||||
name: $request->string('name')->value(),
|
||||
description: $request->filled('description') ? $request->string('description')->value() : null,
|
||||
picture: $request->file('picture'),
|
||||
pictureMetadata: new PictureMetadata(
|
||||
alt: $pictureAlt,
|
||||
title: $pictureTitle,
|
||||
),
|
||||
status: $request->boolean('status'),
|
||||
),
|
||||
$request->toCreateRangeInput(),
|
||||
);
|
||||
|
||||
return to_route('bo.ranges.edit', $range)
|
||||
|
|
@ -99,22 +84,9 @@ class RangesController extends Controller
|
|||
{
|
||||
$this->authorize('update', $range);
|
||||
|
||||
$pictureAlt = $request->filled('picture_alt') ? $request->string('picture_alt')->value() : null;
|
||||
$pictureTitle = $request->filled('picture_title') ? $request->string('picture_title')->value() : null;
|
||||
|
||||
$this->executor->execute(
|
||||
$action,
|
||||
new UpdateRangeInput(
|
||||
range: $range,
|
||||
name: $request->string('name')->value(),
|
||||
description: $request->filled('description') ? $request->string('description')->value() : null,
|
||||
picture: $request->file('picture'),
|
||||
pictureMetadata: new PictureMetadata(
|
||||
alt: $pictureAlt,
|
||||
title: $pictureTitle,
|
||||
),
|
||||
status: $request->boolean('status'),
|
||||
),
|
||||
$request->toUpdateRangeInput($range),
|
||||
);
|
||||
|
||||
return to_route('bo.ranges.edit', $range)
|
||||
|
|
|
|||
|
|
@ -5,13 +5,10 @@ declare(strict_types=1);
|
|||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Actions\Shops\CreateShop;
|
||||
use App\Actions\Shops\CreateShopInput;
|
||||
use App\Actions\Shops\DeleteShop;
|
||||
use App\Actions\Shops\DeleteShopInput;
|
||||
use App\Actions\Shops\UpdateShop;
|
||||
use App\Actions\Shops\UpdateShopInput;
|
||||
use App\Actions\Shops\UpdateShopPickupExceptions;
|
||||
use App\Actions\Shops\UpdateShopPickupExceptionsInput;
|
||||
use App\Contracts\Executor;
|
||||
use App\Dto\ShopDto;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
|
@ -64,20 +61,9 @@ class ShopsController extends Controller
|
|||
{
|
||||
$this->authorize('create', Shop::class);
|
||||
|
||||
$coordinates = $request->toCoordinates();
|
||||
$phone = $request->toPhoneNumber();
|
||||
|
||||
$shop = $this->executor->execute(
|
||||
$action,
|
||||
new CreateShopInput(
|
||||
name: $request->string('name')->value(),
|
||||
address: $request->string('address')->value(),
|
||||
postcode: $request->string('postcode')->value(),
|
||||
city: $request->string('city')->value(),
|
||||
phone: $phone,
|
||||
coordinates: $coordinates,
|
||||
default: $request->boolean('default'),
|
||||
),
|
||||
$request->toCreateShopInput(),
|
||||
);
|
||||
|
||||
return to_route('bo.shops.edit', $shop)
|
||||
|
|
@ -99,21 +85,9 @@ class ShopsController extends Controller
|
|||
{
|
||||
$this->authorize('update', $shop);
|
||||
|
||||
$coordinates = $request->toCoordinates();
|
||||
$phone = $request->toPhoneNumber();
|
||||
|
||||
$this->executor->execute(
|
||||
$action,
|
||||
new UpdateShopInput(
|
||||
shop: $shop,
|
||||
name: $request->string('name')->value(),
|
||||
address: $request->string('address')->value(),
|
||||
postcode: $request->string('postcode')->value(),
|
||||
city: $request->string('city')->value(),
|
||||
phone: $phone,
|
||||
coordinates: $coordinates,
|
||||
default: $request->boolean('default'),
|
||||
),
|
||||
$request->toUpdateShopInput($shop),
|
||||
);
|
||||
|
||||
return to_route('bo.shops.edit', $shop)
|
||||
|
|
@ -163,10 +137,7 @@ class ShopsController extends Controller
|
|||
|
||||
$this->executor->execute(
|
||||
$action,
|
||||
new UpdateShopPickupExceptionsInput(
|
||||
shop: $shop,
|
||||
syncData: $request->toSyncData(),
|
||||
),
|
||||
$request->toUpdateShopPickupExceptionsInput($shop),
|
||||
);
|
||||
|
||||
return back()->with('success', trans('crud.messages.has_been_updated', [
|
||||
|
|
|
|||
|
|
@ -5,11 +5,9 @@ declare(strict_types=1);
|
|||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Actions\Slides\CreateSlide;
|
||||
use App\Actions\Slides\CreateSlideInput;
|
||||
use App\Actions\Slides\DeleteSlide;
|
||||
use App\Actions\Slides\DeleteSlideInput;
|
||||
use App\Actions\Slides\UpdateSlide;
|
||||
use App\Actions\Slides\UpdateSlideInput;
|
||||
use App\Contracts\Executor;
|
||||
use App\Dto\SlideDto;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
|
@ -20,11 +18,9 @@ use App\Queries\Slides\GetPaginatedSlidesQuery;
|
|||
use App\Queries\Slides\GetPaginatedSlidesQueryInput;
|
||||
use App\Traits\Controllers\ChangesModelOrder;
|
||||
use App\Traits\Controllers\TogglesModelStatus;
|
||||
use Domain\Models\ValueObjects\DatePeriod;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SlidesController extends Controller
|
||||
|
|
@ -41,13 +37,11 @@ class SlidesController extends Controller
|
|||
{
|
||||
$this->authorize('viewAny', Slide::class);
|
||||
|
||||
$pagination = $request->pagination();
|
||||
|
||||
$slides = $this->executor->execute(
|
||||
$query,
|
||||
new GetPaginatedSlidesQueryInput(
|
||||
pagination: $pagination,
|
||||
)
|
||||
pagination: $request->pagination(),
|
||||
),
|
||||
);
|
||||
|
||||
return view('bo.slides.index', compact('slides'));
|
||||
|
|
@ -64,25 +58,9 @@ class SlidesController extends Controller
|
|||
{
|
||||
$this->authorize('create', Slide::class);
|
||||
|
||||
$period = new DatePeriod(
|
||||
start: $request->filled('date_start') ? new \DateTimeImmutable($request->string('date_start')->value()) : null,
|
||||
end: $request->filled('date_end') ? new \DateTimeImmutable($request->string('date_end')->value()) : null,
|
||||
);
|
||||
|
||||
$slide = $this->executor->execute(
|
||||
$action,
|
||||
new CreateSlideInput(
|
||||
title: $request->string('title')->value(),
|
||||
text: $request->filled('text') ? $request->string('text')->value() : null,
|
||||
picture: $this->resolvePicture($request),
|
||||
pictureAlt: $request->filled('picture_alt') ? $request->string('picture_alt')->value() : null,
|
||||
pictureTitle: $request->filled('picture_title') ? $request->string('picture_title')->value() : null,
|
||||
link: $request->filled('link') ? $request->string('link')->value() : null,
|
||||
linkLabel: $request->filled('link_label') ? $request->string('link_label')->value() : null,
|
||||
linkNewTab: $request->boolean('link_new_tab'),
|
||||
connected: $request->boolean('connected'),
|
||||
period: $period,
|
||||
),
|
||||
$request->toCreateSlideInput(),
|
||||
);
|
||||
|
||||
return to_route('bo.slides.edit', $slide)
|
||||
|
|
@ -104,26 +82,9 @@ class SlidesController extends Controller
|
|||
{
|
||||
$this->authorize('update', $slide);
|
||||
|
||||
$period = new DatePeriod(
|
||||
start: $request->filled('date_start') ? new \DateTimeImmutable($request->string('date_start')->value()) : null,
|
||||
end: $request->filled('date_end') ? new \DateTimeImmutable($request->string('date_end')->value()) : null,
|
||||
);
|
||||
|
||||
$this->executor->execute(
|
||||
$action,
|
||||
new UpdateSlideInput(
|
||||
slide: $slide,
|
||||
title: $request->string('title')->value(),
|
||||
text: $request->filled('text') ? $request->string('text')->value() : null,
|
||||
picture: $this->resolvePicture($request),
|
||||
pictureAlt: $request->filled('picture_alt') ? $request->string('picture_alt')->value() : null,
|
||||
pictureTitle: $request->filled('picture_title') ? $request->string('picture_title')->value() : null,
|
||||
link: $request->filled('link') ? $request->string('link')->value() : null,
|
||||
linkLabel: $request->filled('link_label') ? $request->string('link_label')->value() : null,
|
||||
linkNewTab: $request->boolean('link_new_tab'),
|
||||
connected: $request->boolean('connected'),
|
||||
period: $period,
|
||||
),
|
||||
$request->toUpdateSlideInput($slide),
|
||||
);
|
||||
|
||||
return to_route('bo.slides.edit', $slide)
|
||||
|
|
@ -146,16 +107,4 @@ class SlidesController extends Controller
|
|||
'model' => Str::ucfirst(trans_choice('models.classes.slides', 1)),
|
||||
]));
|
||||
}
|
||||
|
||||
private function resolvePicture(StoreSlideRequest | UpdateSlideRequest $request): UploadedFile | string | null
|
||||
{
|
||||
$file = $request->file('picture');
|
||||
if ($file instanceof UploadedFile) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
return $request->has('picture') && is_string($request->input('picture'))
|
||||
? $request->input('picture')
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,9 @@ declare(strict_types=1);
|
|||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Actions\Tags\CreateTag;
|
||||
use App\Actions\Tags\CreateTagInput;
|
||||
use App\Actions\Tags\DeleteTag;
|
||||
use App\Actions\Tags\DeleteTagInput;
|
||||
use App\Actions\Tags\UpdateTag;
|
||||
use App\Actions\Tags\UpdateTagInput;
|
||||
use App\Contracts\Executor;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Tags\StoreTagRequest;
|
||||
|
|
@ -63,10 +61,7 @@ class TagsController extends Controller
|
|||
|
||||
$tag = $this->executor->execute(
|
||||
$action,
|
||||
new CreateTagInput(
|
||||
label: $request->string('label')->value(),
|
||||
status: $request->boolean('status'),
|
||||
),
|
||||
$request->toCreateTagInput(),
|
||||
);
|
||||
|
||||
return to_route('bo.tags.edit', $tag)
|
||||
|
|
@ -88,11 +83,7 @@ class TagsController extends Controller
|
|||
|
||||
$this->executor->execute(
|
||||
$action,
|
||||
new UpdateTagInput(
|
||||
tag: $tag,
|
||||
label: $request->string('label')->value(),
|
||||
status: $request->boolean('status'),
|
||||
),
|
||||
$request->toUpdateTagInput($tag),
|
||||
);
|
||||
|
||||
return to_route('bo.tags.edit', $tag)
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Controllers\Fo\Auth;
|
||||
|
||||
use App\Contracts\Directories\CustomerDirectory;
|
||||
use App\Contracts\Executor;
|
||||
use App\Exceptions\CustomerNotEmployedException;
|
||||
use App\Models\Customer;
|
||||
use App\Queries\Customers\GetCustomerByEmailQuery;
|
||||
use App\Queries\Customers\GetCustomerByEmailQueryInput;
|
||||
use Domain\Models\ValueObjects\Email;
|
||||
use Domain\Models\ValueObjects\Entities\ShopperId;
|
||||
use Domain\Services\ShopperService;
|
||||
use Illuminate\Contracts\Auth\PasswordBroker;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
|
@ -24,8 +26,8 @@ class ForgotPasswordController extends AuthController
|
|||
}
|
||||
|
||||
public function __construct(
|
||||
private readonly CustomerDirectory $customerDirectory,
|
||||
private readonly ShopperService $shopperService
|
||||
private readonly Executor $executor,
|
||||
private readonly ShopperService $shopperService,
|
||||
) {
|
||||
$this->middleware('guest:frontend');
|
||||
parent::__construct();
|
||||
|
|
@ -36,15 +38,17 @@ class ForgotPasswordController extends AuthController
|
|||
return view('fo.auth.passwords.email');
|
||||
}
|
||||
|
||||
public function sendResetLinkEmail(Request $request): JsonResponse | RedirectResponse
|
||||
public function sendResetLinkEmail(Request $request, GetCustomerByEmailQuery $query): JsonResponse | RedirectResponse
|
||||
{
|
||||
$this->validateEmail($request);
|
||||
|
||||
$customer = $this->customerDirectory
|
||||
->getCustomerByEmail(new Email($request->string('email')->toString()));
|
||||
$shopperId = $this->executor->execute(
|
||||
$query,
|
||||
new GetCustomerByEmailQueryInput(new Email($request->string('email')->toString())),
|
||||
);
|
||||
|
||||
if ($customer instanceof Customer) {
|
||||
$shopper = $this->shopperService->getShopperFor($customer->getId());
|
||||
if ($shopperId instanceof ShopperId) {
|
||||
$shopper = $this->shopperService->getShopperFor($shopperId);
|
||||
if (! $shopper || ! $shopper->isActive()) {
|
||||
throw new CustomerNotEmployedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@ declare(strict_types=1);
|
|||
namespace App\Http\Controllers\Fo\Pages;
|
||||
|
||||
use App\Contracts\Executor;
|
||||
use App\Contracts\QueryInputEmpty;
|
||||
use App\Dto\PageDto;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Faq;
|
||||
use App\Queries\Faqs\GetFaqsQuery;
|
||||
use App\Queries\Pages\GetPageQuery;
|
||||
use App\Queries\Pages\GetPageQueryInput;
|
||||
use Domain\Enums\StaticPageSlug;
|
||||
|
|
@ -18,6 +19,7 @@ class PageController extends Controller
|
|||
{
|
||||
public function __construct(
|
||||
private readonly Executor $executor,
|
||||
private readonly GetPageQuery $getPageQuery,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -48,12 +50,13 @@ class PageController extends Controller
|
|||
));
|
||||
}
|
||||
|
||||
public function faq(): View
|
||||
public function faq(GetFaqsQuery $getFaqsQuery): View
|
||||
{
|
||||
$page = $this->getPageBySlug(StaticPageSlug::FAQ);
|
||||
$faqs = Faq::query()
|
||||
->orderBy('order', 'asc')
|
||||
->get();
|
||||
$page = $this->getPageBySlug(StaticPageSlug::FAQ);
|
||||
$faqs = $this->executor->execute(
|
||||
$getFaqsQuery,
|
||||
new QueryInputEmpty()
|
||||
);
|
||||
|
||||
return view('fo.pages.faq', compact(
|
||||
'faqs',
|
||||
|
|
@ -67,7 +70,7 @@ class PageController extends Controller
|
|||
$pageSlugInput = new GetPageQueryInput($slug);
|
||||
|
||||
return $this->executor->execute(
|
||||
new GetPageQuery(),
|
||||
$this->getPageQuery,
|
||||
$pageSlugInput
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\Discounts;
|
||||
|
||||
use App\Actions\Discounts\CreateDiscountInput;
|
||||
use Domain\Enums\DiscountType;
|
||||
use Domain\Models\ValueObjects\DatePeriod;
|
||||
use Domain\Models\ValueObjects\DiscountValue;
|
||||
|
|
@ -22,6 +23,17 @@ class StoreDiscountRequest extends FormRequest
|
|||
) {
|
||||
}
|
||||
|
||||
public function toCreateDiscountInput(): CreateDiscountInput
|
||||
{
|
||||
return new CreateDiscountInput(
|
||||
type: $this->toDiscountType(),
|
||||
value: $this->toDiscountValue(),
|
||||
is_old_price_displayed: $this->boolean('is_old_price_displayed'),
|
||||
period: $this->toDatePeriod(),
|
||||
associatedProductsIds: $this->toAssociatedProductsIds(),
|
||||
);
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->authService->check();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,20 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\Discounts;
|
||||
|
||||
use App\Actions\Discounts\UpdateDiscountInput;
|
||||
use App\Models\Discount;
|
||||
|
||||
class UpdateDiscountRequest extends StoreDiscountRequest
|
||||
{
|
||||
public function toUpdateDiscountInput(Discount $discount): UpdateDiscountInput
|
||||
{
|
||||
return new UpdateDiscountInput(
|
||||
discount: $discount,
|
||||
type: $this->toDiscountType(),
|
||||
value: $this->toDiscountValue(),
|
||||
is_old_price_displayed: $this->boolean('is_old_price_displayed'),
|
||||
period: $this->toDatePeriod(),
|
||||
associatedProductsIds: $this->toAssociatedProductsIds(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\Faqs;
|
||||
|
||||
use App\Actions\Faqs\CreateFaqInput;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
||||
|
||||
|
|
@ -36,4 +37,12 @@ class StoreFaqRequest extends FormRequest
|
|||
'answer' => trans('validation.custom.attributes.answer'),
|
||||
];
|
||||
}
|
||||
|
||||
public function toCreateFaqInput(): CreateFaqInput
|
||||
{
|
||||
return new CreateFaqInput(
|
||||
question: $this->string('question')->value(),
|
||||
answer: $this->string('answer')->value(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,17 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\Faqs;
|
||||
|
||||
use App\Actions\Faqs\UpdateFaqInput;
|
||||
use App\Models\Faq;
|
||||
|
||||
class UpdateFaqRequest extends StoreFaqRequest
|
||||
{
|
||||
public function toUpdateFaqInput(Faq $faq): UpdateFaqInput
|
||||
{
|
||||
return new UpdateFaqInput(
|
||||
faq: $faq,
|
||||
question: $this->string('question')->value(),
|
||||
answer: $this->string('answer')->value(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\Pages;
|
||||
|
||||
use App\Actions\Pages\UpdatePageInput;
|
||||
use App\Models\Page;
|
||||
use Domain\Models\ValueObjects\SeoMetadata;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
||||
|
||||
|
|
@ -19,6 +22,19 @@ class UpdatePageRequest extends FormRequest
|
|||
return $this->authService->check();
|
||||
}
|
||||
|
||||
public function toUpdatePageInput(Page $page): UpdatePageInput
|
||||
{
|
||||
return new UpdatePageInput(
|
||||
page: $page,
|
||||
seo: new SeoMetadata(
|
||||
title: $this->string('seo_title')->value(),
|
||||
description: $this->string('seo_description')->value(),
|
||||
),
|
||||
title: $this->filled('title') ? $this->string('title')->value() : null,
|
||||
content: $this->string('content')->value(),
|
||||
);
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public function rules(): array
|
||||
{
|
||||
|
|
@ -38,7 +54,6 @@ class UpdatePageRequest extends FormRequest
|
|||
'seo_description' => trans('validation.custom.attributes.seo_description'),
|
||||
'title' => trans('validation.attributes.title'),
|
||||
'content' => trans('validation.attributes.content'),
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\PickupExceptions;
|
||||
|
||||
use App\Actions\PickupExceptions\CreatePickupExceptionInput;
|
||||
use Domain\Enums\RepeatFrequency;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
|
|
@ -30,6 +31,16 @@ class StorePickupExceptionRequest extends FormRequest
|
|||
: RepeatFrequency::from($this->string('repeat_frequency')->value());
|
||||
}
|
||||
|
||||
public function toCreatePickupExceptionInput(): CreatePickupExceptionInput
|
||||
{
|
||||
return new CreatePickupExceptionInput(
|
||||
date: $this->string('date')->value(),
|
||||
label: $this->string('label')->value(),
|
||||
repeatable: $this->boolean('repeatable'),
|
||||
repeat_frequency: $this->toRepeatFrequency(),
|
||||
);
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,19 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\PickupExceptions;
|
||||
|
||||
use App\Actions\PickupExceptions\UpdatePickupExceptionInput;
|
||||
use App\Models\PickupException;
|
||||
|
||||
class UpdatePickupExceptionRequest extends StorePickupExceptionRequest
|
||||
{
|
||||
public function toUpdatePickupExceptionInput(PickupException $pickupException): UpdatePickupExceptionInput
|
||||
{
|
||||
return new UpdatePickupExceptionInput(
|
||||
pickupException: $pickupException,
|
||||
date: $this->string('date')->value(),
|
||||
label: $this->string('label')->value(),
|
||||
repeatable: $this->boolean('repeatable'),
|
||||
repeat_frequency: $this->toRepeatFrequency(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\Ranges;
|
||||
|
||||
use App\Actions\Ranges\CreateRangeInput;
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Domain\Models\ValueObjects\PictureMetadata;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
||||
|
||||
|
|
@ -67,4 +69,21 @@ class StoreRangeRequest extends FormRequest
|
|||
'picture_title' => trans('validation.custom.attributes.picture_title'),
|
||||
];
|
||||
}
|
||||
|
||||
public function toCreateRangeInput(): CreateRangeInput
|
||||
{
|
||||
$pictureAlt = $this->filled('picture_alt') ? $this->string('picture_alt')->value() : null;
|
||||
$pictureTitle = $this->filled('picture_title') ? $this->string('picture_title')->value() : null;
|
||||
|
||||
return new CreateRangeInput(
|
||||
name: $this->string('name')->value(),
|
||||
description: $this->filled('description') ? $this->string('description')->value() : null,
|
||||
picture: $this->file('picture'),
|
||||
pictureMetadata: new PictureMetadata(
|
||||
alt: $pictureAlt,
|
||||
title: $pictureTitle,
|
||||
),
|
||||
status: $this->boolean('status'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,27 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\Ranges;
|
||||
|
||||
use App\Actions\Ranges\UpdateRangeInput;
|
||||
use App\Models\Range;
|
||||
use Domain\Models\ValueObjects\PictureMetadata;
|
||||
|
||||
class UpdateRangeRequest extends StoreRangeRequest
|
||||
{
|
||||
public function toUpdateRangeInput(Range $range): UpdateRangeInput
|
||||
{
|
||||
$pictureAlt = $this->filled('picture_alt') ? $this->string('picture_alt')->value() : null;
|
||||
$pictureTitle = $this->filled('picture_title') ? $this->string('picture_title')->value() : null;
|
||||
|
||||
return new UpdateRangeInput(
|
||||
range: $range,
|
||||
name: $this->string('name')->value(),
|
||||
description: $this->filled('description') ? $this->string('description')->value() : null,
|
||||
picture: $this->file('picture'),
|
||||
pictureMetadata: new PictureMetadata(
|
||||
alt: $pictureAlt,
|
||||
title: $pictureTitle,
|
||||
),
|
||||
status: $this->boolean('status'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\Shops;
|
||||
|
||||
use App\Actions\Shops\CreateShopInput;
|
||||
use Domain\Models\ValueObjects\Coordinates;
|
||||
use Domain\Models\ValueObjects\PhoneNumber as DomainPhoneNumber;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
|
@ -17,6 +18,19 @@ class StoreShopRequest extends FormRequest
|
|||
) {
|
||||
}
|
||||
|
||||
public function toCreateShopInput(): CreateShopInput
|
||||
{
|
||||
return new CreateShopInput(
|
||||
name: $this->string('name')->value(),
|
||||
address: $this->string('address')->value(),
|
||||
postcode: $this->string('postcode')->value(),
|
||||
city: $this->string('city')->value(),
|
||||
phone: $this->toPhoneNumber(),
|
||||
coordinates: $this->toCoordinates(),
|
||||
default: $this->boolean('default'),
|
||||
);
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->authService->check();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\Shops;
|
||||
|
||||
use App\Actions\Shops\UpdateShopPickupExceptionsInput;
|
||||
use App\Models\Shop;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Str;
|
||||
|
|
@ -16,6 +18,14 @@ class UpdateShopPickupExceptionsRequest extends FormRequest
|
|||
) {
|
||||
}
|
||||
|
||||
public function toUpdateShopPickupExceptionsInput(Shop $shop): UpdateShopPickupExceptionsInput
|
||||
{
|
||||
return new UpdateShopPickupExceptionsInput(
|
||||
shop: $shop,
|
||||
syncData: $this->toSyncData(),
|
||||
);
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->authService->check();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,22 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\Shops;
|
||||
|
||||
use App\Actions\Shops\UpdateShopInput;
|
||||
use App\Models\Shop;
|
||||
|
||||
class UpdateShopRequest extends StoreShopRequest
|
||||
{
|
||||
public function toUpdateShopInput(Shop $shop): UpdateShopInput
|
||||
{
|
||||
return new UpdateShopInput(
|
||||
shop: $shop,
|
||||
name: $this->string('name')->value(),
|
||||
address: $this->string('address')->value(),
|
||||
postcode: $this->string('postcode')->value(),
|
||||
city: $this->string('city')->value(),
|
||||
phone: $this->toPhoneNumber(),
|
||||
coordinates: $this->toCoordinates(),
|
||||
default: $this->boolean('default'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,11 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\Slides;
|
||||
|
||||
use App\Actions\Slides\CreateSlideInput;
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Domain\Models\ValueObjects\DatePeriod;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
||||
|
||||
|
|
@ -23,6 +26,42 @@ class StoreSlideRequest extends FormRequest
|
|||
return $this->authService->check();
|
||||
}
|
||||
|
||||
public function resolvePicture(): UploadedFile | string | null
|
||||
{
|
||||
$file = $this->file('picture');
|
||||
if ($file instanceof UploadedFile) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
return $this->has('picture') && is_string($this->input('picture'))
|
||||
? $this->input('picture')
|
||||
: null;
|
||||
}
|
||||
|
||||
public function toDatePeriod(): DatePeriod
|
||||
{
|
||||
return new DatePeriod(
|
||||
start: $this->filled('date_start') ? new \DateTimeImmutable($this->string('date_start')->value()) : null,
|
||||
end: $this->filled('date_end') ? new \DateTimeImmutable($this->string('date_end')->value()) : null,
|
||||
);
|
||||
}
|
||||
|
||||
public function toCreateSlideInput(): CreateSlideInput
|
||||
{
|
||||
return new CreateSlideInput(
|
||||
title: $this->string('title')->value(),
|
||||
text: $this->filled('text') ? $this->string('text')->value() : null,
|
||||
picture: $this->resolvePicture(),
|
||||
pictureAlt: $this->filled('picture_alt') ? $this->string('picture_alt')->value() : null,
|
||||
pictureTitle: $this->filled('picture_title') ? $this->string('picture_title')->value() : null,
|
||||
link: $this->filled('link') ? $this->string('link')->value() : null,
|
||||
linkLabel: $this->filled('link_label') ? $this->string('link_label')->value() : null,
|
||||
linkNewTab: $this->boolean('link_new_tab'),
|
||||
connected: $this->boolean('connected'),
|
||||
period: $this->toDatePeriod(),
|
||||
);
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,25 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\Slides;
|
||||
|
||||
use App\Actions\Slides\UpdateSlideInput;
|
||||
use App\Models\Slide;
|
||||
|
||||
class UpdateSlideRequest extends StoreSlideRequest
|
||||
{
|
||||
public function toUpdateSlideInput(Slide $slide): UpdateSlideInput
|
||||
{
|
||||
return new UpdateSlideInput(
|
||||
slide: $slide,
|
||||
title: $this->string('title')->value(),
|
||||
text: $this->filled('text') ? $this->string('text')->value() : null,
|
||||
picture: $this->resolvePicture(),
|
||||
pictureAlt: $this->filled('picture_alt') ? $this->string('picture_alt')->value() : null,
|
||||
pictureTitle: $this->filled('picture_title') ? $this->string('picture_title')->value() : null,
|
||||
link: $this->filled('link') ? $this->string('link')->value() : null,
|
||||
linkLabel: $this->filled('link_label') ? $this->string('link_label')->value() : null,
|
||||
linkNewTab: $this->boolean('link_new_tab'),
|
||||
connected: $this->boolean('connected'),
|
||||
period: $this->toDatePeriod(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\Tags;
|
||||
|
||||
use App\Actions\Tags\CreateTagInput;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
||||
|
||||
|
|
@ -44,4 +45,12 @@ class StoreTagRequest extends FormRequest
|
|||
'status' => trans('validation.custom.attributes.status'),
|
||||
];
|
||||
}
|
||||
|
||||
public function toCreateTagInput(): CreateTagInput
|
||||
{
|
||||
return new CreateTagInput(
|
||||
label: $this->string('label')->value(),
|
||||
status: $this->boolean('status'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,17 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Http\Requests\Bo\Tags;
|
||||
|
||||
use App\Actions\Tags\UpdateTagInput;
|
||||
use App\Models\Tag;
|
||||
|
||||
class UpdateTagRequest extends StoreTagRequest
|
||||
{
|
||||
public function toUpdateTagInput(Tag $tag): UpdateTagInput
|
||||
{
|
||||
return new UpdateTagInput(
|
||||
tag: $tag,
|
||||
label: $this->string('label')->value(),
|
||||
status: $this->boolean('status'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
29
app/Queries/Customers/GetCustomerByEmailQuery.php
Normal file
29
app/Queries/Customers/GetCustomerByEmailQuery.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Customers;
|
||||
|
||||
use App\Contracts\Query;
|
||||
use App\Contracts\QueryInput;
|
||||
use App\Models\Customer;
|
||||
use Domain\Models\ValueObjects\Entities\ShopperId;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Query<\App\Queries\Customers\GetCustomerByEmailQueryInput, \Domain\Models\ValueObjects\Entities\ShopperId|null>
|
||||
*/
|
||||
final readonly class GetCustomerByEmailQuery implements Query
|
||||
{
|
||||
public function __invoke(QueryInput $input): ?ShopperId
|
||||
{
|
||||
Assert::isInstanceOf($input, GetCustomerByEmailQueryInput::class);
|
||||
|
||||
/** @var Customer|null $customer */
|
||||
$customer = Customer::query()
|
||||
->where('email', $input->email->value)
|
||||
->first();
|
||||
|
||||
return $customer?->getId();
|
||||
}
|
||||
}
|
||||
16
app/Queries/Customers/GetCustomerByEmailQueryInput.php
Normal file
16
app/Queries/Customers/GetCustomerByEmailQueryInput.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Customers;
|
||||
|
||||
use App\Contracts\QueryInput;
|
||||
use Domain\Models\ValueObjects\Email;
|
||||
|
||||
final readonly class GetCustomerByEmailQueryInput implements QueryInput
|
||||
{
|
||||
public function __construct(
|
||||
public Email $email,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Queries\Dashboard;
|
||||
|
||||
use App\Contracts\Directories\EmployeeDirectory;
|
||||
use App\Contracts\Query;
|
||||
use App\Contracts\QueryInput;
|
||||
use App\Models\Employee;
|
||||
use App\Services\StatsService;
|
||||
use Domain\Enums\StatsCustomerType;
|
||||
use Domain\Enums\StatsShopType;
|
||||
|
|
@ -18,7 +18,6 @@ use Webmozart\Assert\Assert;
|
|||
final readonly class GetBoDashboardQuery implements Query
|
||||
{
|
||||
public function __construct(
|
||||
private EmployeeDirectory $employeeDirectory,
|
||||
private StatsService $statsService,
|
||||
) {
|
||||
}
|
||||
|
|
@ -39,8 +38,8 @@ final readonly class GetBoDashboardQuery implements Query
|
|||
$statsCustomer = $this->statsService->getStats(StatsCustomerType::cases(), $input->start, $input->end);
|
||||
}
|
||||
|
||||
$employeeCount = $this->employeeDirectory->countActiveEmployees();
|
||||
$customersLinkedToEmployeeCount = $this->employeeDirectory->countActiveRegisteredEmployees();
|
||||
$employeeCount = Employee::query()->active()->count();
|
||||
$customersLinkedToEmployeeCount = Employee::query()->active()->whereHas('customer')->count();
|
||||
|
||||
return new GetBoDashboardQueryOutput(
|
||||
employeeCount: $employeeCount,
|
||||
|
|
|
|||
35
app/Queries/Faqs/GetFaqsQuery.php
Normal file
35
app/Queries/Faqs/GetFaqsQuery.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Queries\Faqs;
|
||||
|
||||
use App\Contracts\Query;
|
||||
use App\Contracts\QueryInput;
|
||||
use App\Contracts\QueryInputEmpty;
|
||||
use App\Dto\FaqDto;
|
||||
use App\Models\Faq;
|
||||
use Illuminate\Support\Collection;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @implements \App\Contracts\Query<\App\Contracts\QueryInputEmpty, \Illuminate\Support\Collection<int, \App\Dto\FaqDto>>
|
||||
*/
|
||||
final readonly class GetFaqsQuery implements Query
|
||||
{
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection<int, \App\Dto\FaqDto>
|
||||
*/
|
||||
public function __invoke(QueryInput $input): Collection
|
||||
{
|
||||
Assert::isAOf(
|
||||
$input,
|
||||
QueryInputEmpty::class,
|
||||
);
|
||||
|
||||
return Faq::query()
|
||||
->orderBy('order', 'asc')
|
||||
->get()
|
||||
->map(fn (Faq $faq): FaqDto => FaqDto::fromModel($faq));
|
||||
}
|
||||
}
|
||||
|
|
@ -4,34 +4,29 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Contracts\Directories\OrderDirectory;
|
||||
use App\Dto\OrderDto;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Order;
|
||||
use Domain\Models\ValueObjects\Pagination;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Domain\Models\ValueObjects\Matricule;
|
||||
|
||||
class OrderService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly OrderDirectory $orderDirectory
|
||||
) {
|
||||
}
|
||||
|
||||
/** @return \Illuminate\Pagination\LengthAwarePaginator<int,\App\Models\Order> */
|
||||
public function paginateOrdersFor(Customer $customer, Pagination $pagination): LengthAwarePaginator
|
||||
{
|
||||
return $this->orderDirectory->getPaginatedOrdersOf(
|
||||
$customer,
|
||||
$pagination,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public function isOrderOwnedBy(Order | OrderDto $order, Customer $customer): bool
|
||||
{
|
||||
return $this->orderDirectory
|
||||
->findOf($customer, Uuid::fromString((string) $order->id)) !== null;
|
||||
/** @var \Domain\Models\ValueObjects\Matricule|string|null $employeeMatricule */
|
||||
$employeeMatricule = $customer->employee()->value('matricule');
|
||||
|
||||
if ($employeeMatricule === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$matriculeValue = $employeeMatricule instanceof Matricule
|
||||
? $employeeMatricule->value
|
||||
: (string) $employeeMatricule;
|
||||
|
||||
return Order::query()
|
||||
->where('id', (string) $order->id)
|
||||
->where('employee_matricule', $matriculeValue)
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Models\Customer;
|
||||
use App\Queries\Customers\GetCustomerByEmailQuery;
|
||||
use App\Queries\Customers\GetCustomerByEmailQueryInput;
|
||||
use Domain\Models\ValueObjects\Email;
|
||||
use Domain\Models\ValueObjects\Entities\ShopperId;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Shared\ValueObjects\CrmHashcode;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
describe('GetCustomerByEmailQuery', function (): void {
|
||||
it('returns ShopperId when customer with email exists', function (): void {
|
||||
// GIVEN
|
||||
$email = new Email('john.doe@example.com');
|
||||
$customer = new Customer(['email' => $email]);
|
||||
$customer->hashcode = new CrmHashcode(Uuid::uuid4());
|
||||
$customer->save();
|
||||
|
||||
$query = app(GetCustomerByEmailQuery::class);
|
||||
$input = new GetCustomerByEmailQueryInput($email);
|
||||
|
||||
// WHEN
|
||||
$result = $query($input);
|
||||
|
||||
// THEN
|
||||
expect($result)->toBeInstanceOf(ShopperId::class)
|
||||
->and($result->value->toString())->toBe($customer->id);
|
||||
});
|
||||
|
||||
it('returns null when customer with email does not exist', function (): void {
|
||||
// GIVEN
|
||||
$email = new Email('nonexistent@example.com');
|
||||
$query = app(GetCustomerByEmailQuery::class);
|
||||
$input = new GetCustomerByEmailQueryInput($email);
|
||||
|
||||
// WHEN
|
||||
$result = $query($input);
|
||||
|
||||
// THEN
|
||||
expect($result)->toBeNull();
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Contracts\QueryInputEmpty;
|
||||
use App\Dto\FaqDto;
|
||||
use App\Models\Faq;
|
||||
use App\Queries\Faqs\GetFaqsQuery;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
describe('GetFaqsQuery', function (): void {
|
||||
it('returns a collection of FaqDto instances ordered by order', function (): void {
|
||||
// GIVEN
|
||||
$faq2 = new Faq();
|
||||
$faq2->question = 'Second question?';
|
||||
$faq2->answer = 'Second answer.';
|
||||
$faq2->order = 2;
|
||||
$faq2->save();
|
||||
|
||||
$faq1 = new Faq();
|
||||
$faq1->question = 'First question?';
|
||||
$faq1->answer = 'First answer.';
|
||||
$faq1->order = 1;
|
||||
$faq1->save();
|
||||
|
||||
$query = app(GetFaqsQuery::class);
|
||||
|
||||
// WHEN
|
||||
$faqs = $query(new QueryInputEmpty());
|
||||
|
||||
// THEN
|
||||
expect($faqs)->toBeInstanceOf(Collection::class)
|
||||
->and($faqs)->toHaveCount(2)
|
||||
->and($faqs->first())->toBeInstanceOf(FaqDto::class)
|
||||
->and($faqs->first()->question)->toBe('First question?')
|
||||
->and($faqs->last()->question)->toBe('Second question?');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue