Skip to content

Commit

Permalink
Contactmomenten controller en route
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvdlinde committed Nov 25, 2024
1 parent 0c70fc8 commit d04d5e7
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'taken' => ['url' => 'api/taken'],
'klanten' => ['url' => 'api/klanten'],
'berichten' => ['url' => 'api/berichten'],
'contactmomenten' => ['url' => 'api/contactmomenten'],

],
'routes' => [
Expand Down
134 changes: 134 additions & 0 deletions lib/Controller/ContactMomentenController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

namespace OCA\ZaakAfhandelApp\Controller;

use OCA\ZaakAfhandelApp\Service\ObjectService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;

/**
* Controller for handling contact moments (contactmomenten) operations
*/
class ContactMomentenController extends Controller
{
public function __construct(
$appName,
IRequest $request,
private readonly ObjectService $objectService,
)
{
parent::__construct($appName, $request);
}

/**
* Return (and search) all contact moments
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @return JSONResponse
*/
public function index(): JSONResponse
{
// Retrieve all request parameters
$requestParams = $this->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);
}
}

0 comments on commit d04d5e7

Please sign in to comment.