1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-07-12 16:58:37 +00:00

first draft of hypermedia implementation

This commit is contained in:
Nicolas Lœuillet 2015-02-20 11:45:38 +01:00
parent 73b7744383
commit 0f00688096
7 changed files with 166 additions and 31 deletions

View file

@ -5,10 +5,12 @@ namespace Wallabag\CoreBundle\Controller;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag;
use Wallabag\CoreBundle\Service\Extractor;
use Hateoas\HateoasBuilder;
class WallabagRestController extends Controller
{
@ -72,6 +74,9 @@ class WallabagRestController extends Controller
throw $this->createNotFoundException();
}
$hateoas = HateoasBuilder::create()->build();
$json = $hateoas->serialize($entries, 'json');
return $entries;
}
@ -87,7 +92,10 @@ class WallabagRestController extends Controller
*/
public function getEntryAction(Entry $entry)
{
return $entry;
$hateoas = HateoasBuilder::create()->build();
$json = $hateoas->serialize($entry, 'json');
return new Response($json, 200, array('application/json'));
}
/**

View file

@ -4,17 +4,21 @@ namespace Wallabag\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Hateoas\Configuration\Annotation as Hateoas;
use JMS\Serializer\Annotation\XmlRoot;
/**
* Entry
*
* @XmlRoot("entry")
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
* @ORM\Table(name="entry")
* @ORM\HasLifecycleCallbacks()
*
* @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
*/
class Entry
{
/** @Serializer\XmlAttribute */
/**
* @var integer
*

View file

@ -7,6 +7,8 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;
/**
* User
@ -14,12 +16,14 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\Table(name="user")
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @ExclusionPolicy("all")
*/
class User implements AdvancedUserInterface, \Serializable
{
/**
* @var integer
*
* @Expose
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")

View file

@ -102,8 +102,7 @@ class EntryRepository extends EntityRepository
public function findEntries($userId, $isArchived = null, $isStarred = null, $isDeleted = null, $sort = 'created', $order = 'ASC')
{
$qb = $this->createQueryBuilder('e')
->leftJoin('e.user', 'u')
->where('u.id =:userId')->setParameter('userId', $userId);
->where('e.user =:userId')->setParameter('userId', $userId);
if (null !== $isArchived) {
$qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', (bool) $isArchived);