Initial commit

This commit is contained in:
root
2025-12-21 09:59:17 -05:00
committed by Sebastian Krupinski
commit 974d3fe11b
53 changed files with 7555 additions and 0 deletions

View File

@@ -0,0 +1,178 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\ChronoManager\Controllers;
use KTXC\Http\Response\JsonResponse;
use KTXC\SessionIdentity;
use KTXC\SessionTenant;
use KTXF\Controller\ControllerAbstract;
use KTXF\Chrono\Collection\ICollectionBase;
use KTXF\Routing\Attributes\AuthenticatedRoute;
use InvalidArgumentException;
use KTXF\Resource\Selector\SourceSelector;
use KTXM\ChronoManager\Manager;
class CollectionController extends ControllerAbstract {
public function __construct(
private readonly SessionTenant $tenantIdentity,
private readonly SessionIdentity $userIdentity,
private Manager $chronoManager,
) {}
/**
* Retrieve all collections matching criteria
*
* @param SourceSelector|null $sources collection sources
* @param array|null $filter collection filter options
* @param array|null $sort collection sorting options
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/collection/list', name: 'chronomanager.collection.list', methods: ['POST'])]
public function list(?SourceSelector $sources = null, ?array $filter = null, ?array $sort = null, ?string $uid = null): JsonResponse {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// retrieve collections
$responseData = $this->chronoManager->collectionList($tenantId, $userId, $sources, $filter, $sort);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
}
/**
* Confirm if specific collections are available for a specific user
*
* @param SourceSelector $sources collection sources
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/collection/extant', name: 'chronomanager.collection.extant', methods: ['POST'])]
public function extant(SourceSelector $sources, ?string $uid = null): JsonResponse {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// retrieve collection status
$responseData = $this->chronoManager->collectionExtant($tenantId, $userId, $sources);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
}
/**
* Fetch a collection
*
* @param string $provider provider identifier
* @param string $service service identifier
* @param string|int $identifier collection identifier
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/collection/fetch', name: 'chronomanager.collection.fetch', methods: ['POST'])]
public function fetch(string $provider, string $service, string|int $identifier, ?string $uid = null): JsonResponse {
try {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// retrieve collection
$responseData = $this->chronoManager->collectionFetch($tenantId, $userId, $provider, $service, $identifier);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
} catch (InvalidArgumentException $e) {
return new JsonResponse(['error' => $e->getMessage()], JsonResponse::HTTP_BAD_REQUEST);
}
}
/**
* Create a collection
*
* @param string $provider provider identifier
* @param string $service service identifier
* @param ICollectionBase|array $data collection to create
* @param array $options additional options
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/collection/create', name: 'chronomanager.collection.create', methods: ['POST'])]
public function create(string $provider, string $service, ICollectionBase|array $data, array $options = [], ?string $uid = null): JsonResponse {
try {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// create collection
$responseData = $this->chronoManager->collectionCreate($tenantId, $userId, $provider, $service, $data, $options);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
} catch (InvalidArgumentException $e) {
return new JsonResponse(['error' => $e->getMessage()], JsonResponse::HTTP_BAD_REQUEST);
}
}
/**
* Modify an existing collection
*
* @param string $provider provider identifier
* @param string $service service identifier
* @param string|int $identifier collection identifier
* @param ICollectionBase|array $data collection data
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/collection/modify', name: 'chronomanager.collection.modify', methods: ['POST'])]
public function modify(string $provider, string $service, string|int $identifier, ICollectionBase|array $data, ?string $uid = null): JsonResponse {
try {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// modify collection
$responseData = $this->chronoManager->collectionModify($tenantId, $userId, $provider, $service, $identifier, $data);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
} catch (InvalidArgumentException $e) {
return new JsonResponse(['error' => $e->getMessage()], JsonResponse::HTTP_BAD_REQUEST);
}
}
/**
* Delete a collection
*
* @param string $provider provider identifier
* @param string $service service identifier
* @param string|int $identifier collection identifier
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/collection/destroy', name: 'chronomanager.collection.destroy', methods: ['POST'])]
public function destroy(string $provider, string $service, string|int $identifier, string|null $uid = null): JsonResponse {
try {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// destroy collection
$success = $this->chronoManager->collectionDestroy($tenantId, $userId, $provider, $service, $identifier);
return new JsonResponse(['success' => $success], $success ? JsonResponse::HTTP_OK : JsonResponse::HTTP_NOT_FOUND);
} catch (InvalidArgumentException $e) {
return new JsonResponse(['error' => $e->getMessage()], JsonResponse::HTTP_BAD_REQUEST);
}
}
}

View File

@@ -0,0 +1,202 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\ChronoManager\Controllers;
use KTXC\Http\Response\JsonResponse;
use KTXC\SessionIdentity;
use KTXC\SessionTenant;
use KTXF\Controller\ControllerAbstract;
use KTXF\Routing\Attributes\AuthenticatedRoute;
use InvalidArgumentException;
use KTXF\Resource\Selector\SourceSelector;
use KTXM\ChronoManager\Manager;
class EntityController extends ControllerAbstract {
public function __construct(
private readonly SessionTenant $tenantIdentity,
private readonly SessionIdentity $userIdentity,
private Manager $chronoManager,
) {}
/**
* List entities for a specific user
*
* @param SourceSelector|null $sources entity sources
* @param array|null $filter entity filter
* @param array|null $sort entity sort
* @param array|null $range entity range
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/entity/list', name: 'chronomanager.entity.list', methods: ['POST'])]
public function list(?SourceSelector $sources = null, ?array $filter = null, ?array $sort = null, ?array $range = null, ?string $uid = null): JsonResponse {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// retrieve entities
$responseData = $this->chronoManager->entityList($tenantId, $userId, $sources, $filter, $sort, $range);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
}
/**
* Delta of entity changes since last request
*
* @param SourceSelector $sources entity sources
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/entity/delta', name: 'chronomanager.entity.delta', methods: ['POST'])]
public function delta(SourceSelector $sources, ?string $uid = null): JsonResponse {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// retrieve entity delta
$responseData = $this->chronoManager->entityDelta($tenantId, $userId, $sources);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
}
/**
* Confirm if specific entities are available for a specific user
*
* @param SourceSelector $sources entity sources
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/entity/extant', name: 'chronomanager.entity.extant', methods: ['POST'])]
public function extant(SourceSelector $sources, ?string $uid = null): JsonResponse {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// retrieve entity status
$responseData = $this->chronoManager->entityExtant($tenantId, $userId, $sources);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
}
/**
* Fetch specific entities from a specific collection
*
* @param string|null $uid user identifier
* @param string $provider provider identifier
* @param string $service service identifier
* @param string|int $collection collection identifier
* @param array<string|int> $identifiers entity identifiers
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/entity/fetch', name: 'chronomanager.entity.fetch', methods: ['POST'])]
public function fetch(string $provider, string $service, string|int $collection, array $identifiers, ?string $uid = null): JsonResponse {
try {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// retrieve entities
$responseData = $this->chronoManager->entityFetch($tenantId, $userId, $provider, $service, $collection, $identifiers);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
} catch (InvalidArgumentException $e) {
return new JsonResponse(['error' => $e->getMessage()], JsonResponse::HTTP_BAD_REQUEST);
}
}
/**
* Create a new entity in a collection
*
* @param string $provider provider identifier
* @param string $service service identifier
* @param string|int $collection collection identifier
* @param array $data entity to create
* @param array $options additional options
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/entity/create', name: 'chronomanager.entity.create', methods: ['POST'])]
public function create(string $provider, string $service, string|int $collection, array $data, array $options = [], ?string $uid = null): JsonResponse {
try {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// create entity
$responseData = $this->chronoManager->entityCreate($tenantId, $userId, $provider, $service, $collection, $data, $options);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
} catch (InvalidArgumentException $e) {
return new JsonResponse(['error' => $e->getMessage()], JsonResponse::HTTP_BAD_REQUEST);
}
}
/**
* Modify an existing entity in a collection
*
* @param string $provider provider identifier
* @param string $service service identifier
* @param string|int $collection collection identifier
* @param string|int $identifier entity identifier
* @param array $entity entity with modifications
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/entity/modify', name: 'chronomanager.entity.modify', methods: ['POST'])]
public function modify(string $provider, string $service, string|int $collection, string|int $identifier, array $data, ?string $uid = null): JsonResponse {
try {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// modify entity
$responseData = $this->chronoManager->entityModify($tenantId, $userId, $provider, $service, $collection, $identifier, $data);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
} catch (InvalidArgumentException $e) {
return new JsonResponse(['error' => $e->getMessage()], JsonResponse::HTTP_BAD_REQUEST);
}
}
/**
* Delete an entity from a collection
*
* @param string $provider provider identifier
* @param string $service service identifier
* @param string|int $collection collection identifier
* @param string|int $identifier entity identifier
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/entity/destroy', name: 'chronomanager.entity.destroy', methods: ['POST'])]
public function destroy(string $provider, string $service, string|int $collection, string|int $identifier, ?string $uid = null): JsonResponse {
try {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// destroy entity
$success = $this->chronoManager->entityDestroy($tenantId, $userId, $provider, $service, $collection, $identifier);
return new JsonResponse(['success' => $success], $success ? JsonResponse::HTTP_OK : JsonResponse::HTTP_NOT_FOUND);
} catch (InvalidArgumentException $e) {
return new JsonResponse(['error' => $e->getMessage()], JsonResponse::HTTP_BAD_REQUEST);
}
}
}

View File

@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\ChronoManager\Controllers;
use KTXC\Http\Response\JsonResponse;
use KTXF\Controller\ControllerAbstract;
use KTXF\Resource\Selector\SourceSelector;
use KTXF\Routing\Attributes\AuthenticatedRoute;
use KTXM\ChronoManager\Manager;
class ProviderController extends ControllerAbstract {
public function __construct(
private Manager $chronoManager,
) {}
/**
* Retrieve list of available providers
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/provider/list', name: 'chronomanager.provider.list', methods: ['GET'])]
public function list(): JsonResponse {
$providers = $this->chronoManager->providerList();
return new JsonResponse($providers, JsonResponse::HTTP_OK);
}
/**
* Confirm which providers are available
*
* @param SourceSelector $sources provider sources
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/provider/extant', name: 'chronomanager.provider.extant', methods: ['POST'])]
public function extant(SourceSelector $sources): JsonResponse {
$responseData = $this->chronoManager->providerExtant($sources);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
}
}

View File

@@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\ChronoManager\Controllers;
use KTXC\Http\Response\JsonResponse;
use KTXC\SessionIdentity;
use KTXC\SessionTenant;
use KTXF\Controller\ControllerAbstract;
use KTXF\Routing\Attributes\AuthenticatedRoute;
use InvalidArgumentException;
use KTXF\Resource\Selector\SourceSelector;
use KTXM\ChronoManager\Manager;
class ServiceController extends ControllerAbstract {
public function __construct(
private readonly SessionTenant $tenantIdentity,
private readonly SessionIdentity $userIdentity,
private Manager $chronoManager,
) {}
/**
* Retrieve services for a specific user
*
* @param SourceSelector|null $sources service sources
* @param array|null $filter service filter options
* @param array|null $sort service sorting options
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/service/list', name: 'chronomanager.service.list', methods: ['POST'])]
public function list(?SourceSelector $sources = null, ?array $filter = null, ?array $sort = null, ?string $uid = null): JsonResponse {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// retrieve services
$responseData = $this->chronoManager->serviceList($tenantId, $userId, $sources, $filter, $sort);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
}
/**
* Confirm if specific services are available for a specific user
*
* @param SourceSelector $sources service sources
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/service/extant', name: 'chronomanager.service.extant', methods: ['POST'])]
public function extant(SourceSelector $sources, ?string $uid = null): JsonResponse {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// retrieve services status
$responseData = $this->chronoManager->serviceExtant($tenantId, $userId, $sources);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
}
/**
* Fetch specific service for a specific user
*
* @param string $provider provider identifier
* @param string $identifier service identifier
* @param string|null $uid user identifier
*
* @return JsonResponse
*/
#[AuthenticatedRoute('/service/fetch', name: 'chronomanager.service.fetch', methods: ['POST'])]
public function fetch(string $provider, string $identifier, ?string $uid = null): JsonResponse {
try {
// authorize request
$tenantId = $this->tenantIdentity->identifier();
$userId = $this->userIdentity->identifier();
// retrieve service
$responseData = $this->chronoManager->serviceFetch($tenantId, $userId, $provider, $identifier);
return new JsonResponse($responseData, JsonResponse::HTTP_OK);
} catch (InvalidArgumentException $e) {
return new JsonResponse(['error' => $e->getMessage()], JsonResponse::HTTP_BAD_REQUEST);
}
}
}