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

AttachmentApiController::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 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2018 Ryan Fletcher <[email protected]>
4
 *
5
 * @author Ryan Fletcher <[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
namespace OCA\Deck\Controller;
24
25
use OCP\AppFramework\ApiController;
26
use OCP\AppFramework\Http;
27
use OCP\AppFramework\Http\DataResponse;
28
use OCP\IRequest;
29
use OCA\Deck\Service\AttachmentService;
30
31
class AttachmentApiController extends ApiController {
32
33
    private $attachmentService;
34
35
    public function __construct($appName, IRequest $request, AttachmentService $attachmentService) {
36
        parent::__construct($appName, $request);
37
        $this->attachmentService = $attachmentService;
38
    }
39
40
    /**
41
	 * @NoAdminRequired
42
	 * @CORS
43
	 * @NoCSRFRequired
44
	 *
45
	 */
46
    public function getAll() {
47
        $attachment = $this->attachmentService->findAll($this->request->getParam('cardId'));
48
        return new DataResponse($attachment, HTTP::STATUS_OK);
49
    }
50
51
    /**
52
	 * @NoAdminRequired
53
	 * @CORS
54
	 * @NoCSRFRequired
55
	 *
56
	 */
57
    public function display() {
58
        $attachment = $this->attachmentService->display($this->request->getParam('cardId'), $this->request->getParam('attachmentId'));
59
        return new DataResponse($attachment, HTTP::STATUS_OK);
60
    }
61
62
    /**
63
	 * @NoAdminRequired
64
	 * @CORS
65
	 * @NoCSRFRequired
66
	 *
67
	 */
68
    public function create($type, $data) {
69
        $attachment = $this->attachmentService->create($this->request->getParam('cardId'), $type, $data);
70
        return new DataResponse($attachment, HTTP::STATUS_OK);
71
    }
72
73
    /**
74
	 * @NoAdminRequired
75
	 * @CORS
76
	 * @NoCSRFRequired
77
	 *
78
	 */
79
    public function update($data) {
80
        $attachment = $this->attachmentService->update($this->request->getParam('cardId'), $this->request->getParam('attachmentId'), $data);
81
        return new DataResponse($attachment, HTTP::STATUS_OK);
82
    }
83
84
    /**
85
	 * @NoAdminRequired
86
	 * @CORS
87
	 * @NoCSRFRequired
88
	 *
89
	 */
90
    public function delete() {
91
        $attachment = $this->attachmentService->delete($this->request->getParam('cardId'), $this->request->getParam('attachmentId'));
92
        return new DataResponse($attachment, HTTP::STATUS_OK);
93
    }
94
95
    /**
96
	 * @NoAdminRequired
97
	 * @CORS
98
	 * @NoCSRFRequired
99
	 *
100
	 */
101
    public function restore() {
102
        $attachment = $this->attachmentService->restore($this->request->getParam('cardId'), $this->request->getParam('attachmentId'));
103
        return new DataResponse($attachment, HTTP::STATUS_OK);
104
    }
105
}