Lines
100.00%
17 / 17
Methods
100.00%
1 / 1
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __invoke | 100.00% | 17 / 17 | 100.00% | 1 / 1 | 2 | ||
| 21 | final class AgentStatCreate extends BaseController | |
| 22 | { | |
| 23 | public function __invoke( | |
| 24 | #[MapRequestPayload(acceptFormat: 'json')] AgentStatInput $input, | |
| 25 | AgentStatService $agentStatService, | |
| 26 | ): JsonResponse { | |
| 27 | try { | |
| 28 | $agentStat = $agentStatService->create($this->getUser(), $input); | |
| 29 | } catch (StatsAlreadyAddedException $statsAlreadyAddedException) { | |
| 30 | return $this->json(['error' => $statsAlreadyAddedException->getMessage()], Response::HTTP_CONFLICT); | |
| 31 | } | |
| 32 | ||
| 33 | return $this->json( | |
| 34 | [ | |
| 35 | 'id' => $agentStat->id, | |
| 36 | 'createdAt' => $agentStat->createdAt->format(\DATE_ATOM), | |
| 37 | ], | |
| 38 | Response::HTTP_CREATED, | |
| 39 | [ | |
| 40 | 'Location' => $this->generateUrl( | |
| 41 | 'app_agent_stat_show', | |
| 42 | ['id' => $agentStat->id], | |
| 43 | UrlGeneratorInterface::ABSOLUTE_URL | |
| 44 | ), | |
| 45 | ], | |
| 46 | ); | |
| 47 | } | |
| 48 | } |