Completed
Push — master ( a3a70f...f040df )
by Julius
11s
created

BoardApiController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Steven R. Baker <[email protected]>
4
 *
5
 * @author Steven R. Baker <[email protected]>
6
 * @author Ryan Fletcher <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 *  This program is free software: you can redistribute it and/or modify
11
 *  it under the terms of the GNU Affero General Public License as
12
 *  published by the Free Software Foundation, either version 3 of the
13
 *  License, or (at your option) any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU Affero General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU Affero General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
namespace OCA\Deck\Controller;
26
27
use OCP\AppFramework\ApiController;
28
use OCP\AppFramework\Http;
29
use OCP\AppFramework\Http\DataResponse;
30
use OCP\IRequest;
31
32
use OCA\Deck\Service\BoardService;
33
34
/**
35
 * Class BoardApiController
36
 *
37
 * @package OCA\Deck\Controller
38
 */
39
class BoardApiController extends ApiController {
40
41
	private $service;
42
43
	/**
44
	 * @param string $appName
45
	 * @param IRequest $request
46
	 * @param BoardService $service
47
	 * @param $userId
48
	 */
49
	public function __construct($appName, IRequest $request, BoardService $service, $userId) {
50
		parent::__construct($appName, $request);
51
		$this->service = $service;
52
		$this->userId = $userId;
0 ignored issues
show
Bug introduced by
The property userId does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
53
	}
54
55
	/**
56
	 * @NoAdminRequired
57
	 * @CORS
58
	 * @NoCSRFRequired
59
	 *
60
	 * Return all of the boards that the current user has access to.
61
	 */
62
	public function index() {
63
		$boards = $this->service->findAll();
64
		return new DataResponse($boards, HTTP::STATUS_OK);
65
	}
66
67
	/**
68
	 * @NoAdminRequired
69
	 * @CORS
70
	 * @NoCSRFRequired
71
	 *
72
	 *
73
	 * Return the board specified by $this->request->getParam('boardId').
74
	 */
75
	public function get() {		
76
		$board = $this->service->find($this->request->getParam('boardId'));
77
		return new DataResponse($board, HTTP::STATUS_OK);
78
	}
79
80
	/**
81
	 * @NoAdminRequired
82
	 * @CORS
83
	 * @NoCSRFRequired
84
	 *
85
	 * @params $title
86
	 * @params $color
87
	 *
88
	 * Create a board with the specified title and color.
89
	 */
90
	public function create($title, $color) {		
91
		$board = $this->service->create($title, $this->userId, $color);		
92
		return new DataResponse($board, HTTP::STATUS_OK);
93
	}
94
95
	/**
96
	 * @NoAdminRequired
97
	 * @CORS
98
	 * @NoCSRFRequired
99
	 *	 
100
	 * @params $title
101
	 * @params $color	
102
	 * @params $archived 
103
	 *
104
	 * Update a board with the specified boardId, title and color, and archived state.
105
	 */
106
	public function update($title, $color, $archived = false) {		
107
		$board = $this->service->update($this->request->getParam('boardId'), $title, $color, $archived);
108
		return new DataResponse($board, HTTP::STATUS_OK);
109
	}
110
111
	/**
112
	 * @NoAdminRequired
113
	 * @CORS
114
	 * @NoCSRFRequired
115
	 *	 
116
	 *
117
	 * Delete the board specified by $boardId.  Return the board that was deleted.
118
	 */
119
	public function delete() {
120
		$board = $this->service->delete($this->request->getParam('boardId'));
121
		return new DataResponse($board, HTTP::STATUS_OK);
122
	}
123
124
	/**
125
	 * @NoAdminRequired
126
	 * @CORS
127
	 * @NoCSRFRequired
128
	 *	 
129
	 *
130
	 * Undo the deletion of the board specified by $boardId.
131
	 */
132
	public function undoDelete() {		
133
		$board = $this->service->deleteUndo($this->request->getParam('boardId'));		
134
		return new DataResponse($board, HTTP::STATUS_OK);
135
	}
136
137
}
138