-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53daa49
commit cc823cf
Showing
2 changed files
with
101 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
use OCP\IAppConfig; | ||
use OCP\IRequest; | ||
use OCP\IURLGenerator; | ||
use Psr\Container\ContainerExceptionInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
|
||
class MappingsController extends Controller | ||
{ | ||
|
@@ -126,17 +128,17 @@ public function create(): JSONResponse | |
return new JSONResponse($this->mappingMapper->createFromArray(object: $data)); | ||
} | ||
|
||
/** | ||
* Updates an existing mapping | ||
* | ||
* This method updates an existing mapping based on its ID. | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @param string $id The ID of the mapping to update | ||
* @return JSONResponse A JSON response containing the updated mapping details | ||
*/ | ||
/** | ||
* Updates an existing mapping | ||
* | ||
* This method updates an existing mapping based on its ID. | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @param int $id The ID of the mapping to update | ||
* @return JSONResponse A JSON response containing the updated mapping details | ||
*/ | ||
public function update(int $id): JSONResponse | ||
{ | ||
$data = $this->request->getParams(); | ||
|
@@ -152,60 +154,66 @@ public function update(int $id): JSONResponse | |
return new JSONResponse($this->mappingMapper->updateFromArray(id: (int) $id, object: $data)); | ||
} | ||
|
||
/** | ||
* Deletes a mapping | ||
* | ||
* This method deletes a mapping based on its ID. | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @param string $id The ID of the mapping to delete | ||
* @return JSONResponse An empty JSON response | ||
*/ | ||
/** | ||
* Deletes a mapping | ||
* | ||
* This method deletes a mapping based on its ID. | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @param int $id The ID of the mapping to delete | ||
* @return JSONResponse An empty JSON response | ||
* @throws \OCP\DB\Exception | ||
*/ | ||
public function destroy(int $id): JSONResponse | ||
{ | ||
$this->mappingMapper->delete($this->mappingMapper->find((int) $id)); | ||
|
||
return new JSONResponse([]); | ||
} | ||
|
||
/** | ||
* Tests a mapping | ||
* | ||
* This method tests a mapping with provided input data and optional schema validation. | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @return JSONResponse A JSON response containing the test results | ||
* | ||
* @example | ||
* Request: | ||
* { | ||
* "inputObject": "{\"name\":\"John Doe\",\"age\":30,\"email\":\"[email protected]\"}", | ||
* "mapping": { | ||
* "mapping": { | ||
* "fullName":"{{name}}", | ||
* "userAge":"{{age}}", | ||
* "contactEmail":"{{email}}" | ||
* } | ||
* }, | ||
* "schema": "user_schema_id", | ||
* "validation": true | ||
* } | ||
* | ||
* Response: | ||
* { | ||
* "resultObject": { | ||
* "fullName": "John Doe", | ||
* "userAge": 30, | ||
* "contactEmail": "[email protected]" | ||
* }, | ||
* "isValid": true, | ||
* "validationErrors": [] | ||
* } | ||
*/ | ||
/** | ||
* Tests a mapping | ||
* | ||
* This method tests a mapping with provided input data and optional schema validation. | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @param ObjectService $objectService | ||
* @param IURLGenerator $urlGenerator | ||
* | ||
* @return JSONResponse A JSON response containing the test results | ||
* @throws ContainerExceptionInterface | ||
* @throws NotFoundExceptionInterface | ||
* | ||
* @example | ||
* Request: | ||
* { | ||
* "inputObject": "{\"name\":\"John Doe\",\"age\":30,\"email\":\"[email protected]\"}", | ||
* "mapping": { | ||
* "mapping": { | ||
* "fullName":"{{name}}", | ||
* "userAge":"{{age}}", | ||
* "contactEmail":"{{email}}" | ||
* } | ||
* }, | ||
* "schema": "user_schema_id", | ||
* "validation": true | ||
* } | ||
* | ||
* Response: | ||
* { | ||
* "resultObject": { | ||
* "fullName": "John Doe", | ||
* "userAge": 30, | ||
* "contactEmail": "[email protected]" | ||
* }, | ||
* "isValid": true, | ||
* "validationErrors": [] | ||
* } | ||
*/ | ||
public function test(ObjectService $objectService, IURLGenerator $urlGenerator): JSONResponse | ||
{ | ||
$openRegisters = $objectService->getOpenRegisters(); | ||
|
@@ -293,32 +301,42 @@ public function test(ObjectService $objectService, IURLGenerator $urlGenerator): | |
]); | ||
} | ||
|
||
/** | ||
* Saves a mapping object | ||
* | ||
* This method saves a mapping object based on POST data. | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
*/ | ||
public function saveObject(): JSONResponse | ||
/** | ||
* Saves a mapping object | ||
* | ||
* This method saves a mapping object based on POST data. | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @return JSONResponse|null | ||
* @throws ContainerExceptionInterface | ||
* @throws NotFoundExceptionInterface | ||
*/ | ||
public function saveObject(): ?JSONResponse | ||
{ | ||
// Check if the OpenRegister service is available | ||
$openRegisters = $this->objectService->getOpenRegisters(); | ||
if ($openRegisters !== null) { | ||
$data = $this->request->getParams(); | ||
return new JSONResponse($openRegisters->saveObject($data['register'], $data['schema'], $data['object'])); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Retrieves a list of objects to map to | ||
* | ||
* This method retrieves a list of objects to map to based on GET data. | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
*/ | ||
/** | ||
* Retrieves a list of objects to map to | ||
* | ||
* This method retrieves a list of objects to map to based on GET data. | ||
* | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* | ||
* @return JSONResponse | ||
* @throws ContainerExceptionInterface | ||
* @throws NotFoundExceptionInterface | ||
*/ | ||
public function getObjects(): JSONResponse | ||
{ | ||
// Check if the OpenRegister service is available | ||
|
@@ -333,6 +351,6 @@ public function getObjects(): JSONResponse | |
} | ||
|
||
return new JSONResponse($data); | ||
|
||
} | ||
} |
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