Skip to content

Commit e5f636e

Browse files
committed
Extend wiki details with profile data
1 parent 60c7b3d commit e5f636e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

app/Http/Controllers/WikiController.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
use App\WikiProfile;
1818
use App\WikiSetting;
1919
use Illuminate\Http\Request;
20-
use Illuminate\Support\Facades\App;
2120
use Illuminate\Support\Facades\DB;
22-
use Illuminate\Support\Facades\Validator;
2321
use Illuminate\Support\Str;
2422
use Illuminate\Support\Facades\Config;
2523
use App\Helper\DomainValidator;
@@ -63,14 +61,14 @@ public function create(Request $request): \Illuminate\Http\Response
6361
'username' => 'required',
6462
'profile' => 'nullable|json',
6563
]);
66-
64+
6765
$rawProfile = false;
6866
if ($request->filled('profile') ) {
6967
$rawProfile = json_decode($request->input('profile'), true);
7068
$profileValidator = $this->profileValidator->validate($rawProfile);
7169
$profileValidator->validateWithBag('post');
7270
}
73-
71+
7472
$wiki = null;
7573
$dbAssignment = null;
7674

@@ -160,12 +158,12 @@ public function create(Request $request): \Illuminate\Http\Response
160158
'user_id' => $user->id,
161159
'wiki_id' => $wiki->id,
162160
]);
163-
161+
164162
// Create WikiProfile
165163
if ($rawProfile) {
166164
WikiProfile::create([ 'wiki_id' => $wiki->id, ...$rawProfile ] );
167165
}
168-
166+
169167

170168
// TODO maybe always make these run in a certain order..?
171169
dispatch(new MediawikiInit($wiki->domain, $request->input('username'), $user->email));
@@ -250,6 +248,7 @@ public function getWikiDetailsForIdForOwner(Request $request): \Illuminate\Http\
250248
$wiki = Wiki::where('id', $wikiId)
251249
->with('wikiManagers')
252250
->with('wikiDbVersion')
251+
->with('wikiLatestProfile')
253252
->with('publicSettings')->first();
254253

255254
$res = [

app/Wiki.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,8 @@ public static function getSiteDirectory( int $wiki_id ): string {
182182
public function getDomainDecodedAttribute(): string {
183183
return DomainHelper::decode($this->domain);
184184
}
185+
186+
public function wikiLatestProfile() {
187+
return $this->hasOne(WikiProfile::class)->latestOfMany();
188+
}
185189
}

routes/api.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
$router->post('create', ['uses' => 'WikiController@create']);
4141
$router->post('delete', ['uses' => 'WikiController@delete']);
4242
$router->post('details', ['uses' => 'WikiController@getWikiDetailsForIdForOwner']);
43+
$router->get('details', ['uses' => 'WikiController@getWikiDetailsForIdForOwner']);
4344
$router->post('logo/update', ['uses' => 'WikiLogoController@update']);
4445
$router->post('setting/{setting}/update', ['uses' => 'WikiSettingController@update']);
4546
// TODO should wiki managers really be here?

0 commit comments

Comments
 (0)