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

StackApiController::delete()   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 0
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
use OCA\Deck\Service\StackService;
32
use OCA\Deck\Service\BoardService;
33
34
/**
35
 * Class StackApiController
36
 *
37
 * @package OCA\Deck\Controller
38
 */
39
class StackApiController extends ApiController {
40
41
	private $boardService;
42
	private $stackService;
43
44
	/**
45
	 * @param string $appName
46
	 * @param IRequest $request
47
	 * @param StackService $stackService
48
	 */
49
	public function __construct($appName, IRequest $request, StackService $stackService, BoardService $boardService) {
50
		parent::__construct($appName, $request);
51
		$this->stackService = $stackService;
52
		$this->boardService = $boardService;		
53
	}
54
55
	/**
56
	 * @NoAdminRequired
57
	 * @CORS
58
	 * @NoCSRFRequired
59
	 *
60
	 * Return all of the stacks in the specified board.
61
	 */
62
	public function index() {				
63
		$stacks = $this->stackService->findAll($this->request->getParam('boardId'));
64
		return new DataResponse($stacks, HTTP::STATUS_OK);
65
	}
66
67
	/**
68
	 * @NoAdminRequired
69
	 * @CORS
70
	 * @NoCSRFRequired
71
	 *
72
	 * Return all of the stacks in the specified board.
73
	 */
74
	public function get() {
75
		$stack = $this->stackService->find($this->request->getParam('stackId'));
76
		return new DataResponse($stack, HTTP::STATUS_OK);
77
	}
78
	
79
	/**
80
	 * @NoAdminRequired
81
	 * @CORS
82
	 * @NoCSRFRequired
83
	 *
84
	 * @params $title
85
	 * @params $order
86
	 *
87
	 * Create a stack with the specified title and order.
88
	 */
89
	public function create($title, $order) {
90
		$stack = $this->stackService->create($title, $this->request->getParam('boardId'), $order);
91
		return new DataResponse($stack, HTTP::STATUS_OK);
92
	}
93
94
	/**
95
	 * @NoAdminRequired
96
	 * @CORS
97
	 * @NoCSRFRequired
98
	 *	 
99
	 * @params $title	 
100
	 * @params $order
101
	 *
102
	 * Update a stack by the specified stackId and boardId with the values that were put.
103
	 */
104
	public function update($title, $order) {		
105
		$stack = $this->stackService->update($this->request->getParam('stackId'), $title, $this->request->getParam('boardId'), $order, 0);
106
		return new DataResponse($stack, HTTP::STATUS_OK);
107
	}
108
109
	/**
110
	 * @NoAdminRequired
111
	 * @CORS
112
	 * @NoCSRFRequired
113
	 *
114
	 * Delete the stack specified by $this->request->getParam('stackId').
115
	 */
116
	public function delete() {				
117
		$stack = $this->stackService->delete($this->request->getParam('stackId'));
118
		return new DataResponse($stack, HTTP::STATUS_OK);
119
	}
120
121
	/**
122
	 * @NoAdminRequired
123
	 * @CORS
124
	 * @NoCSRFRequired
125
	 *
126
	 * get the stacks that have been archived.
127
	 */
128
	public function getArchived() {
129
		$stacks = $this->stackService->findAllArchived($this->request->getParam('boardId'));
130
		return new DataResponse($stacks, HTTP::STATUS_OK);
131
	}
132
}
133