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