-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTakenController.php
121 lines (101 loc) · 2.85 KB
/
TakenController.php
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
<?php
namespace OCA\ZaakAfhandelApp\Controller;
use OCA\ZaakAfhandelApp\Service\ObjectService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
class TakenController extends Controller
{
public function __construct(
$appName,
IRequest $request,
private readonly ObjectService $objectService,
) {
parent::__construct($appName, $request);
}
/**
* Return (and serach) all objects
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @return JSONResponse
*/
public function index(): JSONResponse
{
// Retrieve all request parameters
$requestParams = $this->request->getParams();
// Fetch catalog objects based on filters and order
$data = $this->objectService->getResultArrayForRequest('taken', $requestParams);
// Return JSON response
return new JSONResponse($data);
}
/**
* Read a single object
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @return JSONResponse
*/
public function show(string $id): JSONResponse
{
// Fetch the catalog object by its ID
$object = $this->objectService->getObject('taken', $id);
// Return the catalog as a JSON response
return new JSONResponse($object);
}
/**
* Creatue an object
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @return JSONResponse
*/
public function create(): JSONResponse
{
// Get all parameters from the request
$data = $this->request->getParams();
// Remove the 'id' field if it exists, as we're creating a new object
unset($data['id']);
// Save the new catalog object
$object = $this->objectService->saveObject('taken', $data);
// Return the created object as a JSON response
return new JSONResponse($object);
}
/**
* Update an object
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @return JSONResponse
*/
public function update(string $id): JSONResponse
{
// Get all parameters from the request
$data = $this->request->getParams();
// Remove the 'id' field if it exists, as we're creating a new object
unset($data['id']);
// Save the new catalog object
$object = $this->objectService->saveObject('taken', $data);
// Return the created object as a JSON response
return new JSONResponse($object);
}
/**
* Delate an object
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @return JSONResponse
*/
public function destroy(string $id): JSONResponse
{
// Delete the catalog object
$result = $this->objectService->deleteObject('taken', $id);
// Return the result as a JSON response
return new JSONResponse(['success' => $result], $result === true ? '200' : '404');
}
}