diff --git a/appinfo/routes.php b/appinfo/routes.php index aa002e4..34334e4 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -24,6 +24,7 @@ 'taken' => ['url' => 'api/taken'], 'klanten' => ['url' => 'api/klanten'], 'berichten' => ['url' => 'api/berichten'], + 'contactmomenten' => ['url' => 'api/contactmomenten'], ], 'routes' => [ diff --git a/lib/Controller/ContactMomentenController.php b/lib/Controller/ContactMomentenController.php new file mode 100644 index 0000000..05a1fd4 --- /dev/null +++ b/lib/Controller/ContactMomentenController.php @@ -0,0 +1,134 @@ +request->getParams(); + + // Fetch contact moments based on filters and order + $data = $this->objectService->getResultArrayForRequest('contactmomenten', $requestParams); + + // Return JSON response + return new JSONResponse($data); + } + + /** + * Read a single contact moment + * + * @NoAdminRequired + * @NoCSRFRequired + * + * @return JSONResponse + */ + public function show(string $id): JSONResponse + { + // Fetch the contact moment by its ID + $object = $this->objectService->getObject('contactmomenten', $id); + + // Return the contact moment as a JSON response + return new JSONResponse($object); + } + + /** + * Create a contact moment + * + * @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 contact moment + unset($data['id']); + + // Save the new contact moment + $object = $this->objectService->saveObject('contactmomenten', $data); + + // Return the created contact moment as a JSON response + return new JSONResponse($object); + } + + /** + * Update a contact moment + * + * @NoAdminRequired + * @NoCSRFRequired + * + * @return JSONResponse + */ + public function update(string $id): JSONResponse + { + // Get all parameters from the request + $data = $this->request->getParams(); + + // Save the updated contact moment + $object = $this->objectService->saveObject('contactmomenten', $data); + + // Return the updated contact moment as a JSON response + return new JSONResponse($object); + } + + /** + * Delete a contact moment + * + * @NoAdminRequired + * @NoCSRFRequired + * + * @return JSONResponse + */ + public function destroy(string $id): JSONResponse + { + // Delete the contact moment + $result = $this->objectService->deleteObject('contactmomenten', $id); + + // Return the result as a JSON response + return new JSONResponse(['success' => $result], $result === true ? '200' : '404'); + } + + /** + * Get audit trail for a specific contact moment + * + * @NoAdminRequired + * @NoCSRFRequired + * + * @return JSONResponse + */ + public function getAuditTrail(string $id): JSONResponse + { + $auditTrail = $this->objectService->getAuditTrail('contactmomenten', $id); + return new JSONResponse($auditTrail); + } +}