Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit 215604f

Browse files
committed
[SEARCH] update search to match legacy return format
1 parent f5c5d09 commit 215604f

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

app/Extensions/Services/Maps/MapService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ public function search(string $game, string $query, ?int $age): array {
151151
continue;
152152

153153
$output[] = [
154-
'raw' => $line,
154+
'name' => trim($name),
155+
'game' => $game,
155156
'date' => date('Y-m-d H:i', $date),
156-
'sha1' => $sha1,
157+
'hash' => $sha1,
158+
'raw' => $line,
157159
'url' => $game . '/' . $sha1 . '.zip'
158160
];
159161

app/Http/Controllers/Api/V1/Maps/SearchController.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,22 @@ public function __construct(MapService $mapService)
1919
public function __invoke(SearchMapRequest $request)
2020
{
2121
$inputs = $request->validated();
22+
$raw = $inputs['raw'] ?? false;
2223
$result = $this->mapService->search($inputs['game'], $inputs['search'], $inputs['age'] ?? 0);
2324

24-
return response()->json($result, 200);
25+
if($raw) {
26+
return join(PHP_EOL, array_map(fn($m) => $m['raw'], $result));
27+
}
28+
else {
29+
$out = 'Use the /map command to select or suggest the map on CnCNet (you must be inside of a game room)<br /><br /><br /><br />';
30+
31+
foreach ($result as $map) {
32+
$out .= $map['date'] . ' &emsp;/map ' . $map['hash'] . '&emsp; <A href="./' . $map['game'] . '/' . $map['hash'] . '.zip' . '">' .
33+
strip_tags($map['name']) .
34+
'</a><br /><br />';
35+
}
36+
return $out;
37+
}
38+
2539
}
2640
}

app/Http/Requests/Api/V1/Maps/SearchMapRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function rules(): array
2525
'game' => 'required|string|in:' . join(',', config('cncnet.games')),
2626
'search' => 'required|string|min:3',
2727
'age' => 'nullable|integer|min:0',
28+
'raw' => 'nullable|boolean',
2829
];
2930
}
3031
}

tests/Feature/SearchTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use Illuminate\Foundation\Testing\RefreshDatabase;
6+
use Illuminate\Foundation\Testing\WithFaker;
7+
use Tests\TestCase;
8+
9+
class SearchTest extends TestCase
10+
{
11+
/**
12+
* A basic feature test example.
13+
*/
14+
public function test_example(): void
15+
{
16+
$response = $this->get('/');
17+
18+
$response->assertStatus(200);
19+
}
20+
}

0 commit comments

Comments
 (0)