Skip to content

Commit

Permalink
Added content/article/search-code endpoint
Browse files Browse the repository at this point in the history
Returns ID by code (guid)
  • Loading branch information
IvanJelicSF authored Oct 9, 2024
1 parent 3429f4b commit e74e624
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/SWP/Bundle/ContentBundle/Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,30 @@ public function getAction($id): SingleResourceResponseInterface {
$article = $this->articleProvider->getOneById($id);

if (null === $article) {
throw new NotFoundHttpException('Article was not found.');
throw new NotFoundHttpException('Article was not found');
}

return new SingleResourceResponse($article);
}

/**
* @Route("/api/{version}/content/article/search-code", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles_by_code", requirements={"code"=".+"})
*/
public function getByCodeAction(Request $request): SingleResourceResponseInterface {
// Extract parameters from the request
$code = $request->query->get('code', '');
//$tenantCode = $request->query->get('tenant_code', '');

//var_dump($code, $tenantCode);

$article = $this->entityManager->createQuery('SELECT a.id FROM SWP\Bundle\ContentBundle\Model\Article a where a.code = :code')
->setParameter('code', $code)
//->setParameter('tenant_code', $tenantCode)
->setMaxResults(1)
->getOneOrNullResult();

if (null === $article) {
throw new NotFoundHttpException('Article was not found');
}

return new SingleResourceResponse($article);
Expand Down

0 comments on commit e74e624

Please sign in to comment.