mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
Port the stateless POST /api/meta-extraction endpoint from the dev branch onto current main. Extracts title/price/image from a product URL without persisting anything, auto-matching a store by domain and accepting an optional store override to test custom scrape strategies. The service is reimplemented against main's current ScrapeUrl/Store APIs (uses the existing domainFilter scope rather than dev's findByDomain helper chain) so it stays decoupled from dev's competing scraper refactor. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
33 lines
906 B
PHP
33 lines
906 B
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
/**
|
|
* @property array $resource
|
|
*/
|
|
class MetaExtractionResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
$store = data_get($this->resource, 'store');
|
|
|
|
return [
|
|
'title' => data_get($this->resource, 'title'),
|
|
'price' => data_get($this->resource, 'price'),
|
|
'image' => data_get($this->resource, 'image'),
|
|
'description' => data_get($this->resource, 'description'),
|
|
'availability' => data_get($this->resource, 'availability'),
|
|
/** @var array<string, StoreResource> */
|
|
'store' => $store ? new StoreResource($store) : (object) [],
|
|
];
|
|
}
|
|
}
|