-
Notifications
You must be signed in to change notification settings - Fork 326
Expand file tree
/
Copy pathStackOcsController.php
More file actions
95 lines (84 loc) · 2.88 KB
/
StackOcsController.php
File metadata and controls
95 lines (84 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Deck\Controller;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\ExternalBoardService;
use OCA\Deck\Service\StackService;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
class StackOcsController extends OCSController {
public function __construct(
string $appName,
IRequest $request,
private ExternalBoardService $externalBoardService,
private BoardService $boardService,
private StackService $stackService,
) {
parent::__construct($appName, $request);
}
#[NoAdminRequired]
#[PublicPage]
public function index(int $boardId): DataResponse {
$localBoard = $this->boardService->find($boardId, true, true);
if ($localBoard->getExternalId() !== null) {
return $this->externalBoardService->getExternalStacksFromRemote($localBoard);
} else {
return new DataResponse($this->stackService->findAll($boardId));
}
}
#[NoAdminRequired]
#[PublicPage]
public function create(string $title, int $boardId, int $order = 0):DataResponse {
$board = $this->boardService->find($boardId, false);
if ($board->getExternalId()) {
$stack = $this->externalBoardService->createStackOnRemote($board, $title, $order);
return new DataResponse($stack);
} else {
$stack = $this->stackService->create($title, $boardId, $order);
return new DataResponse($stack);
};
}
#[NoAdminRequired]
#[PublicPage]
public function setDoneStack(int $stackId, int $boardId, bool $isDone): DataResponse {
$board = $this->boardService->find($boardId, false);
if ($board->getExternalId()) {
$result = $this->externalBoardService->setDoneStackOnRemote($board, $stackId, $isDone);
return new DataResponse($result);
}
$this->stackService->setDoneStack($stackId, $boardId, $isDone);
return new DataResponse();
}
#[NoAdminRequired]
#[PublicPage]
public function delete(int $stackId, ?int $boardId = null):DataResponse {
if ($boardId) {
$board = $this->boardService->find($boardId, false);
if ($board->getExternalId()) {
$result = $this->externalBoardService->deleteStackOnRemote($board, $stackId);
return new DataResponse($result);
}
}
$result = $this->stackService->delete($stackId);
return new DataResponse($result);
}
#[NoAdminRequired]
#[PublicPage]
public function reorder(int $stackId, int $order, ?int $boardId):DataResponse {
if ($boardId !== null) {
$board = $this->boardService->find($boardId, false);
if ($board->getExternalId()) {
$stacks = $this->externalBoardService->reorderStackOnRemote($board, $stackId, $order);
return new DataResponse($stacks);
}
}
$stacks = $this->stackService->reorder($stackId, $order);
return new DataResponse($stacks);
}
}