1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Nextcloud - ownnote |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2015, Ben Curtis <[email protected]> |
6
|
|
|
* @copyright Copyright (c) 2017, Sander Brand ([email protected]) |
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
|
|
|
|
24
|
|
|
namespace OCA\OwnNote\Controller; |
25
|
|
|
|
26
|
|
|
use OCA\OwnNote\Service\OwnNoteService; |
27
|
|
|
use OCA\OwnNote\Utility\NotFoundJSONResponse; |
28
|
|
|
use \OCP\AppFramework\ApiController; |
29
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
30
|
|
|
use OCP\IConfig; |
31
|
|
|
use OCP\ILogger; |
32
|
|
|
use \OCP\IRequest; |
33
|
|
|
use \OCA\OwnNote\Lib\Backend; |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
class Ownnotev2ApiController extends ApiController { |
37
|
|
|
|
38
|
|
|
private $backend; |
39
|
|
|
private $config; |
40
|
|
|
private $noteService; |
41
|
|
|
|
42
|
|
|
public function __construct($appName, IRequest $request, ILogger $logger, IConfig $config, OwnNoteService $noteService){ |
43
|
|
|
parent::__construct($appName, $request); |
44
|
|
|
$this->backend = new Backend($config); |
45
|
|
|
$this->config = $config; |
46
|
|
|
$this->noteService = $noteService; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* MOBILE FUNCTIONS |
51
|
|
|
*/ |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @NoAdminRequired |
55
|
|
|
* @NoCSRFRequired |
56
|
|
|
*/ |
57
|
|
|
public function index() { |
58
|
|
|
$results = $this->noteService->getListing('', false); |
59
|
|
|
return new JSONResponse($results); |
60
|
|
|
} |
61
|
|
|
/** |
62
|
|
|
* @NoAdminRequired |
63
|
|
|
* @NoCSRFRequired |
64
|
|
|
*/ |
65
|
|
View Code Duplication |
public function get($id) { |
66
|
|
|
$results = $this->noteService->find($id); |
67
|
|
|
if(!$results){ |
68
|
|
|
return new NotFoundJSONResponse(); |
69
|
|
|
} |
70
|
|
|
return new JSONResponse($results); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @NoAdminRequired |
76
|
|
|
* @NoCSRFRequired |
77
|
|
|
*/ |
78
|
|
|
public function create($title, $group, $note) { |
79
|
|
|
$note = [ |
80
|
|
|
'title' => $title, |
81
|
|
|
'group' => $group, |
82
|
|
|
'note' => $note |
83
|
|
|
]; |
84
|
|
|
$uid = \OC::$server->getUserSession()->getUser()->getUID(); |
85
|
|
|
$result = $this->noteService->create('', $note, $uid); //@TODO add folder |
86
|
|
|
return new JSONResponse($result); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @NoAdminRequired |
91
|
|
|
* @NoCSRFRequired |
92
|
|
|
*/ |
93
|
|
|
public function update($id, $title, $group, $note) { |
94
|
|
|
|
95
|
|
|
$note = [ |
96
|
|
|
'id' => $id, |
97
|
|
|
'title' => $title, |
98
|
|
|
'group' => $group, |
99
|
|
|
'note' => $note |
100
|
|
|
]; |
101
|
|
|
|
102
|
|
|
$entity = $this->noteService->find($id); |
103
|
|
|
if(!$entity){ |
104
|
|
|
return new NotFoundJSONResponse(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$results = $this->noteService->update('',$note); //@TODO add folder |
108
|
|
|
return new JSONResponse($results); |
109
|
|
|
} |
110
|
|
|
/** |
111
|
|
|
* @NoAdminRequired |
112
|
|
|
* @NoCSRFRequired |
113
|
|
|
*/ |
114
|
|
View Code Duplication |
public function delete($id) { |
115
|
|
|
$entity = $this->noteService->find($id); |
116
|
|
|
if(!$entity){ |
117
|
|
|
return new NotFoundJSONResponse(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
$results = $this->noteService->delete('', $id); //@TODO add folder |
121
|
|
|
return new JSONResponse($results); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|