66
77use HiEvents \DomainObjects \EventDomainObject ;
88use HiEvents \DomainObjects \Generated \ProductDomainObjectAbstract ;
9- use HiEvents \DomainObjects \TaxAndFeesDomainObject ;
109use HiEvents \DomainObjects \ProductPriceDomainObject ;
10+ use HiEvents \DomainObjects \TaxAndFeesDomainObject ;
1111use HiEvents \Http \Actions \BaseAction ;
1212use HiEvents \Repository \Interfaces \ProductRepositoryInterface ;
1313use HiEvents \Resources \Product \ProductResource ;
1414use Illuminate \Http \JsonResponse ;
15+ use Illuminate \Http \Response ;
1516
1617class GetProductAction extends BaseAction
1718{
@@ -22,16 +23,22 @@ public function __construct(ProductRepositoryInterface $productRepository)
2223 $ this ->productRepository = $ productRepository ;
2324 }
2425
25- public function __invoke (int $ eventId , int $ productId ): JsonResponse
26+ public function __invoke (int $ eventId , int $ productId ): JsonResponse | Response
2627 {
2728 $ this ->isActionAuthorized ($ eventId , EventDomainObject::class);
2829
29- return $ this -> resourceResponse (ProductResource::class, $ this ->productRepository
30+ $ product = $ this ->productRepository
3031 ->loadRelation (TaxAndFeesDomainObject::class)
3132 ->loadRelation (ProductPriceDomainObject::class)
3233 ->findFirstWhere ([
3334 ProductDomainObjectAbstract::EVENT_ID => $ eventId ,
3435 ProductDomainObjectAbstract::ID => $ productId ,
35- ]));
36+ ]);
37+
38+ if ($ product === null ) {
39+ return $ this ->notFoundResponse ();
40+ }
41+
42+ return $ this ->resourceResponse (ProductResource::class, $ product );
3643 }
3744}
0 commit comments