From b8eda54267e36822eddca41f3a0b56bdaa0d34de Mon Sep 17 00:00:00 2001 From: Ro Date: Mon, 10 Apr 2023 13:34:52 -0700 Subject: [PATCH] Added Public Search API Added the first version of the method that can be used to search the DB programatically. Making it public for now. --- composer.json | 1 + composer.lock | 103 ++++++++++++++++++++++++++- src/Controller/Routes/API/Search.php | 55 ++++++++++++++ 3 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 src/Controller/Routes/API/Search.php diff --git a/composer.json b/composer.json index 03aee07..c0ae5f9 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "symfony/proxy-manager-bridge": "6.1.*", "symfony/runtime": "6.1.*", "symfony/security-csrf": "6.1.*", + "symfony/serializer": "6.1.*", "symfony/twig-bundle": "6.1.*", "symfony/uid": "6.1.*", "symfony/yaml": "6.1.*", diff --git a/composer.lock b/composer.lock index dc6a7fe..91e7999 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f31b264b29ff1c91409f2abfcd475ad0", + "content-hash": "18bd0f15ee53f2ad2db2d20860095ca3", "packages": [ { "name": "doctrine/annotations", @@ -4616,6 +4616,107 @@ ], "time": "2022-05-14T12:53:54+00:00" }, + { + "name": "symfony/serializer", + "version": "v6.1.11", + "source": { + "type": "git", + "url": "https://github.com/symfony/serializer.git", + "reference": "5761725c7d007ef8fed3cb425be866a772977ad4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/serializer/zipball/5761725c7d007ef8fed3cb425be866a772977ad4", + "reference": "5761725c7d007ef8fed3cb425be866a772977ad4", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/polyfill-ctype": "~1.8" + }, + "conflict": { + "doctrine/annotations": "<1.12", + "phpdocumentor/reflection-docblock": "<3.2.2", + "phpdocumentor/type-resolver": "<1.4.0|>=1.7.0", + "symfony/dependency-injection": "<5.4", + "symfony/property-access": "<5.4", + "symfony/property-info": "<5.4", + "symfony/uid": "<5.4", + "symfony/yaml": "<5.4" + }, + "require-dev": { + "doctrine/annotations": "^1.12|^2", + "phpdocumentor/reflection-docblock": "^3.2|^4.0|^5.0", + "symfony/cache": "^5.4|^6.0", + "symfony/config": "^5.4|^6.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/error-handler": "^5.4|^6.0", + "symfony/filesystem": "^5.4|^6.0", + "symfony/form": "^5.4|^6.0", + "symfony/http-foundation": "^5.4|^6.0", + "symfony/http-kernel": "^5.4|^6.0", + "symfony/mime": "^5.4|^6.0", + "symfony/property-access": "^5.4|^6.0", + "symfony/property-info": "^5.4|^6.0", + "symfony/uid": "^5.4|^6.0", + "symfony/validator": "^5.4|^6.0", + "symfony/var-dumper": "^5.4|^6.0", + "symfony/var-exporter": "^5.4|^6.0", + "symfony/yaml": "^5.4|^6.0" + }, + "suggest": { + "psr/cache-implementation": "For using the metadata cache.", + "symfony/config": "For using the XML mapping loader.", + "symfony/mime": "For using a MIME type guesser within the DataUriNormalizer.", + "symfony/property-access": "For using the ObjectNormalizer.", + "symfony/property-info": "To deserialize relations.", + "symfony/var-exporter": "For using the metadata compiler.", + "symfony/yaml": "For using the default YAML mapping loader." + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Serializer\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/serializer/tree/v6.1.11" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-01-20T17:44:30+00:00" + }, { "name": "symfony/service-contracts", "version": "v3.1.1", diff --git a/src/Controller/Routes/API/Search.php b/src/Controller/Routes/API/Search.php new file mode 100644 index 0000000..32b8318 --- /dev/null +++ b/src/Controller/Routes/API/Search.php @@ -0,0 +1,55 @@ +getMethod() == "GET") { + return new Response("LOL, nice try"); + } else { + $encoders = [new JsonEncoder()]; + $normalizers = [new ObjectNormalizer()]; + $serializer = new Serializer($normalizers, $encoders); + $response = []; + + $data = json_decode($request->getContent(), true); + $list = $locations->searchLocations(($data['url'])); + $entries = []; + foreach ($list['items'] as $entry) { + array_push($entries, ["url" => $entry['url'], + "name" => $entry['name'], + "description" => $entry['description'], + "link" => "https://thebad.space/location/" . $entry['uuid'] + ]); + } + + $items = ["listingCount" => count($entries), "locations" => $entries]; + + $data = $serializer->serialize($items, "json"); + $response = new Response($data); + $response->headers->set("Content-Type", "application/json"); + return $response; + } + } +}