|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use AppBundle\Entity\CustomerOrder; |
|
6
|
|
|
use AppBundle\Entity\Ticket; |
|
7
|
|
|
use AppBundle\Exception\TicketStatusConflictException; |
|
8
|
|
|
use AppBundle\Services\OrderManager; |
|
9
|
|
|
use FOS\RestBundle\Controller\Annotations\Get; |
|
10
|
|
|
use FOS\RestBundle\Controller\Annotations\Patch; |
|
11
|
|
|
use FOS\RestBundle\Controller\Annotations\View as RestView; |
|
12
|
|
|
use FOS\RestBundle\Controller\Annotations\RouteResource; |
|
13
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @RouteResource("Ticket") |
|
18
|
|
|
*/ |
|
19
|
|
|
class TicketsController extends Controller |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @Get(requirements={"id" = "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"}) |
|
23
|
2 |
|
* @ParamConverter("id", class="AppBundle:Ticket") |
|
24
|
|
|
* @RestView(serializerGroups={"get_ticket"}) |
|
25
|
|
|
*/ |
|
26
|
2 |
|
public function csgetAction(Ticket $id) |
|
27
|
|
|
{ |
|
28
|
2 |
|
//This done not in right way (Ticket $ticket) to have RESTfully looking route: /tickets/{id} |
|
29
|
|
|
$ticket = $id; |
|
30
|
|
|
|
|
31
|
|
|
return $ticket; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @RestView(statusCode=204) |
|
36
|
1 |
|
* @Patch(requirements={"id" = "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"}) |
|
37
|
|
|
* @ParamConverter("id", class="AppBundle:Ticket") |
|
38
|
|
|
*/ |
|
39
|
1 |
|
public function freeAction(Ticket $id) |
|
40
|
|
|
{ |
|
41
|
1 |
|
//This done not in right way (Ticket $ticket) to have RESTfully looking route: /tickets/{id} |
|
42
|
1 |
|
$ticket = $id; |
|
43
|
1 |
|
|
|
44
|
1 |
|
$em = $this->getDoctrine()->getManager(); |
|
45
|
|
|
$ticket->setStatus(Ticket::STATUS_FREE); |
|
46
|
|
|
/** @var OrderManager $orderManager */ |
|
47
|
|
|
$this->get('app.order.manager')->removeOrderToTicket($ticket); |
|
48
|
|
|
$em->flush(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
/** |
|
52
|
|
|
* @RestView(statusCode=200) |
|
53
|
|
|
* @Get(requirements={"id" = "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"}) |
|
54
|
1 |
|
* @ParamConverter("id", class="AppBundle:Ticket") |
|
55
|
|
|
*/ |
|
56
|
1 |
|
public function getAction(Ticket $id) |
|
57
|
1 |
|
{ |
|
58
|
1 |
|
//This done not in right way (Ticket $ticket) to have RESTfully looking route: /tickets/{id} |
|
59
|
1 |
|
$ticket = $id; |
|
60
|
|
|
|
|
61
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
62
|
|
|
|
|
63
|
|
|
if ($ticket->getStatus() === Ticket::STATUS_BOOKED) { |
|
64
|
|
|
throw new TicketStatusConflictException('Ticket is already booked'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$ticket->setStatus(Ticket::STATUS_BOOKED); |
|
68
|
|
|
$this->get('app.order.manager')->addOrderToTicket($ticket); |
|
69
|
|
|
$em->flush(); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|