Added public search API

Finally moved over the public search API from the old version and
updated the about page to show the new data structure

Also tweaked the location update script to change 'defederate' to
'suspend' for the sake of consistency
develop
Ro 1 year ago
parent d5efbd96a3
commit 0c2b8bae7c
Signed by: are0h
GPG Key ID: 29B551CDBD4D3B50

@ -147,7 +147,7 @@ class LocationController extends Controller
'url' => $item['url'],
'description' => ($item['comment'] != null) ? $item['comment'] : "no description",
'active' => true,
'rating' => $item['rating'],
'rating' => ($item['rating'] == 'defederate') ? 'suspend',
'added_by' => 1,
'tags' => 'poor moderation, hate speech',
'images' => json_encode($images),

@ -0,0 +1,24 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
class LocationCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @return array<int|string, mixed>
*/
public function toArray(Request $request): array
{
//return parent::toArray($request);
return [
'listingCount' => count($this->collection),
'locations' => LocationResource::collection($this->collection),
];
}
}

@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class LocationResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'url' => $this->url,
'name' => $this->name,
'description' => $this->description,
'rating' => $this->rating,
'count' => $this->block_count,
'link' => "/location/" . $this->uuid,
];
}
}

@ -59,16 +59,18 @@
<pre>
<code>{
"listingCount":1,
"locations":
[
{
"url":"search.url",
"name":"Instance Name",
"description":"instance description",
"link":"bad-space-instance-link"
data:{
"listingCount":1,
"locations":
[
{
"url":"search.url",
"name":"Instance Name",
"description":"instance description",
"link":"bad-space-instance-link"
}
]
}
]
}</code>
</pre>
</p>

@ -2,6 +2,8 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\DB;
use App\Http\Resources\LocationCollection;
/*
|--------------------------------------------------------------------------
@ -17,3 +19,13 @@ use Illuminate\Support\Facades\Route;
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
// public search API
Route::post("/v1/search", function (Request $request) {
$data = json_decode($request->getContent());
$search = $data->url;
$search = str_replace(",", "", $search);
$search = str_replace(" ", "|", $search);
$results = DB::select("SELECT * FROM searchlocations('$search')");
return new LocationCollection($results);
});

Loading…
Cancel
Save