Skip to content

Commit a98246b

Browse files
committed
cleanup
1 parent bcbea7c commit a98246b

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

app/Http/Controllers/Backend/WikiController.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,23 @@
77
use Illuminate\Http\Request;
88

99
class WikiController extends Controller {
10-
private static $with = ['wikiDb', 'wikiQueryserviceNamespace', 'settings'];
11-
1210
public function getWikiForDomain(Request $request): \Illuminate\Http\JsonResponse {
13-
$domain = $request->input('domain');
11+
$validated = $request->validate([
12+
'domain' => 'required|string',
13+
]);
1414

15+
$domain = $validated['domain'];
1516
// XXX: this same logic is in quickstatements.php and platform api WikiController backend
1617
try {
17-
if ($domain === 'localhost' || $domain === 'mediawiki') {
18-
// If just using localhost then just get the first undeleted wiki
19-
$result = Wiki::with(self::$with)->first();
20-
} else {
21-
// TODO don't select the timestamps and redundant info for the settings?
22-
$result = Wiki::where('domain', $domain)->with(self::$with)->first();
23-
}
24-
} catch (\Exception $ex) {
25-
return response()->json($ex->getMessage(), 500);
18+
$wiki = Wiki::with(['wikiDb', 'wikiQueryserviceNamespace', 'settings'])->firstWhere('domain', $domain);
19+
} catch (\Exception $e) {
20+
return response()->json($e->getMessage(), 500);
2621
}
2722

28-
if (!$result) {
23+
if (!$wiki) {
2924
return response()->json(['error' => 'Not found'], 404);
3025
}
3126

32-
return response()->json(['data' => $result], 200);
27+
return response()->json(['data' => $wiki], 200);
3328
}
3429
}

0 commit comments

Comments
 (0)