Completed
Push — master ( b2e486...1ced49 )
by Sam
02:58
created

ApiController::nonautomated_edits()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 1
eloc 10
nc 1
nop 4
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use AppBundle\Helper\ApiHelper;
6
use AppBundle\Helper\LabsHelper;
7
use AppBundle\Helper\AutomatedEditsHelper;
8
use Exception;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
10
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpFoundation\Response;
13
use Symfony\Component\Debug\Exception\FatalErrorException;
14
use FOS\RestBundle\Controller\Annotations as Rest;
15
use FOS\RestBundle\Controller\FOSRestController;
16
use FOS\RestBundle\View\View;
17
18
class ApiController extends FOSRestController
19
{
20
    /**
21
     * @Rest\Get("/api/namespaces/{project}")
22
     */
23
    public function namespaces($project)
24
    {
25
        $api = $this->get("app.api_helper");
26
27
        try {
28
            $namespaces = $api->namespaces($project);
29
        } catch (Exception $e) {
30
            return new View(
31
                [
32
                    'error' => $e->getMessage(),
33
                ],
34
                Response::HTTP_NOT_FOUND
35
            );
36
        }
37
38
        return new View(
39
            $namespaces,
40
            Response::HTTP_OK
41
        );
42
    }
43
44
    /**
45
     * @Rest\Get("/api/nonautomated_edits/{project}/{username}/{namespace}/{offset}")
46
     */
47
    public function nonautomatedEdits($project, $username, $namespace, $offset = 0)
48
    {
49
        $twig = $this->container->get('twig');
50
        $aeh = $this->get("app.automated_edits_helper");
51
        $editData = $aeh->getNonautomatedEdits($project, $username, $namespace, $offset);
52
53
        $markup = $twig->render('api/automated_edits.html.twig', [
54
            'edits' => $editData,
55
            'projectUrl' =>  "https://$project",
56
        ]);
57
58
        return new View(
59
            ['markup' => $markup],
60
            Response::HTTP_OK
61
        );
62
    }
63
}
64