AttachmentApiController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 75
rs 10
c 0
b 0
f 0

7 Methods

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