forked from projects/thebadspace
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.
This commit is contained in:
parent
2b174a96c8
commit
b8eda54267
3 changed files with 158 additions and 1 deletions
|
@ -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.*",
|
||||
|
|
103
composer.lock
generated
103
composer.lock
generated
|
@ -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",
|
||||
|
|
55
src/Controller/Routes/API/Search.php
Normal file
55
src/Controller/Routes/API/Search.php
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
// src/Controller/DataImport.php
|
||||
// Grab data from transfer app
|
||||
|
||||
namespace App\Controller\Routes\API;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
use App\Service\Auth;
|
||||
use App\Service\HandleLocations;
|
||||
|
||||
class Search extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/api/v1/search", name="api-saerch-locations")
|
||||
*/
|
||||
public function handlePublicSearch(
|
||||
Request $request,
|
||||
Auth $auth,
|
||||
HandleLocations $locations
|
||||
): Response {
|
||||
if ($request->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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue