Skip to content

Commit

Permalink
Merge pull request #826 from plural/reviews-endpoint
Browse files Browse the repository at this point in the history
Add basic API endpoint for retrieving card reviews.
  • Loading branch information
plural authored Jun 21, 2024
2 parents 523e48c + d92cdd5 commit 1e681e6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/AppBundle/Controller/PublicApi20Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,46 @@ public function mwlAction(Request $request)
}, $request);
}

/**
* Get all Review data
*
* @ApiDoc(
* section="Reviews",
* resource=true,
* description="Get all the reviews data by card title.",
* parameters={
* },
* )
*/
public function reviewsAction(Request $request)
{
$rulings = $this->entityManager->getRepository('AppBundle:Review')->findAll();

$out = [];
foreach($rulings as $r) {
$comments = [];
foreach($r->getComments() as $comment) {
array_push($comments, [
'user' => $comment->getAuthor()->getUsername(),
'comment' => str_replace('\r', '', $r->getText()),
'date_create' => $comment->getDateCreation()->format('c'),
'date_update' => $comment->getDateupdate()->format('c'),
]);
}
array_push($out, [
'id' => $r->getId(),
'title' => $r->getCard()->getTitle(),
'user' => $r->getUser()->getUsername(),
'ruling' => str_replace('\r', '', $r->getRawText()),
'votes' => $r->getNbvotes(),
'comments' => $comments,
'date_create' => $r->getDateCreation()->format('c'),
'date_update' => $r->getDateupdate()->format('c'),
]);
}
return $this->prepareResponseFromCache($out, count($out), new DateTime(), $request);
}

/**
* Get all Ruling data
*
Expand Down
6 changes: 6 additions & 0 deletions src/AppBundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,12 @@ api_public_mwl:
defaults:
_controller: AppBundle:PublicApi20:mwl

api_public_reviews:
path: /api/2.0/public/reviews
methods: [GET]
defaults:
_controller: AppBundle:PublicApi20:reviews

api_public_rulings:
path: /api/2.0/public/rulings
methods: [GET]
Expand Down

0 comments on commit 1e681e6

Please sign in to comment.