-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add phpspec tests for paginator, improvements for editorial comments
- Loading branch information
1 parent
0ee97f3
commit 64398f3
Showing
16 changed files
with
406 additions
and
265 deletions.
There are no files selected for viewing
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
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
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
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
148 changes: 148 additions & 0 deletions
148
newscoop/src/Newscoop/ArticlesBundle/Controller/EditorialCommentsApiController.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
namespace Newscoop\ArticlesBundle\Controller; | ||
|
||
use FOS\RestBundle\Controller\FOSRestController; | ||
use FOS\RestBundle\Controller\Annotations\View; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Newscoop\ArticlesBundle\Form\Type\EditorialCommentType; | ||
use Newscoop\ArticlesBundle\Entity\EditorialComment; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Nelmio\ApiDocBundle\Annotation\ApiDoc; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; | ||
|
||
class EditorialCommentsApiController extends FOSRestController | ||
{ | ||
/** | ||
* Get editorial comments | ||
* | ||
* @ApiDoc( | ||
* statusCodes={ | ||
* 200="Returned when success", | ||
* } | ||
* ) | ||
* | ||
* @Route("/articles/{number}/{language}/editorial_comments.{_format}", defaults={"_format"="json"}, options={"expose"=true}, name="newscoop_gimme_articles_get_editorial_comment") | ||
* @Method("GET") | ||
* @View(serializerGroups={"list"}) | ||
*/ | ||
public function getCommentsAction(Request $request) | ||
{ | ||
$em = $this->container->get('em'); | ||
|
||
$editorialComments = $em->getRepository('Newscoop\ArticlesBundle\Entity\EditorialComment')->getAll(); | ||
|
||
$paginator = $this->get('newscoop.paginator.paginator_service'); | ||
$editorialComments = $paginator->paginate($editorialComments, array( | ||
'distinct' => false | ||
)); | ||
|
||
return $editorialComments; | ||
} | ||
|
||
/** | ||
* Create editorial comments | ||
* | ||
* @ApiDoc( | ||
* statusCodes={ | ||
* 201="Returned when editorial comment is created", | ||
* 404={ | ||
* "Returned when article is not found", | ||
* } | ||
* } | ||
* ) | ||
* | ||
* @Route("/articles/{number}/{language}/editorial_comments.{_format}", defaults={"_format"="json"}, options={"expose"=true}, name="newscoop_gimme_articles_create_editorial_comment") | ||
* @Method("POST") | ||
* @View(serializerGroups={"list"}) | ||
*/ | ||
public function createCommentAction(Request $request, $number, $language) | ||
{ | ||
$em = $this->container->get('em'); | ||
$article = $em->getRepository('Newscoop\Entity\Article') | ||
->getArticle($number, $language) | ||
->getOneOrNullResult(); | ||
|
||
return $this->processForm($request, $article); | ||
} | ||
|
||
/** | ||
* Edit editorial comments | ||
* | ||
* @ApiDoc( | ||
* statusCodes={ | ||
* 201="Returned when editorial comment is created", | ||
* 404={ | ||
* "Returned when article is not found", | ||
* } | ||
* } | ||
* ) | ||
* | ||
* @Route("/articles/{number}/{language}/editorial_comments/{commentId}.{_format}", defaults={"_format"="json"}, options={"expose"=true}, name="newscoop_gimme_articles_edit_editorial_comment") | ||
* @Method("POST") | ||
* @View(serializerGroups={"list"}) | ||
*/ | ||
public function editCommentAction(Request $request, $number, $language, $commentId) | ||
{ | ||
return $this->processForm($request, null, $commentId); | ||
} | ||
|
||
public function removeCommentAction(Request $request, $number, $language, $commentId) | ||
{ | ||
//return $this->processForm($request, null, $commentId); | ||
} | ||
|
||
/** | ||
* Process editorial comments form | ||
* | ||
* @param Request $request | ||
* | ||
* @return Form | ||
*/ | ||
private function processForm($request, $article = null, $comment = null) | ||
{ | ||
$em = $this->container->get('em'); | ||
$editorialCommentService = $this->container->get('newscoop.editorial_comments'); | ||
|
||
if (!$comment) { | ||
$statusCode = 201; | ||
} else { | ||
$statusCode = 200; | ||
$comment = $em->getRepository('Newscoop\ArticlesBundle\Entity\EditorialComment')->findOneBy(array('id' => 1)); | ||
|
||
if (!$comment) { | ||
throw new EntityNotFoundException('Result was not found.'); | ||
} | ||
} | ||
|
||
$form = $this->createForm(new EditorialCommentType(), array()); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isValid()) { | ||
$attributes = $form->getData(); | ||
$user = $this->container->get('user')->getCurrentUser(); | ||
|
||
$response = new Response(); | ||
$response->setStatusCode($statusCode); | ||
|
||
if ($statusCode == 201 && $article) { | ||
$comment = $editorialCommentService->create($attributes['comment'], $article, $user); | ||
|
||
// TODO: apply here new route | ||
/* $response->headers->set( | ||
'X-Location', | ||
$this->generateUrl('newscoop_gimme_attachments_getattachment', array( | ||
'number' => $comment->getId(), | ||
), true) | ||
);*/ | ||
} elseif ($statusCode == 200 && $comment) { | ||
$comment = $editorialCommentService->edit($attributes['comment'], $comment, $user); | ||
} | ||
|
||
return $response; | ||
} | ||
|
||
return $form; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
newscoop/src/Newscoop/ArticlesBundle/Form/Type/EditorialCommentType.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* @package Newscoop\ArticlesBundle | ||
* @author Paweł Mikołajczuk <pawel.mikolajczuk@sourcefabric.org> | ||
* @copyright 2014 Sourcefabric ź.u. | ||
* @license http://www.gnu.org/licenses/gpl-3.0.txt | ||
*/ | ||
|
||
namespace Newscoop\ArticlesBundle\Form\Type; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class EditorialCommentType extends AbstractType | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder->add('comment', null, array( | ||
'required' => true, | ||
)); | ||
$builder->add('resolved', 'checkbox', array( | ||
'required' => false, | ||
)); | ||
$builder->add('parent', 'number', array( | ||
'required' => false, | ||
)); | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'editorial_comment'; | ||
} | ||
|
||
public function setDefaultOptions(OptionsResolverInterface $resolver) | ||
{ | ||
$resolver->setDefaults(array( | ||
'csrf_protection' => false, | ||
)); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
newscoop/src/Newscoop/ArticlesBundle/Resources/config/routing.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
NewscoopArticlesBundleEditorialComments: | ||
resource: "@NewscoopArticlesBundle/Controller/EditorialCommentsApiController.php" | ||
prefix: / | ||
type: annotation |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
services: | ||
newscoop.editorial_comments: | ||
class: Newscoop\ArticlesBundle\Services\EditorialCommentsService | ||
arguments: ["@em"] |
35 changes: 0 additions & 35 deletions
35
newscoop/src/Newscoop/GimmeBundle/Tests/ContainerAwareUnitTestCase.php
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
newscoop/src/Newscoop/GimmeBundle/Tests/Newscoop/Gimme/PaginationTest.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.