Passed
Pull Request — master (#1016)
by René
04:03
created

OptionController::getByToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author René Gieling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Polls\Controller;
25
26
use Exception;
27
28
use OCP\IRequest;
29
30
use OCP\AppFramework\Controller;
31
use OCP\AppFramework\Http;
32
use OCP\AppFramework\Http\DataResponse;
33
use OCA\Polls\Service\OptionService;
34
35
class OptionController extends Controller {
36
37
	/** @var OptionService */
38
	private $optionService;
39
40
	/**
41
	 * OptionController constructor.
42
	 * @param string $appName
43
	 * @param IRequest $request
44
	 * @param OptionService $optionService
45
	 */
46
47
	public function __construct(
48
		string $appName,
49
		IRequest $request,
50
		OptionService $optionService
51
	) {
52
		parent::__construct($appName, $request);
53
		$this->optionService = $optionService;
54
	}
55
56
	/**
57
	 * Get all options of given poll
58
	 * @NoAdminRequired
59
	 * @param int $pollId
60
	 * @return DataResponse
61
	 */
62
	public function list($pollId) {
63
		return new DataResponse(['options' => $this->optionService->list($pollId)], Http::STATUS_OK);
64
	}
65
66
	//
67
	// /**
68
	// * Get all options specified by token
69
	// * Read all options of a poll based on a share token and return list as array
70
	// * @NoAdminRequired
71
	// * @PublicPage
72
	// * @param string $token
73
	// * @return DataResponse
74
	// */
75
	// public function listByToken($token) {
76
	// 	return new DataResponse($this->optionService->list(0, $token), Http::STATUS_OK);
77
	// }
78
79
80
81
82
	/**
83
	 * Add a new option
84
	 * @NoAdminRequired
85
	 * @param array $option
86
	 * @return DataResponse
87
	 */
88
	public function add($pollId, $timestamp = 0, $pollOptionText = '') {
89
		return new DataResponse(['option' => $this->optionService->add($pollId, $timestamp, $pollOptionText)], Http::STATUS_OK);
90
	}
91
92
	/**
93
	 * Update option
94
	 * @NoAdminRequired
95
	 * @param array $option
96
	 * @return DataResponse
97
	 */
98
	public function update($optionId, $timestamp, $pollOptionText) {
99
		return new DataResponse(['option' => $this->optionService->update($optionId, $timestamp, $pollOptionText)], Http::STATUS_OK);
100
	}
101
102
	/**
103
	 * Delete option
104
	 * @NoAdminRequired
105
	 * @param Option $option
106
	 * @return DataResponse
107
	 */
108
	public function delete($optionId) {
109
		return new DataResponse(['option' => $this->optionService->delete($optionId)], Http::STATUS_OK);
110
	}
111
112
	/**
113
	 * Switch option confirmation
114
	 * @NoAdminRequired
115
	 * @param int $optionId
116
	 * @return DataResponse
117
	 */
118
	public function confirm($optionId) {
119
		return new DataResponse(['option' => $this->optionService->confirm($optionId)], Http::STATUS_OK);
120
	}
121
122
	/**
123
	 * Reorder options
124
	 * @NoAdminRequired
125
	 * @param int $pollId
126
	 * @param Array $options
127
	 * @return DataResponse
128
	 */
129
	public function reorder($pollId, $options) {
130
		return new DataResponse(['options' => $this->optionService->reorder($pollId, $options)], Http::STATUS_OK);
131
	}
132
}
133