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
This commit is contained in:
parent
d5efbd96a3
commit
0c2b8bae7c
5 changed files with 74 additions and 10 deletions
|
@ -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),
|
||||
|
|
24
app/Http/Resources/LocationCollection.php
Normal file
24
app/Http/Resources/LocationCollection.php
Normal file
|
@ -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),
|
||||
];
|
||||
}
|
||||
}
|
26
app/Http/Resources/LocationResource.php
Normal file
26
app/Http/Resources/LocationResource.php
Normal file
|
@ -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,6 +59,7 @@
|
|||
|
||||
<pre>
|
||||
<code>{
|
||||
data:{
|
||||
"listingCount":1,
|
||||
"locations":
|
||||
[
|
||||
|
@ -69,6 +70,7 @@
|
|||
"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…
Reference in a new issue