Refactor Catalog API: Remove Create Catalog Item Endpoint and Update Related Logic
- Removed the "Create Catalog" endpoint from the Postman collection. - Updated the CatalogController to handle tenant-specific catalog items based on active events. - Refactored CatalogItem model to automatically set event_id based on tenant's active_event_id during creation. - Deleted StoreCatalogItemRequest and CatalogItemResource as they are no longer needed. - Updated various services and controllers to utilize the new tenant-based catalog item retrieval logic. - Added tests to ensure that catalog reads are limited to items associated with the active event.
This commit is contained in:
@@ -238,7 +238,7 @@ class CatalogService
|
||||
$startsWithPattern = "{$normalizedTerm}%";
|
||||
|
||||
$paginator = CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->forTenantCatalog($tenant)
|
||||
->whereAvailable()
|
||||
->where(function (Builder $query) use ($containsPattern): void {
|
||||
$query
|
||||
@@ -287,7 +287,7 @@ class CatalogService
|
||||
int $page,
|
||||
): LengthAwarePaginator {
|
||||
return CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->forTenantCatalog($tenant)
|
||||
->where('category_id', $category->id)
|
||||
->whereAvailable()
|
||||
->with([
|
||||
@@ -369,6 +369,8 @@ class CatalogService
|
||||
$componentItem = CatalogItem::query()
|
||||
->whereKey($catalogItemId)
|
||||
->where('tenant_code', $bundle->tenant_code)
|
||||
->when($bundle->event_id !== null, fn (Builder $query): Builder => $query
|
||||
->where('event_id', $bundle->event_id))
|
||||
->first();
|
||||
|
||||
if ($componentItem === null) {
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Domains\Commerce\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Commerce\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Commerce\Catalog\Models\FeaturedGroup;
|
||||
use App\Domains\Commerce\Catalog\Resources\CatalogFeaturedItemResource;
|
||||
use App\Domains\Core\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
@@ -19,10 +20,10 @@ class FeaturedGroupService
|
||||
private readonly CatalogItemAllowanceService $allowances,
|
||||
) {}
|
||||
|
||||
public function itemsResponse(FeaturedGroup $featuredGroup, int $page, ?int $userId = null): array
|
||||
public function itemsResponse(FeaturedGroup $featuredGroup, Tenant $tenant, int $page, ?int $userId = null): array
|
||||
{
|
||||
if ($featuredGroup->group_layout !== GroupLayout::Paginated) {
|
||||
$query = $this->itemsQuery($featuredGroup);
|
||||
$query = $this->itemsQuery($featuredGroup, $tenant);
|
||||
|
||||
if ($featuredGroup->group_layout === GroupLayout::Single) {
|
||||
$query->limit(1);
|
||||
@@ -35,7 +36,7 @@ class FeaturedGroupService
|
||||
return CatalogFeaturedItemResource::collection($items)->resolve();
|
||||
}
|
||||
|
||||
$paginator = $this->paginateItems($featuredGroup, $page);
|
||||
$paginator = $this->paginateItems($featuredGroup, $tenant, $page);
|
||||
$this->attachGroup($paginator->getCollection(), $featuredGroup);
|
||||
$this->allowances->attach($paginator->getCollection(), $userId);
|
||||
|
||||
@@ -45,10 +46,10 @@ class FeaturedGroupService
|
||||
}
|
||||
|
||||
/** @return Builder<CatalogItem> */
|
||||
private function itemsQuery(FeaturedGroup $featuredGroup): Builder
|
||||
private function itemsQuery(FeaturedGroup $featuredGroup, Tenant $tenant): Builder
|
||||
{
|
||||
$query = CatalogItem::query()
|
||||
->where('catalog_items.tenant_code', $featuredGroup->tenant_code)
|
||||
->forTenantCatalog($tenant)
|
||||
->whereAvailable()
|
||||
->where(function (Builder $query): void {
|
||||
$query
|
||||
@@ -90,9 +91,10 @@ class FeaturedGroupService
|
||||
|
||||
private function paginateItems(
|
||||
FeaturedGroup $featuredGroup,
|
||||
Tenant $tenant,
|
||||
int $page,
|
||||
): LengthAwarePaginator {
|
||||
$paginator = $this->itemsQuery($featuredGroup)->paginate(
|
||||
$paginator = $this->itemsQuery($featuredGroup, $tenant)->paginate(
|
||||
perPage: self::ITEMS_PER_PAGE,
|
||||
pageName: 'page',
|
||||
page: $page,
|
||||
|
||||
Reference in New Issue
Block a user