From e854490fd49d09ab07f4583a4415d5659e420763 Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Thu, 7 Nov 2024 07:33:30 +0100 Subject: [PATCH 1/3] Making the mapping service ussable for other nextcloud applications --- lib/Service/MappingService.php | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/Service/MappingService.php b/lib/Service/MappingService.php index 9e222561..4cd47b95 100644 --- a/lib/Service/MappingService.php +++ b/lib/Service/MappingService.php @@ -415,4 +415,40 @@ public function coordinateStringToArray(string $coordinates): array }//end coordinateStringToArray() + + /** + * Retrieves a single mapping by its ID. + * + * This is a wrapper function that provides controlled access to the mapping mapper. + * We use this wrapper pattern to ensure other Nextcloud apps can only interact with + * mappings through this service layer, rather than accessing the mapper directly. + * This maintains proper encapsulation and separation of concerns. + * + * @param string $mappingId The unique identifier of the mapping to retrieve + * @return Mapping The requested mapping entity + * @throws \OCP\AppFramework\Db\DoesNotExistException If mapping is not found + * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException If multiple mappings found + */ + public function getMapping(string $mappingId): Mapping + { + // Forward the find request to the mapper while maintaining encapsulation + return $this->mappingMapper->find($mappingId); + } + + /** + * Retrieves all available mappings. + * + * This is a wrapper function that provides controlled access to the mapping mapper. + * We use this wrapper pattern to ensure other Nextcloud apps can only interact with + * mappings through this service layer, rather than accessing the mapper directly. + * This maintains proper encapsulation and separation of concerns. + * + * @return array An array containing all mapping entities + */ + public function getMappings(): array + { + // Forward the findAll request to the mapper while maintaining encapsulation + return $this->mappingMapper->findAll(); + } + } From 98c7289cd9b7d47bef660f5256d67feff9f104a3 Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Thu, 7 Nov 2024 07:35:11 +0100 Subject: [PATCH 2/3] Declared todo --- lib/Service/MappingService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Service/MappingService.php b/lib/Service/MappingService.php index 4cd47b95..bdad011c 100644 --- a/lib/Service/MappingService.php +++ b/lib/Service/MappingService.php @@ -448,6 +448,7 @@ public function getMapping(string $mappingId): Mapping public function getMappings(): array { // Forward the findAll request to the mapper while maintaining encapsulation + // @todo: add filtering options return $this->mappingMapper->findAll(); } From 791dc23cf48572743df2345147c5e9646039ed66 Mon Sep 17 00:00:00 2001 From: Thijn Date: Thu, 7 Nov 2024 16:50:04 +0100 Subject: [PATCH 3/3] fixed objects mapping --- lib/Service/MappingService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Service/MappingService.php b/lib/Service/MappingService.php index bdad011c..8111fa7a 100644 --- a/lib/Service/MappingService.php +++ b/lib/Service/MappingService.php @@ -36,11 +36,11 @@ class MappingService */ public function __construct( ArrayLoader $loader, - MappingMapper $mappingMapper + private readonly MappingMapper $mappingMapper ) { $this->twig = new Environment($loader); $this->twig->addExtension(new MappingExtension()); - $this->twig->addRuntimeLoader(new MappingRuntimeLoader(mappingService: $this, mappingMapper: $mappingMapper)); + $this->twig->addRuntimeLoader(new MappingRuntimeLoader(mappingService: $this, mappingMapper: $this->mappingMapper)); }//end __construct()