| @@ 251-275 (lines=25) @@ | ||
| 248 | * } |
|
| 249 | * ) |
|
| 250 | */ |
|
| 251 | public function postCampaignAction(Project $project, CampaignDTO $campaignDTO, Request $request) |
|
| 252 | { |
|
| 253 | if ($this->isInvalidToken($request, $project->getToken())) { |
|
| 254 | return $this->getInvalidTokenView(); |
|
| 255 | } |
|
| 256 | ||
| 257 | $validator = $this->get('validator'); |
|
| 258 | $violationsDTO = $validator->validate($campaignDTO); |
|
| 259 | ||
| 260 | if (count($violationsDTO) > 0) { |
|
| 261 | return $this->view($violationsDTO, Response::HTTP_BAD_REQUEST); |
|
| 262 | } |
|
| 263 | $campaign = new Campaign($project); |
|
| 264 | $campaign->setFromDTO($campaignDTO); |
|
| 265 | ||
| 266 | $violations = $validator->validate($campaign); |
|
| 267 | if (count($violations) > 0) { |
|
| 268 | return $this->view($violations, Response::HTTP_BAD_REQUEST); |
|
| 269 | } |
|
| 270 | $em = $this->getDoctrine()->getManager(); |
|
| 271 | $em->persist($campaign); |
|
| 272 | $em->flush(); |
|
| 273 | ||
| 274 | return $campaign; |
|
| 275 | } |
|
| 276 | ||
| 277 | /** |
|
| 278 | * Update a campaign. Example: </br> |
|
| @@ 235-259 (lines=25) @@ | ||
| 232 | * } |
|
| 233 | * ) |
|
| 234 | */ |
|
| 235 | public function postSuiteAction(Project $project, Campaign $campaign, SuiteDTO $suiteDTO, Request $request) |
|
| 236 | { |
|
| 237 | if ($this->isInvalidToken($request, $project->getToken())) { |
|
| 238 | return $this->getInvalidTokenView(); |
|
| 239 | } |
|
| 240 | ||
| 241 | $validator = $this->get('validator'); |
|
| 242 | $violationsDTO = $validator->validate($suiteDTO); |
|
| 243 | ||
| 244 | if (count($violationsDTO) > 0) { |
|
| 245 | return $this->view($violationsDTO, Response::HTTP_BAD_REQUEST); |
|
| 246 | } |
|
| 247 | $suite = new Suite($campaign); |
|
| 248 | $suite->setFromDTO($suiteDTO); |
|
| 249 | ||
| 250 | $violations = $validator->validate($suite); |
|
| 251 | if (count($violations) > 0) { |
|
| 252 | return $this->view($violations, Response::HTTP_BAD_REQUEST); |
|
| 253 | } |
|
| 254 | $em = $this->getDoctrine()->getManager(); |
|
| 255 | $em->persist($suite); |
|
| 256 | $em->flush(); |
|
| 257 | ||
| 258 | return $suite; |
|
| 259 | } |
|
| 260 | } |
|
| 261 | ||