forked from nextcloud/notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotescontroller.php
More file actions
135 lines (114 loc) · 3.03 KB
/
notescontroller.php
File metadata and controls
135 lines (114 loc) · 3.03 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* Nextcloud - Notes
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Bernhard Posselt <[email protected]>
* @copyright Bernhard Posselt 2012, 2014
*/
namespace OCA\Notes\Controller;
use OCP\AppFramework\Controller;
use OCP\IRequest;
use OCP\IConfig;
use OCP\AppFramework\Http\DataResponse;
use OCA\Notes\Service\NotesService;
/**
* Class NotesController
*
* @package OCA\Notes\Controller
*/
class NotesController extends Controller {
use Errors;
/** @var NotesService */
private $notesService;
/** @var IConfig */
private $settings;
/** @var string */
private $userId;
/**
* @param string $AppName
* @param IRequest $request
* @param NotesService $service
* @param IConfig $settings
* @param string $UserId
*/
public function __construct($AppName, IRequest $request,
NotesService $service, IConfig $settings,
$UserId){
parent::__construct($AppName, $request);
$this->notesService = $service;
$this->settings = $settings;
$this->userId = $UserId;
}
/**
* @NoAdminRequired
*/
public function index() {
return new DataResponse($this->notesService->getAll($this->userId));
}
/**
* @NoAdminRequired
*
* @param int $id
* @return DataResponse
*/
public function get($id) {
// save the last viewed note
$this->settings->setUserValue(
$this->userId, $this->appName, 'notesLastViewedNote', $id
);
return $this->respond(function () use ($id) {
return $this->notesService->get($id, $this->userId);
});
}
/**
* @NoAdminRequired
*
* @param string $content
*/
public function create($content="") {
$note = $this->notesService->create($this->userId);
$note = $this->notesService->update(
$note->getId(), $content, $this->userId
);
return new DataResponse($note);
}
/**
* @NoAdminRequired
*
* @param int $id
* @param string $content
* @return DataResponse
*/
public function update($id, $content) {
return $this->respond(function () use ($id, $content) {
return $this->notesService->update($id, $content, $this->userId);
});
}
/**
* @NoAdminRequired
*
* @param int $id
* @param boolean $favorite
* @return DataResponse
*/
public function favorite($id, $favorite) {
return $this->respond(function () use ($id, $favorite) {
return $this->notesService->favorite($id, $favorite, $this->userId);
});
}
/**
* @NoAdminRequired
*
* @param int $id
* @return DataResponse
*/
public function destroy($id) {
return $this->respond(function () use ($id) {
$this->notesService->delete($id, $this->userId);
return [];
});
}
}