- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees) - Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue) - Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts - Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs - Remove legacy and dead CSV employee import/export code - Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation - Add comprehensive Pest unit, integration, and feature test coverage
77 lines
2.4 KiB
PHP
77 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Queries\Products;
|
|
|
|
use App\Contracts\Query;
|
|
use App\Contracts\QueryInput;
|
|
use App\Dto\DiscountDto;
|
|
use App\Dto\RangeDto;
|
|
use App\Dto\TagDto;
|
|
use App\Models\Discount;
|
|
use App\Models\Product;
|
|
use App\Models\Range;
|
|
use App\Models\Tag;
|
|
use Domain\Enums\ProductBrand;
|
|
use Illuminate\Support\Collection;
|
|
use SortDirection;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Query<\App\Queries\Products\GetFoProductIndexPageQueryInput, \App\Queries\Products\GetFoProductIndexPageQueryOutput>
|
|
*/
|
|
final readonly class GetFoProductIndexPageQuery implements Query
|
|
{
|
|
#[\Override]
|
|
public function __invoke(QueryInput $input): GetFoProductIndexPageQueryOutput
|
|
{
|
|
Assert::isAOf($input, GetFoProductIndexPageQueryInput::class);
|
|
|
|
/** @var \Illuminate\Database\Eloquent\Builder<Product> $query */
|
|
$query = Product::query()
|
|
->with(['inco', 'validDiscount'])
|
|
->orderBy('order', SortDirection::Ascending)
|
|
->published();
|
|
|
|
$paginatedProducts = $query->paginate(
|
|
perPage: $input->pagination->pageSize()->value(),
|
|
page: $input->pagination->pageNumber()->value()
|
|
);
|
|
|
|
$publishedBrandStringList = Product::query()
|
|
->published()
|
|
->select(['brand'])
|
|
->distinct()
|
|
->pluck('brand');
|
|
|
|
/** @var Collection<int, ProductBrand> $brandList */
|
|
$brandList = Collection::make(ProductBrand::cases())->filter(
|
|
fn (ProductBrand $case) => $publishedBrandStringList->contains($case->value())
|
|
)->values();
|
|
|
|
$rangeList = Range::query()
|
|
->orderBy('order')
|
|
->get()
|
|
->map(fn (Range $range): RangeDto => RangeDto::fromModel($range));
|
|
|
|
$tagList = Tag::query()
|
|
->published()
|
|
->get()
|
|
->map(fn (Tag $tag): TagDto => TagDto::fromModel($tag));
|
|
|
|
$discountList = Discount::query()
|
|
->published()
|
|
->get()
|
|
->map(fn (Discount $discount): DiscountDto => DiscountDto::fromModel($discount));
|
|
|
|
return new GetFoProductIndexPageQueryOutput(
|
|
paginatedProducts: $paginatedProducts,
|
|
brandList: $brandList,
|
|
rangeList: $rangeList,
|
|
tagList: $tagList,
|
|
discountList: $discountList,
|
|
perPage: $input->pagination->pageSize()->value(),
|
|
);
|
|
}
|
|
}
|