Created
July 16, 2015 12:21
-
-
Save AhmedSamy/7ca2b0e78e0eabadcdef to your computer and use it in GitHub Desktop.
paramconvertor FOS REST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @Annotations\View(statusCode=200) | |
* @Annotations\Route("/reviews") | |
* @Annotations\QueryParam(name="place_id", strict=true, requirements="\d+", description="Place id "), | |
* @Annotations\QueryParam(name="offset", strict=true, requirements="\d+", default="0", description="offset (default is 0)"), | |
* @Annotations\QueryParam(name="limit", strict=true, requirements="\d+", default="5", description="limit (default is 5)"), | |
* @ApiDoc( | |
* statusCodes={ | |
* 200="Returned when successful", | |
* 400="Returned with invalid parameters" | |
* }, | |
* documentation="Get reviews for specific place", | |
* description="Get reviews for specific place", | |
* section="Place", | |
* resource=true | |
* ) | |
* @param ParamFetcher $paramFetcher | |
* | |
* @return \Symfony\Component\HttpFoundation\Response | |
*/ | |
public function getReviewsByPlaceAction(ParamFetcher $paramFetcher) | |
{ | |
$placeId = $paramFetcher->get('place_id', true); | |
$offset = $paramFetcher->get('offset', true); | |
$limit = $paramFetcher->get('limit', true); | |
$place = $this->placeRepository->find($placeId); | |
if (!$place instanceof Place) { | |
throw new NotFoundHttpException(sprintf("no place found for id: %s", $placeId)); | |
} | |
//@TODO make better way for serialization | |
$reviews = new ArrayCollection($place->getReviews()->slice($offset, $limit)); | |
return [ | |
'reviews' => [ | |
'count' => $reviews->count(), | |
'items' => $reviews->getValues(), | |
] | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment