Skip to content

Commit

Permalink
Merge pull request #102 from ConductionNL/development
Browse files Browse the repository at this point in the history
Development to main
  • Loading branch information
MWest2020 authored Oct 16, 2024
2 parents 9d306fe + 86f6ce4 commit 12826a5
Show file tree
Hide file tree
Showing 57 changed files with 1,323 additions and 544 deletions.
8 changes: 4 additions & 4 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
'themes' => ['url' => '/api/themes'],
'attachments' => ['url' => '/api/attachments'],
'catalogi' => ['url' => '/api/catalogi'],
'listing' => ['url' => '/api/listing'],
'listings' => ['url' => '/api/listings'],
],
'routes' => [
// Custom
// Custom
['name' => 'listing#synchronise', 'url' => '/api/listing/synchronise/{id?}', 'verb' => 'POST'],
['name' => 'directory#index', 'url' => '/api/directory', 'verb' => 'GET'],
['name' => 'directory#view', 'url' => '/api/directory/{id}', 'verb' => 'GET'],
Expand All @@ -33,7 +33,7 @@
['name' => 'search#publications', 'url' => '/api/search/publications', 'verb' => 'GET'],
['name' => 'search#publication', 'url' => '/api/search/publications/{publicationId}', 'verb' => 'GET', 'requirements' => ['publicationId' => '\d+']],
['name' => 'search#attachments', 'url' => '/api/search/publications/{publicationId}/attachments', 'verb' => 'GET', 'requirements' => ['publicationId' => '\d+']],
['name' => 'search#theme', 'url' => '/api/search/themes', 'verb' => 'GET'],
['name' => 'search#themes', 'url' => '/api/search/themes/{themeId}', 'verb' => 'GET', 'requirements' => ['themeId' => '\d+']]
['name' => 'search#themes', 'url' => '/api/search/themes', 'verb' => 'GET'],
['name' => 'search#theme', 'url' => '/api/search/themes/{themeId}', 'verb' => 'GET', 'requirements' => ['themeId' => '\d+']]
]
];
12 changes: 6 additions & 6 deletions composer-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ function checkPlatform(&$warnings, $quiet, $disableTls, $install)
unset($warnings['openssl']);
}

if (!empty($errors)) {
if (empty($errors) === false) {
// Composer-Setup.exe uses "Some settings" to flag platform errors
out('Some settings on your machine make Composer unable to work properly.', 'error');
out('Make sure that you fix the issues listed below and run this script again:', 'error');
Expand Down Expand Up @@ -517,7 +517,7 @@ function outputIssues($issues)
*/
function showWarnings($warnings)
{
if (!empty($warnings)) {
if (empty($warnings) === false) {
out('Some settings on your machine may cause stability issues with Composer.', 'error');
out('If you encounter issues, try to change the following:', 'error');
outputIssues($warnings);
Expand Down Expand Up @@ -1347,7 +1347,7 @@ public function __construct($disableTls = false, $cafile = false)
{
$this->disableTls = $disableTls;
if ($this->disableTls === false) {
if (!empty($cafile) && !is_dir($cafile)) {
if (empty($cafile) === false && is_dir($cafile) === false) {
if (!is_readable($cafile) || !validateCaFile(file_get_contents($cafile))) {
throw new RuntimeException('The configured cafile (' .$cafile. ') was not valid or could not be read.');
}
Expand Down Expand Up @@ -1506,7 +1506,7 @@ protected function getMergedStreamContext($url)
}

// Prefer CGI_HTTP_PROXY if available
if (!empty($_SERVER['CGI_HTTP_PROXY'])) {
if (empty($_SERVER['CGI_HTTP_PROXY']) === false) {
$proxy = parse_url($_SERVER['CGI_HTTP_PROXY']);
}

Expand All @@ -1516,8 +1516,8 @@ protected function getMergedStreamContext($url)
}

// Remove proxy if URL matches no_proxy directive
if (!empty($_SERVER['NO_PROXY']) || !empty($_SERVER['no_proxy']) && parse_url($url, PHP_URL_HOST)) {
$pattern = new NoProxyPattern(!empty($_SERVER['no_proxy']) ? $_SERVER['no_proxy'] : $_SERVER['NO_PROXY']);
if (empty($_SERVER['NO_PROXY']) === false || empty($_SERVER['no_proxy']) === false && parse_url($url, PHP_URL_HOST) === true) {
$pattern = new NoProxyPattern(empty($_SERVER['no_proxy']) === false ? $_SERVER['no_proxy'] : $_SERVER['NO_PROXY']);
if ($pattern->test($url)) {
unset($proxy);
}
Expand Down
6 changes: 6 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
border-bottom: 1px solid var(--color-border);
}

.emptyListHeader {
margin-block-start: var(--OC-margin-10);
margin-inline-start: var(--OC-margin-10);
margin-inline-end: var(--OC-margin-10);
}

.searchField {
padding-inline-start: 65px;
padding-inline-end: 20px;
Expand Down
16 changes: 8 additions & 8 deletions lib/Controller/AttachmentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function index(ObjectService $objectService): JSONResponse

// Fetch attachment objects based on filters and order
$data = $this->objectService->getResultArrayForRequest('attachment', $requestParams);

// Return JSON response
return new JSONResponse($data);
}
Expand Down Expand Up @@ -102,13 +102,13 @@ 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 attachment object
$object = $this->objectService->saveObject('attachment', $data);

// Return the created object as a JSON response
return new JSONResponse($object);
}
Expand All @@ -127,13 +127,13 @@ public function update(string|int $id, ObjectService $objectService): JSONRespon
{
// 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 attachment object
$object = $this->objectService->saveObject('attachment', $data);

// Return the updated object as a JSON response
return new JSONResponse($object);
}
Expand All @@ -152,9 +152,9 @@ public function destroy(string|int $id, ObjectService $objectService): JSONRespo
{
// Delete the attachment object
$result = $this->objectService->deleteObject('attachment', $id);

// Return the result as a JSON response
return new JSONResponse(['success' => $result]);
return new JSONResponse(['success' => $result], $result === true ? '200' : '404');
}

/**
Expand Down
81 changes: 51 additions & 30 deletions lib/Controller/CatalogiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

namespace OCA\OpenCatalogi\Controller;

use GuzzleHttp\Exception\GuzzleException;
use OCA\OpenCatalogi\Db\CatalogMapper;
use OCA\OpenCatalogi\Service\DirectoryService;
use OCA\OpenCatalogi\Service\ObjectService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IAppConfig;
use OCP\IRequest;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

/**
* Class CatalogiController
Expand All @@ -27,13 +30,15 @@ class CatalogiController extends Controller
* @param IAppConfig $config The app configuration
* @param CatalogMapper $catalogMapper The catalog mapper
* @param ObjectService $objectService The object service
* @param DirectoryService $directoryService The directory service
*/
public function __construct(
$appName,
IRequest $request,
private readonly IAppConfig $config,
private readonly CatalogMapper $catalogMapper,
private readonly ObjectService $objectService
private readonly ObjectService $objectService,
private readonly DirectoryService $directoryService
)
{
parent::__construct($appName, $request);
Expand All @@ -43,7 +48,9 @@ public function __construct(
* Retrieve a list of catalogs based on provided filters and parameters.
*
* @param ObjectService $objectService Service to handle object operations
*
* @return JSONResponse JSON response containing the list of catalogs and total count
* @throws DoesNotExistException|MultipleObjectsReturnedException|ContainerExceptionInterface|NotFoundExceptionInterface
*
* @NoAdminRequired
* @NoCSRFRequired
Expand All @@ -55,7 +62,7 @@ public function index(ObjectService $objectService): JSONResponse

// Fetch catalog objects based on filters and order
$data = $this->objectService->getResultArrayForRequest('catalog', $requestParams);

// Return JSON response
return new JSONResponse($data);
}
Expand All @@ -65,7 +72,9 @@ public function index(ObjectService $objectService): JSONResponse
*
* @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
Expand All @@ -79,51 +88,61 @@ public function show(string|int $id, ObjectService $objectService): JSONResponse
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.
*
* @NoAdminRequired
* @NoCSRFRequired
*/
/**
* 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);


$this->directoryService->updateAllExternalDirectories();

// 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.
*
* @NoAdminRequired
* @NoCSRFRequired
*/
/**
* 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;

// Save the updated catalog object
$object = $this->objectService->saveObject('catalog', $data);


$this->directoryService->updateAllExternalDirectories();

// Return the updated object as a JSON response
return new JSONResponse($object);
}
Expand All @@ -133,17 +152,19 @@ public function update(string|int $id, ObjectService $objectService): JSONRespon
*
* @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]);
return new JSONResponse(['success' => $result], $result === true ? '200' : '404');
}
}
2 changes: 2 additions & 0 deletions lib/Controller/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCA\OpenCatalogi\Service\ObjectService;


/**
* Class ConfigurationController
Expand Down
23 changes: 17 additions & 6 deletions lib/Controller/DirectoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

namespace OCA\OpenCatalogi\Controller;

use GuzzleHttp\Exception\GuzzleException;
use OCA\OpenCatalogi\Db\ListingMapper;
use OCA\OpenCatalogi\Service\DirectoryService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IAppConfig;
use OCP\IRequest;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

/**
* Controller for handling directory-related operations
Expand Down Expand Up @@ -39,39 +43,44 @@ public function __construct(
/**
* Retrieve all directories
*
* @return JSONResponse The JSON response containing all directories
* @throws DoesNotExistException|MultipleObjectsReturnedException|ContainerExceptionInterface|NotFoundExceptionInterface
*
* @PublicPage
* @NoCSRFRequired
* @return JSONResponse The JSON response containing all directories
*/
public function index(): JSONResponse
{
// Get all directories from the directory service
$data = $this->directoryService->getDirectories();

// Return JSON response with the directory data
return new JSONResponse($data);
}

/**
* Update an external directory
*
* @return JSONResponse The JSON response containing the update result
* @throws DoesNotExistException|MultipleObjectsReturnedException|ContainerExceptionInterface|NotFoundExceptionInterface
* @throws GuzzleException
*
* @PublicPage
* @NoCSRFRequired
* @return JSONResponse The JSON response containing the update result
*/
public function update(): JSONResponse
{
// Get the URL from the request parameters
$url = $this->request->getParam('url');

// Check if the URL parameter is provided
if (!$url) {
return new JSONResponse(['error' => 'URL parameter is required'], 400);
if (empty($url) === true) {
return new JSONResponse(['error' => 'url parameter is required'], 400);
}

// Sync the external directory with the provided URL
$data = $this->directoryService->syncExternalDirectory($url);

// Return JSON response with the sync result
return new JSONResponse($data);
}
Expand All @@ -88,6 +97,8 @@ public function show(string|int $id): JSONResponse
{
// TODO: Implement the logic to retrieve and return the specific directory
// This method is currently empty and needs to be implemented

return new JSONResponse([]);
}

}
Loading

0 comments on commit 12826a5

Please sign in to comment.