Skip to content

Commit

Permalink
Finish 'feature/fos-rest'
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Young committed Sep 16, 2016
2 parents f276452 + c687b05 commit 856552e
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 178 deletions.
1 change: 1 addition & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function registerBundles()
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new FOS\RestBundle\FOSRestBundle(),
new FOS\UserBundle\FOSUserBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Darkbluesun\GoldfishBundle\DarkbluesunGoldfishBundle(),
Expand Down
4 changes: 4 additions & 0 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ fos_user:
form:
type: goldfish_user_profile

fos_rest:
routing_loader:
default_format: json

# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"angular-smart-table": "^2.1.8"
},
"resolutions": {
"angular": "1.4.8",
"angular": "~1.4.6",
"angular-route": "~1.4.6"
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"incenteev/composer-parameter-handler": "~2.0",
"jms/serializer-bundle": "^1.1",
"cspoo/swiftmailer-mailgun-bundle": "dev-master",
"friendsofsymfony/rest-bundle": "^2.1",
"friendsofsymfony/user-bundle": "~2.0@dev"
},
"require-dev": {
Expand Down
184 changes: 182 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
<?php

namespace Darkbluesun\GoldfishBundle\Controller;
namespace Darkbluesun\GoldfishBundle\Controller\API;

use FOS\RestBundle\Routing\ClassResourceInterface;
use JMS\Serializer\SerializationContext;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Darkbluesun\GoldfishBundle\Entity\Workspace;
use Darkbluesun\GoldfishBundle\Entity\Client;
use Darkbluesun\GoldfishBundle\Entity\ClientComment;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Permission\MaskBuilder;

/**
* Client controller.
*
* @Route("/api/clients")
*/
class ClientController extends Controller
class ClientController extends Controller implements ClassResourceInterface
{
/**
* Lists all Client entities.
*
* @Route("/", name="clients")
* @Method("GET")
*/
public function getcAction()
public function cgetAction()
{
$user = $this->get('security.context')->getToken()->getUser();
$workspace = $user->getWorkspace();
Expand All @@ -52,22 +40,14 @@ public function getcAction()
}

/**
* Gets an existing Client entity.
* @Security("is_granted('VIEW', client)")
* @Route("/{id}", name="clients_get")
* @Method("GET")
*/
public function getAction(Client $client)
{
return new Response($this->get('serializer')->serialize($client,'json',SerializationContext::create()->setGroups(['client_details'])));
}
/**
* Creates a new Client entity.
*
* @Route("", name="clients_create")
* @Method("POST")
*/
public function createAction(Request $request)

public function postAction(Request $request)
{
$serializer = $this->get('serializer');
$em = $this->getDoctrine()->getManager();
Expand All @@ -86,12 +66,9 @@ public function createAction(Request $request)
}

/**
* Updates an existing Client entity.
* @Security("is_granted('EDIT', client)")
* @Route("/{id}", name="clients_update")
* @Method("POST")
*/
public function updateAction(Request $request, Client $client)
public function putAction(Request $request, Client $client)
{
$em = $this->getDoctrine()->getManager();
$created = $client->getCreatedAt();
Expand All @@ -102,13 +79,7 @@ public function updateAction(Request $request, Client $client)
return $this->getAction($client);
}

/**
* Adds a comment to a client
*
* @Route("/{id}/comment", name="clients_comment")
* @Method("POST")
*/
public function commentAction(Request $request, Client $client) {
public function postCommentAction(Request $request, Client $client) {
$comment = new ClientComment;
$em = $this->getDoctrine()->getManager();

Expand All @@ -120,14 +91,10 @@ public function commentAction(Request $request, Client $client) {
return new Response($this->get('serializer')->serialize($client,'json',SerializationContext::create()->setGroups(['client_details'])));
}


/**
* Deletes a Client entity.
* @Security("is_granted('DELETE', client)")
* @Route("/{id}", name="clients_delete")
* @Method("DELETE")
*/
public function destroyAction(Request $request, Client $client)
public function deleteAction(Request $request, Client $client)
{
$em = $this->getDoctrine()->getManager();
$em->remove($client);
Expand Down
Loading

0 comments on commit 856552e

Please sign in to comment.