Newer
Older
<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use Doctrine\ORM\Mapping as ORM;
use App\Controller\ChartController;
uriTemplate: '/api/bar-chart/{startDate}/{endDate}/{granularity}',
requirements: [
'startDate' => '\d{4}-\d{2}-\d{2}',
'endDate' => '\d{4}-\d{2}-\d{2}',
'granularity' => 'day|month|year',
],
controller: ChartController::class,
),
new GetCollection(
uriTemplate: '/api/donut-chart/{id}',
],
controller: ChartController::class,
name: 'donut-chart',
#[ApiResource(
operations: [
new GetCollection(
uriTemplate: '/sales/monthly_average_price_evolution',
controller: SaleController::class,
name: 'monthly_average_price_evolution'
)
]
)]
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/** A sale. */
#[ORM\Entity]
class Sale
{
/** The id of this sale. **/
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
private ?int $id;
/** The date of this sale. */
#[ORM\Column]
private ?\DateTimeImmutable $date;
/** The amount of this sale. */
#[ORM\Column]
private ?float $amount;
/** The surface of this sale. */
#[ORM\Column]
private ?float $surface;
/** The region of this sale. */
#[ORM\Column()]
private ?string $region;
// constructor
public function __construct(
\DateTimeImmutable $date = null,
float $amount = null,
float $surface = null,
string $region = null
) {
$this->date = $date;
$this->amount = $amount;
$this->surface = $surface;
$this->region = $region;
}
// getters
public function getId(): ?int
{
return $this->id;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function getAmount(): ?float
{
return $this->amount;
}
public function getSurface(): ?float
{
return $this->surface;
}
public function getRegion(): ?string
{
return $this->region;
}
// setters
public function setDate(\DateTimeImmutable $date): void
{
$this->date = $date;
}
public function setAmount(float $amount): void
{
$this->amount = $amount;
}
public function setSurface(float $surface): void
{
$this->surface = $surface;
}
public function setRegion(string $region): void
{
$this->region = $region;
}
}