-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from ConductionNL/feature/PC108-82/Contactmome…
…nt-detail-page feature/PC108-82/Contactmoment-detail-page
- Loading branch information
Showing
30 changed files
with
1,805 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 employees (medewerkers) operations | ||
*/ | ||
class MedewerkersController extends Controller | ||
{ | ||
public function __construct( | ||
$appName, | ||
IRequest $request, | ||
private readonly ObjectService $objectService, | ||
) | ||
{ | ||
parent::__construct($appName, $request); | ||
} | ||
|
||
/** | ||
* Return (and search) all employees | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @return JSONResponse | ||
*/ | ||
public function index(): JSONResponse | ||
{ | ||
// Retrieve all request parameters | ||
$requestParams = $this->request->getParams(); | ||
|
||
// Fetch employees based on filters and order | ||
$data = $this->objectService->getResultArrayForRequest('medewerkers', $requestParams); | ||
|
||
// Return JSON response | ||
return new JSONResponse($data); | ||
} | ||
|
||
/** | ||
* Read a single employee | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @return JSONResponse | ||
*/ | ||
public function show(string $id): JSONResponse | ||
{ | ||
// Fetch the employee by its ID | ||
$object = $this->objectService->getObject('medewerkers', $id); | ||
|
||
// Return the employee as a JSON response | ||
return new JSONResponse($object); | ||
} | ||
|
||
/** | ||
* Create an employee | ||
* | ||
* @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 employee | ||
unset($data['id']); | ||
|
||
// Save the new employee | ||
$object = $this->objectService->saveObject('medewerkers', $data); | ||
|
||
// Return the created employee as a JSON response | ||
return new JSONResponse($object); | ||
} | ||
|
||
/** | ||
* Update an employee | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @return JSONResponse | ||
*/ | ||
public function update(string $id): JSONResponse | ||
{ | ||
// Get all parameters from the request | ||
$data = $this->request->getParams(); | ||
|
||
// Save the updated employee | ||
$object = $this->objectService->saveObject('medewerkers', $data); | ||
|
||
// Return the updated employee as a JSON response | ||
return new JSONResponse($object); | ||
} | ||
|
||
/** | ||
* Delete an employee | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @return JSONResponse | ||
*/ | ||
public function destroy(string $id): JSONResponse | ||
{ | ||
// Delete the employee | ||
$result = $this->objectService->deleteObject('medewerkers', $id); | ||
|
||
// Return the result as a JSON response | ||
return new JSONResponse(['success' => $result], $result === true ? '200' : '404'); | ||
} | ||
|
||
/** | ||
* Get audit trail for a specific employee | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @return JSONResponse | ||
*/ | ||
public function getAuditTrail(string $id): JSONResponse | ||
{ | ||
$auditTrail = $this->objectService->getAuditTrail('medewerkers', $id); | ||
return new JSONResponse($auditTrail); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './medewerkers.ts' | ||
export * from './medewerkers.types.ts' | ||
export * from './medewerkers.mock.ts' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Medewerker } from './medewerkers' | ||
import { TMedewerker } from './medewerkers.types' | ||
|
||
export const mockMedewerkerData = (): TMedewerker[] => [ | ||
{ | ||
id: '15551d6f-44e3-43f3-a9d2-59e583c91eb0', | ||
voornaam: 'John', | ||
tussenvoegsel: 'de', | ||
achternaam: 'Doe', | ||
email: '[email protected]', | ||
}, | ||
] | ||
|
||
export const mockMedewerker = (data: TMedewerker[] = mockMedewerkerData()): TMedewerker[] => data.map(item => new Medewerker(item)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Medewerker } from './medewerkers' | ||
import { mockMedewerkerData } from './medewerkers.mock' | ||
|
||
describe('Medewerker Entity', () => { | ||
it('should create a Medewerker entity with full data', () => { | ||
const medewerker = new Medewerker(mockMedewerkerData()[0]) | ||
|
||
expect(medewerker).toBeInstanceOf(Medewerker) | ||
expect(medewerker).toEqual(mockMedewerkerData()[0]) | ||
expect(medewerker.validate().success).toBe(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { SafeParseReturnType, z } from 'zod' | ||
import { TMedewerker } from './medewerkers.types' | ||
|
||
export class Medewerker implements TMedewerker { | ||
|
||
public id: string | ||
public voornaam: string | ||
public tussenvoegsel: string | ||
public achternaam: string | ||
public email: string | ||
|
||
constructor(source: TMedewerker) { | ||
this.id = source.id || '' | ||
this.voornaam = source.voornaam || '' | ||
this.tussenvoegsel = source.tussenvoegsel || '' | ||
this.achternaam = source.achternaam || '' | ||
this.email = source.email || '' | ||
|
||
} | ||
|
||
public validate(): SafeParseReturnType<TMedewerker, unknown> { | ||
const schema = z.object({ | ||
id: z.string().optional(), | ||
voornaam: z.string().min(1), | ||
tussenvoegsel: z.string(), | ||
achternaam: z.string(), | ||
email: z.string().email(), | ||
}) | ||
|
||
return schema.safeParse(this) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type TMedewerker = { | ||
id: string; | ||
voornaam: string; | ||
tussenvoegsel: string; | ||
achternaam: string; | ||
email: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.