Completed
Push — master ( bbae65...c4726b )
by
unknown
22:25
created

NotesController::favorite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * ownCloud - Notes
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Bernhard Posselt <[email protected]>
9
 * @copyright Bernhard Posselt 2012, 2014
10
 */
11
12
namespace OCA\Notes\Controller;
13
14
use OCP\AppFramework\Controller;
15
use OCP\IRequest;
16
use OCP\IConfig;
17
use OCP\AppFramework\Http\DataResponse;
18
19
use OCA\Notes\Service\NotesService;
20
21
/**
22
 * Class NotesController
23
 *
24
 * @package OCA\Notes\Controller
25
 */
26
class NotesController extends Controller {
27
28
    use Errors;
29
30
    /** @var NotesService */
31
    private $notesService;
32
    /** @var IConfig */
33
    private $settings;
34
    /** @var string */
35
    private $userId;
36
37
    /**
38
     * @param string $AppName
39
     * @param IRequest $request
40
     * @param NotesService $service
41
     * @param IConfig $settings
42
     * @param string $UserId
43
     */
44 8 View Code Duplication
    public function __construct($AppName, IRequest $request,
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
                                NotesService $service, IConfig $settings,
46
                                $UserId){
47 8
        parent::__construct($AppName, $request);
48 8
        $this->notesService = $service;
49 8
        $this->settings = $settings;
50 8
        $this->userId = $UserId;
51 8
    }
52
53
54
    /**
55
     * @NoAdminRequired
56
     */
57 1
    public function index() {
58 1
        return new DataResponse($this->notesService->getAll($this->userId));
59
    }
60
61
62
    /**
63
     * @NoAdminRequired
64
     *
65
     * @param int $id
66
     * @return DataResponse
67
     */
68 2
    public function get($id) {
69
        // save the last viewed note
70 2
        $this->settings->setUserValue(
71 2
            $this->userId, $this->appName, 'notesLastViewedNote', $id
72 2
        );
73
74
        return $this->respond(function ()  use ($id) {
75 2
            return $this->notesService->get($id, $this->userId);
76 2
        });
77
    }
78
79
80
    /**
81
     * @NoAdminRequired
82
     *
83
     * @param string $content
84
     */
85 1
    public function create($content) {
86 1
        $note = $this->notesService->create($this->userId);
87 1
        $note = $this->notesService->update(
88 1
            $note->getId(), $content, $this->userId
89 1
        );
90 1
        return new DataResponse($note);
91
    }
92
93
94
    /**
95
     * @NoAdminRequired
96
     *
97
     * @param int $id
98
     * @param string $content
99
     * @return DataResponse
100
     */
101 2
    public function update($id, $content) {
102
        return $this->respond(function () use ($id, $content) {
103 2
            return $this->notesService->update($id, $content, $this->userId);
104 2
        });
105
    }
106
107
108
    /**
109
     * @NoAdminRequired
110
     *
111
     * @param int $id
112
     * @param boolean $favorite
113
     * @return DataResponse
114
     */
115 2
    public function favorite($id, $favorite) {
116 2
        return $this->respond(function () use ($id, $favorite) {
117 1
            return $this->notesService->favorite($id, $favorite, $this->userId);
118 2
        });
119
    }
120
121
122
    /**
123
     * @NoAdminRequired
124
     *
125
     * @param int $id
126
     * @return DataResponse
127
     */
128
    public function destroy($id) {
129
        return $this->respond(function () use ($id) {
130
            $this->notesService->delete($id, $this->userId);
131
            return [];
132
        });
133
    }
134
135
}
136