diff --git a/app/Http/Controllers/LocationController.php b/app/Http/Controllers/LocationController.php index b45c26b..a82b1ba 100644 --- a/app/Http/Controllers/LocationController.php +++ b/app/Http/Controllers/LocationController.php @@ -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), diff --git a/app/Http/Resources/LocationCollection.php b/app/Http/Resources/LocationCollection.php new file mode 100644 index 0000000..57e246a --- /dev/null +++ b/app/Http/Resources/LocationCollection.php @@ -0,0 +1,24 @@ + + */ + public function toArray(Request $request): array + { + //return parent::toArray($request); + + return [ + 'listingCount' => count($this->collection), + 'locations' => LocationResource::collection($this->collection), + ]; + } +} diff --git a/app/Http/Resources/LocationResource.php b/app/Http/Resources/LocationResource.php new file mode 100644 index 0000000..5424f27 --- /dev/null +++ b/app/Http/Resources/LocationResource.php @@ -0,0 +1,26 @@ + + */ + 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, + ]; + } +} diff --git a/resources/views/front/about.blade.php b/resources/views/front/about.blade.php index f3fb414..ad16afc 100644 --- a/resources/views/front/about.blade.php +++ b/resources/views/front/about.blade.php @@ -59,16 +59,18 @@
         {
-        "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"
+                    }
+                  ]
             }
-          ]
         }
         

diff --git a/routes/api.php b/routes/api.php index 889937e..2a1f64a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -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); +});