Completed
Push — master ( b22221...546355 )
by FX
03:15
created

CampaignApiController::getCampaignAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright (c) 2017 Francois-Xavier Soubirou.
5
 *
6
 * This file is part of ci-report.
7
 *
8
 * ci-report is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * ci-report is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with ci-report. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
declare(strict_types=1);
22
23
namespace AppBundle\Controller;
24
25
use AppBundle\Entity\Campaign;
26
use AppBundle\Entity\Project;
27
use FOS\RestBundle\Controller\Annotations as Rest;
28
use Nelmio\ApiDocBundle\Annotation as Doc;
29
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
30
31
/**
32
 * Campaign API controller class.
33
 *
34
 * @category  ci-report app
35
 *
36
 * @author    Francois-Xavier Soubirou <[email protected]>
37
 * @copyright 2017 Francois-Xavier Soubirou
38
 * @license   http://www.gnu.org/licenses/   GPLv3
39
 *
40
 * @see      https://www.ci-report.io
41
 *
42
 * @Rest\Route("/api")
43
 */
44
class CampaignApiController extends AbstractApiController
45
{
46
    /**
47
     * Get list of campaigns for a project. Example: </br>
48
     * <pre style="background:black; color:white; font-size:10px;"><code style="background:black;">curl https://www.ci-report.io/api/projects/project-one/campaigns -X GET
49
     * </code></pre>.
50
     *
51
     * @param Project $project Project
52
     *
53
     * @return array
54
     *
55
     * @Rest\Get("/projects/{prefid}/campaigns")
56
     * @Rest\View(serializerGroups={"public"})
57
     *
58
     * @ParamConverter("project", options={"mapping": {"prefid": "refid"}})
59
     *
60
     * @Doc\ApiDoc(
61
     *     section="Campaigns",
62
     *     description="Get the list of all campaigns for a project.",
63
     *     requirements={
64
     *         {
65
     *             "name"="prefid",
66
     *             "dataType"="string",
67
     *             "requirement"="string",
68
     *             "description"="Unique short name of project defined on project creation."
69
     *         }
70
     *     },
71
     *     output={
72
     *         "class"=Campaign::class,
73
     *         "groups"={"public"},
74
     *         "parsers"={"Nelmio\ApiDocBundle\Parser\JmsMetadataParser"}
75
     *     },
76
     *     statusCodes={
77
     *         200="Returned when successful array of public data of campaigns",
78
     *         404="Returned when project not found"
79
     *     }
80
     * )
81
     */
82
    public function getCampaignsAction(Project $project): array
83
    {
84
        $campaigns = $this->getDoctrine()
85
            ->getRepository(Campaign::class)
86
            ->findCampaignsByProject($project);
87
88
        return $campaigns;
89
    }
90
91
    /**
92
     * Get campaign data. Example: </br>
93
     * <pre style="background:black; color:white; font-size:10px;"><code style="background:black;">curl https://www.ci-report.io/api/projects/project-one/campaigns/1 -X GET
94
     * </code></pre>.
95
     *
96
     * @param Campaign $campaign Campaign
97
     *
98
     * @return Campaign
99
     *
100
     * @Rest\Get(
101
     *    "/projects/{prefid}/campaigns/{crefid}",
102
     *    requirements={"crefid" = "\d+"}
103
     * )
104
     * @Rest\View(serializerGroups={"public"})
105
     *
106
     * @ParamConverter("campaign", class="AppBundle:Campaign", options={
107
     *    "repository_method" = "findCampaignByProjectRefidAndRefid",
108
     *    "mapping": {"prefid": "prefid", "crefid": "crefid"},
109
     *    "map_method_signature" = true
110
     * })
111
     *
112
     * @Doc\ApiDoc(
113
     *     section="Campaigns",
114
     *     description="Get campaign data.",
115
     *     requirements={
116
     *         {
117
     *             "name"="prefid",
118
     *             "dataType"="string",
119
     *             "requirement"="string",
120
     *             "description"="Unique short name of project defined on project creation."
121
     *         },
122
     *         {
123
     *             "name"="crefid",
124
     *             "dataType"="int",
125
     *             "requirement"="int",
126
     *             "description"="Reference id of the campaign."
127
     *         }
128
     *     },
129
     *     output= {
130
     *         "class"=Campaign::class,
131
     *         "groups"={"public"},
132
     *         "parsers"={"Nelmio\ApiDocBundle\Parser\JmsMetadataParser"}
133
     *     },
134
     *     statusCodes={
135
     *         200="Returned when successful",
136
     *         404="Returned when project or campaign not found"
137
     *     }
138
     * )
139
     */
140
    public function getCampaignAction(Campaign $campaign): Campaign
141
    {
142
        return $campaign;
143
    }
144
145
    /**
146
     * Get last added campaign data. Example: </br>
147
     * <pre style="background:black; color:white; font-size:10px;"><code style="background:black;">curl https://www.ci-report.io/api/projects/project-one/campaigns/last -X GET
148
     * </code></pre>.
149
     *
150
     * @param Campaign $campaign Campaign
151
     *
152
     * @return Campaign
153
     *
154
     * @Rest\Get("/projects/{prefid}/campaigns/last")
155
     * @Rest\View(serializerGroups={"public"})
156
     *
157
     * @ParamConverter("campaign", class="AppBundle:Campaign", options={
158
     *    "repository_method" = "findLastCampaignByProjectRefid",
159
     *    "mapping": {"prefid": "prefid"},
160
     *    "map_method_signature" = true
161
     * })
162
     *
163
     * @Doc\ApiDoc(
164
     *     section="Campaigns",
165
     *     description="Get last added campaign data.",
166
     *     requirements={
167
     *         {
168
     *             "name"="prefid",
169
     *             "dataType"="string",
170
     *             "requirement"="string",
171
     *             "description"="Unique short name of project defined on project creation."
172
     *         }
173
     *     },
174
     *     output= {
175
     *         "class"=Campaign::class,
176
     *         "groups"={"public"},
177
     *         "parsers"={"Nelmio\ApiDocBundle\Parser\JmsMetadataParser"}
178
     *     },
179
     *     statusCodes={
180
     *         200="Returned when successful",
181
     *         404="Returned when no campaign exists for project"
182
     *     }
183
     * )
184
     */
185
    public function getLastCampaignAction(Campaign $campaign): Campaign
186
    {
187
        return $campaign;
188
    }
189
}
190