From c130864b1e8b2b0a9c56200b47b9e0706dc5400e Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Fri, 24 Jan 2025 10:31:16 +0100 Subject: [PATCH] Codeclean up --- lib/Controller/CatalogiController.php | 192 --------------------- lib/Controller/OrganizationsController.php | 173 ------------------- lib/Controller/PagesController.php | 145 ---------------- lib/Controller/ThemesController.php | 161 ----------------- src/store/modules/catalogi.ts | 2 +- src/store/modules/organization.ts | 2 +- src/store/modules/page.ts | 2 +- src/store/modules/publication.ts | 2 +- src/store/modules/publicationType.ts | 2 +- src/store/modules/theme.ts | 2 +- 10 files changed, 6 insertions(+), 677 deletions(-) delete mode 100644 lib/Controller/CatalogiController.php delete mode 100644 lib/Controller/OrganizationsController.php delete mode 100644 lib/Controller/PagesController.php delete mode 100644 lib/Controller/ThemesController.php diff --git a/lib/Controller/CatalogiController.php b/lib/Controller/CatalogiController.php deleted file mode 100644 index 23d43adf..00000000 --- a/lib/Controller/CatalogiController.php +++ /dev/null @@ -1,192 +0,0 @@ -request->getParams(); - - // Fetch catalog objects based on filters and order - $data = $this->objectService->getResultArrayForRequest('catalog', $requestParams); - - // Return JSON response - return new JSONResponse($data); - } - - /** - * Retrieve a specific catalog by its ID. - * - * @param string|int $id The ID of the catalog to retrieve - * @param ObjectService $objectService Service to handle object operations - * - * @return JSONResponse JSON response containing the requested catalog - * @throws DoesNotExistException|MultipleObjectsReturnedException|ContainerExceptionInterface|NotFoundExceptionInterface - * - * @NoAdminRequired - * @NoCSRFRequired - */ - public function show(string|int $id, ObjectService $objectService): JSONResponse - { - // Fetch the catalog object by its ID - $object = $this->objectService->getObject('catalog', $id); - - // Return the catalog as a JSON response - return new JSONResponse($object); - } - - /** - * Create a new catalog. - * - * @param ObjectService $objectService The service to handle object operations. - * - * @return JSONResponse The response containing the created catalog object. - * @throws DoesNotExistException|MultipleObjectsReturnedException|ContainerExceptionInterface|NotFoundExceptionInterface - * @throws GuzzleException - * - * @NoAdminRequired - * @NoCSRFRequired - */ - public function create(ObjectService $objectService): 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('catalog', $data); - - // If object is a class change it to array - if (is_object($object) === true) { - $object = $object->jsonSerialize(); - } - - // If we do not have an uri, we need to generate one - if (isset($object['uri']) === false) { - $object['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.catalogs.show', ['id' => $object['id']])); - $object = $this->objectService->saveObject('catalog', $object); - } - - // Update all external directories - $this->broadcastService->broadcast(); - - // Return the created object as a JSON response - return new JSONResponse($object); - } - - /** - * Update an existing catalog. - * - * @param string|int $id The ID of the catalog to update. - * @param ObjectService $objectService The service to handle object operations. - * - * @return JSONResponse The response containing the updated catalog object. - * @throws DoesNotExistException|MultipleObjectsReturnedException|ContainerExceptionInterface|NotFoundExceptionInterface - * @throws GuzzleException - * - * @NoAdminRequired - * @NoCSRFRequired - */ - public function update(string|int $id, ObjectService $objectService): JSONResponse - { - // Get all parameters from the request - $data = $this->request->getParams(); - - // Ensure the ID in the data matches the ID in the URL - $data['id'] = $id; - - // If we do not have an uri, we need to generate one - $data['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.catalogs.show', ['id' => $data['id']])); - - // Save the updated catalog object - $object = $this->objectService->saveObject('catalog', $data); - - // Update all external directories - $this->broadcastService->broadcast(); - - // Return the updated object as a JSON response - return new JSONResponse($object); - } - - /** - * Delete a catalog. - * - * @param string|int $id The ID of the catalog to delete. - * @param ObjectService $objectService The service to handle object operations. - * - * @return JSONResponse The response indicating the result of the deletion. - * @throws ContainerExceptionInterface|NotFoundExceptionInterface|\OCP\DB\Exception - * - * @NoAdminRequired - * @NoCSRFRequired - */ - public function destroy(string|int $id, ObjectService $objectService): JSONResponse - { - // Delete the catalog object - $result = $this->objectService->deleteObject('catalog', $id); - - // Return the result as a JSON response - return new JSONResponse(['success' => $result], $result === true ? '200' : '404'); - } -} diff --git a/lib/Controller/OrganizationsController.php b/lib/Controller/OrganizationsController.php deleted file mode 100644 index 9ee1f6c1..00000000 --- a/lib/Controller/OrganizationsController.php +++ /dev/null @@ -1,173 +0,0 @@ -appName, 'OrganizationIndex', []); - } - - /** - * Retrieve a list of organizations based on provided filters and parameters. - * - * @NoAdminRequired - * @NoCSRFRequired - * - * @return JSONResponse JSON response containing the list of organizations and total count - */ - public function index(): JSONResponse - { - // Retrieve all request parameters - $requestParams = $this->request->getParams(); - - // Fetch organization objects based on filters and order - $data = $this->objectService->getResultArrayForRequest('organization', $requestParams); - - // Return JSON response with the fetched data - return new JSONResponse($data); - } - - /** - * Retrieve a specific organization by its ID. - * - * @NoAdminRequired - * @NoCSRFRequired - * - * @param string|int $id The ID of the organization to retrieve - * @return JSONResponse JSON response containing the requested organization - */ - public function show(string|int $id): JSONResponse - { - // Fetch the organization object by its ID - $object = $this->objectService->getObject('organization', $id); - - // Return the organization as a JSON response - return new JSONResponse($object); - } - - /** - * Create a new organization. - * - * @NoAdminRequired - * @NoCSRFRequired - * - * @return JSONResponse The response containing the created organization object - */ - 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 organization object - $object = $this->objectService->saveObject('organization', $data); - - // If object is a class change it to array - if (is_object($object) === true) { - $object = $object->jsonSerialize(); - } - - // If we do not have an uri, we need to generate one - if (isset($object['uri']) === false) { - $object['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.organizations.show', ['id' => $object['id']])); - $object = $this->objectService->saveObject('organization', $object); - } - - // Return the created object as a JSON response - return new JSONResponse($object); - } - - /** - * Update an existing organization. - * - * @NoAdminRequired - * @NoCSRFRequired - * - * @param string|int $id The ID of the organization to update - * @return JSONResponse The response containing the updated organization object - */ - public function update(string|int $id): JSONResponse - { - // Get all parameters from the request - $data = $this->request->getParams(); - - // Ensure the ID in the data matches the ID in the URL - $data['id'] = $id; - - // If we do not have an uri, we need to generate one - $data['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.organizations.show', ['id' => $data['id']])); - - // Save the updated organization object - $object = $this->objectService->saveObject('organization', $data); - - // Return the updated object as a JSON response - return new JSONResponse($object); - } - - /** - * Delete an organization. - * - * @NoAdminRequired - * @NoCSRFRequired - * - * @param string|int $id The ID of the organization to delete - * @return JSONResponse The response indicating the result of the deletion - */ - public function destroy(string|int $id): JSONResponse - { - // Delete the organization object - $result = $this->objectService->deleteObject('organization', $id); - - // Return the result as a JSON response - return new JSONResponse(['success' => $result], $result === true ? '200' : '404'); - } -} diff --git a/lib/Controller/PagesController.php b/lib/Controller/PagesController.php deleted file mode 100644 index d10ef7d5..00000000 --- a/lib/Controller/PagesController.php +++ /dev/null @@ -1,145 +0,0 @@ -request->getParams(); - - // Fetch page objects based on filters and order - $data = $this->objectService->getResultArrayForRequest('page', $requestParams); - - // Return JSON response - return new JSONResponse($data); - } - - /** - * Retrieve a specific page by its ID. - * - * @param string|int $id The ID of the page to retrieve - * @return JSONResponse JSON response containing the requested page - * - * @NoAdminRequired - * @NoCSRFRequired - */ - public function show(string|int $id): JSONResponse - { - // Fetch the page object by its ID - $object = $this->objectService->getObject('page', $id); - - // Return the page as a JSON response - return new JSONResponse($object); - } - - /** - * Create a new page. - * - * @return JSONResponse The response containing the created page object. - * - * @NoAdminRequired - * @NoCSRFRequired - */ - 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 page object - $object = $this->objectService->saveObject('page', $data); - - // Return the created object as a JSON response - return new JSONResponse($object); - } - - /** - * Update an existing page. - * - * @param string|int $id The ID of the page to update. - * @return JSONResponse The response containing the updated page object. - * - * @NoAdminRequired - * @NoCSRFRequired - */ - public function update(string|int $id): JSONResponse - { - // Get all parameters from the request - $data = $this->request->getParams(); - - // Ensure the ID in the data matches the ID in the URL - $data['id'] = $id; - - // Save the updated page object - $object = $this->objectService->saveObject('page', $data); - - // Return the updated object as a JSON response - return new JSONResponse($object); - } - - /** - * Delete a page. - * - * @param string|int $id The ID of the page to delete. - * @return JSONResponse The response indicating the result of the deletion. - * - * @NoAdminRequired - * @NoCSRFRequired - */ - public function destroy(string|int $id): JSONResponse - { - // Delete the page object - $result = $this->objectService->deleteObject('page', $id); - - // Return the result as a JSON response - return new JSONResponse(['success' => $result], $result === true ? '200' : '404'); - } -} diff --git a/lib/Controller/ThemesController.php b/lib/Controller/ThemesController.php deleted file mode 100644 index b5233943..00000000 --- a/lib/Controller/ThemesController.php +++ /dev/null @@ -1,161 +0,0 @@ -request->getParams(); - - // Fetch theme objects based on filters and order - $data = $this->objectService->getResultArrayForRequest('theme', $requestParams); - - // Return JSON response - return new JSONResponse($data); - } - - /** - * Retrieve a specific theme by its ID. - * - * @param string|int $id The ID of the theme to retrieve - * @return JSONResponse JSON response containing the requested theme - * - * @NoAdminRequired - * @NoCSRFRequired - */ - public function show(string|int $id): JSONResponse - { - // Fetch the theme object by its ID - $object = $this->objectService->getObject('theme', $id); - - // Return the theme as a JSON response - return new JSONResponse($object); - } - - /** - * Create a new theme. - * - * @return JSONResponse The response containing the created theme object. - * - * @NoAdminRequired - * @NoCSRFRequired - */ - 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 theme object - $object = $this->objectService->saveObject('theme', $data); - - // If object is a class change it to array - if (is_object($object) === true) { - $object = $object->jsonSerialize(); - } - - // If we do not have an uri, we need to generate one - if (isset($object['uri']) === false) { - $object['uri'] = $this->urlGenerator->getAbsoluteURL($$this->urlGenerator->linkToRoute('openCatalogi.themes.show', ['id' => $object['id']])); - $object = $this->objectService->saveObject('theme', $object); - } - - // Return the created object as a JSON response - return new JSONResponse($object); - } - - /** - * Update an existing theme. - * - * @param string|int $id The ID of the theme to update. - * @return JSONResponse The response containing the updated theme object. - * - * @NoAdminRequired - * @NoCSRFRequired - */ - public function update(string|int $id): JSONResponse - { - // Get all parameters from the request - $data = $this->request->getParams(); - - // Ensure the ID in the data matches the ID in the URL - $data['id'] = $id; - - // If we do not have an uri, we need to generate one - $data['uri'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('openCatalogi.themes.show', ['id' => $data['id']])); - - // Save the updated theme object - $object = $this->objectService->saveObject('theme', $data); - - // Return the updated object as a JSON response - return new JSONResponse($object); - } - - /** - * Delete a theme. - * - * @param string|int $id The ID of the theme to delete. - * @return JSONResponse The response indicating the result of the deletion. - * - * @NoAdminRequired - * @NoCSRFRequired - */ - public function destroy(string|int $id): JSONResponse - { - // Delete the theme object - $result = $this->objectService->deleteObject('theme', $id); - - // Return the result as a JSON response - return new JSONResponse(['success' => $result], $result === true ? '200' : '404'); - } -} diff --git a/src/store/modules/catalogi.ts b/src/store/modules/catalogi.ts index 9f1fcec0..9e430980 100644 --- a/src/store/modules/catalogi.ts +++ b/src/store/modules/catalogi.ts @@ -2,7 +2,7 @@ import { defineStore } from 'pinia' import { Catalogi, TCatalogi } from '../../entities/index.js' -const apiEndpoint = '/index.php/apps/opencatalogi/api/catalogi' +const apiEndpoint = '/index.php/apps/opencatalogi/api/objects/catalog' interface Options { /** diff --git a/src/store/modules/organization.ts b/src/store/modules/organization.ts index ce848b24..17c73bab 100644 --- a/src/store/modules/organization.ts +++ b/src/store/modules/organization.ts @@ -2,7 +2,7 @@ import { defineStore } from 'pinia' import { Organization, TOrganization } from '../../entities/index.js' -const apiEndpoint = '/index.php/apps/opencatalogi/api/organizations' +const apiEndpoint = '/index.php/apps/opencatalogi/api/objects/organization' interface OrganizationStoreState { organizationItem: Organization; diff --git a/src/store/modules/page.ts b/src/store/modules/page.ts index 0d132a7c..65ec9b61 100644 --- a/src/store/modules/page.ts +++ b/src/store/modules/page.ts @@ -2,7 +2,7 @@ import { Page, TPage } from '../../entities/index.js' import { defineStore } from 'pinia' -const apiEndpoint = '/index.php/apps/opencatalogi/api/pages' +const apiEndpoint = '/index.php/apps/opencatalogi/api/objects/page' interface Options { /** diff --git a/src/store/modules/publication.ts b/src/store/modules/publication.ts index 24b8fd72..7a5a871f 100644 --- a/src/store/modules/publication.ts +++ b/src/store/modules/publication.ts @@ -3,7 +3,7 @@ import pinia from '../../pinia' import { Attachment, Publication, TAttachment, TPublication } from '../../entities/index.js' import { defineStore } from 'pinia' -const apiEndpoint = '/index.php/apps/opencatalogi/api/publications' +const apiEndpoint = '/index.php/apps/opencatalogi/api/objects/publication' interface Options { /** diff --git a/src/store/modules/publicationType.ts b/src/store/modules/publicationType.ts index 887bab96..966bbf0d 100644 --- a/src/store/modules/publicationType.ts +++ b/src/store/modules/publicationType.ts @@ -2,7 +2,7 @@ import { defineStore } from 'pinia' import { PublicationType, TPublicationType } from '../../entities/index.js' -const apiEndpoint = '/index.php/apps/opencatalogi/api/publication_types' +const apiEndpoint = '/index.php/apps/opencatalogi/api/objects/publicationType' interface PublicationTypeStoreState { publicationTypeItem: PublicationType; diff --git a/src/store/modules/theme.ts b/src/store/modules/theme.ts index f60d404c..a614e7ed 100644 --- a/src/store/modules/theme.ts +++ b/src/store/modules/theme.ts @@ -2,7 +2,7 @@ import { Theme, TTheme } from '../../entities/index.js' import { defineStore } from 'pinia' -const apiEndpoint = '/index.php/apps/opencatalogi/api/themes' +const apiEndpoint = '/index.php/apps/opencatalogi/api/objects/theme' interface Options { /**