|
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 |
|
public function __construct($AppName, IRequest $request, |
|
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
|
|
|
|