Skip to content

Commit

Permalink
Merge pull request #103 from heseya/feature/SK-923
Browse files Browse the repository at this point in the history
Added product_ids
  • Loading branch information
daVitekPL authored Dec 2, 2024
2 parents a6e7c63 + 07e5f58 commit 6477b3f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/Domain/Manufacturer/Models/Manufacturer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ public function products(): HasMany
{
return $this->hasMany(Product::class);
}

/**
* @return array<int, string>
*/
public function productIds(): array
{
return $this->products()->pluck('products.id')->toArray();
}
}
3 changes: 1 addition & 2 deletions src/Domain/Manufacturer/Resources/ManufacturerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Domain\Manufacturer\Resources;

use App\Http\Resources\AddressResource;
use App\Http\Resources\ProductWithoutSalesResource;
use App\Http\Resources\Resource;
use Illuminate\Http\Request;

Expand All @@ -32,7 +31,7 @@ public function base(Request $request): array
public function view(Request $request): array
{
return [
'products' => ProductWithoutSalesResource::collection($this->resource->products),
'product_ids' => $this->resource->productIds(),
];
}
}
8 changes: 4 additions & 4 deletions tests/Feature/Manufacturers/ManufacturerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function testCreate(string $user): void
])
->assertCreated()
->assertJsonFragment([
'id' => $product->getKey(),
$product->getKey(),
]);
}

Expand Down Expand Up @@ -194,13 +194,13 @@ public function testUpdate(string $user): void
])
->assertOk()
->assertJsonFragment([
'id' => $product->getKey(),
$product->getKey(),
])
->assertJsonFragment([
'id' => $newProduct->getKey(),
$newProduct->getKey(),
])
->assertJsonMissing([
'id' => $oldProduct->getKey(),
$oldProduct->getKey(),
]);
}

Expand Down

0 comments on commit 6477b3f

Please sign in to comment.