|
7 | 7 | use Illuminate\Http\Request; |
8 | 8 |
|
9 | 9 | class WikiController extends Controller { |
10 | | - private static $with = ['wikiDb', 'wikiQueryserviceNamespace', 'settings']; |
11 | | - |
12 | 10 | public function getWikiForDomain(Request $request): \Illuminate\Http\JsonResponse { |
13 | | - $domain = $request->input('domain'); |
| 11 | + $validated = $request->validate([ |
| 12 | + 'domain' => 'required|string', |
| 13 | + ]); |
14 | 14 |
|
| 15 | + $domain = $validated['domain']; |
15 | 16 | // XXX: this same logic is in quickstatements.php and platform api WikiController backend |
16 | 17 | 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); |
26 | 21 | } |
27 | 22 |
|
28 | | - if (!$result) { |
| 23 | + if (!$wiki) { |
29 | 24 | return response()->json(['error' => 'Not found'], 404); |
30 | 25 | } |
31 | 26 |
|
32 | | - return response()->json(['data' => $result], 200); |
| 27 | + return response()->json(['data' => $wiki], 200); |
33 | 28 | } |
34 | 29 | } |
0 commit comments