33namespace HiEvents \Http \Actions \Questions ;
44
55use HiEvents \DomainObjects \EventDomainObject ;
6+ use HiEvents \DomainObjects \Generated \QuestionDomainObjectAbstract ;
67use HiEvents \DomainObjects \ProductDomainObject ;
8+ use HiEvents \Exceptions \ResourceNotFoundException ;
79use HiEvents \Http \Actions \BaseAction ;
810use HiEvents \Repository \Interfaces \QuestionRepositoryInterface ;
911use HiEvents \Resources \Question \QuestionResource ;
@@ -19,14 +21,24 @@ public function __construct(QuestionRepositoryInterface $questionRepository)
1921 $ this ->questionRepository = $ questionRepository ;
2022 }
2123
24+ /**
25+ * @throws ResourceNotFoundException
26+ */
2227 public function __invoke (Request $ request , int $ eventId , int $ questionId ): JsonResponse
2328 {
2429 $ this ->isActionAuthorized ($ eventId , EventDomainObject::class);
2530
26- $ questions = $ this ->questionRepository
31+ $ question = $ this ->questionRepository
2732 ->loadRelation (ProductDomainObject::class)
28- ->findById ($ questionId );
33+ ->findFirstWhere ([
34+ QuestionDomainObjectAbstract::ID => $ questionId ,
35+ QuestionDomainObjectAbstract::EVENT_ID => $ eventId ,
36+ ]);
2937
30- return $ this ->resourceResponse (QuestionResource::class, $ questions );
38+ if ($ question === null ) {
39+ throw new ResourceNotFoundException (__ ('Question not found ' ));
40+ }
41+
42+ return $ this ->resourceResponse (QuestionResource::class, $ question );
3143 }
3244}
0 commit comments