Skip to content

Commit 47f5ec3

Browse files
committed
WIP
1 parent 60c7b3d commit 47f5ec3

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
lines changed

app/Http/Controllers/WikiController.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Controllers;
44

55
use App\Helper\ProfileValidator;
6+
use App\Http\Resources\WikiResource;
67
use App\Jobs\KubernetesIngressCreate;
78
use App\Jobs\MediawikiInit;
89
use App\Jobs\ProvisionQueryserviceNamespaceJob;
@@ -17,9 +18,7 @@
1718
use App\WikiProfile;
1819
use App\WikiSetting;
1920
use Illuminate\Http\Request;
20-
use Illuminate\Support\Facades\App;
2121
use Illuminate\Support\Facades\DB;
22-
use Illuminate\Support\Facades\Validator;
2322
use Illuminate\Support\Str;
2423
use Illuminate\Support\Facades\Config;
2524
use App\Helper\DomainValidator;
@@ -63,14 +62,14 @@ public function create(Request $request): \Illuminate\Http\Response
6362
'username' => 'required',
6463
'profile' => 'nullable|json',
6564
]);
66-
65+
6766
$rawProfile = false;
6867
if ($request->filled('profile') ) {
6968
$rawProfile = json_decode($request->input('profile'), true);
7069
$profileValidator = $this->profileValidator->validate($rawProfile);
7170
$profileValidator->validateWithBag('post');
7271
}
73-
72+
7473
$wiki = null;
7574
$dbAssignment = null;
7675

@@ -160,12 +159,12 @@ public function create(Request $request): \Illuminate\Http\Response
160159
'user_id' => $user->id,
161160
'wiki_id' => $wiki->id,
162161
]);
163-
162+
164163
// Create WikiProfile
165164
if ($rawProfile) {
166165
WikiProfile::create([ 'wiki_id' => $wiki->id, ...$rawProfile ] );
167166
}
168-
167+
169168

170169
// TODO maybe always make these run in a certain order..?
171170
dispatch(new MediawikiInit($wiki->domain, $request->input('username'), $user->email));
@@ -264,4 +263,10 @@ public static function isSubDomain( string $domain, string $subDomainSuffix = nu
264263
$subDomainSuffix = $subDomainSuffix ?? Config::get('wbstack.subdomain_suffix');
265264
return preg_match('/' . preg_quote( $subDomainSuffix ) . '$/', $domain) === 1;
266265
}
266+
267+
public function show(Wiki $wiki)
268+
{
269+
$wiki->load('latestProfile');
270+
return new WikiResource($wiki);
271+
}
267272
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Http\Resources;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Http\Resources\Json\JsonResource;
7+
8+
class WikiResource extends JsonResource
9+
{
10+
/**
11+
* Transform the resource into an array.
12+
*
13+
* @return array<string, mixed>
14+
*/
15+
public function toArray(Request $request): array
16+
{
17+
return [
18+
'id' => $this->id,
19+
'description' => $this->description,
20+
'domain' => $this->domain,
21+
'sitename' => $this->sitename,
22+
'profile' => $this->whenLoaded('latestProfile', function () {
23+
if (!$this->latestProfile) {
24+
return null;
25+
}
26+
return [
27+
'id' => $this->latestProfile->id,
28+
'wiki_id' => $this->latestProfile->wiki_id,
29+
'purpose' => $this->latestProfile->purpose,
30+
'purpose_other' => $this->latestProfile->purpose_other,
31+
'audience' => $this->latestProfile->audience,
32+
'audience_other' => $this->latestProfile->audience_other,
33+
'temporality' => $this->latestProfile->temporality,
34+
'temporality_other' => $this->latestProfile->temporality_other
35+
];
36+
})
37+
];
38+
}
39+
}

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 latestProfile() {
187+
return $this->hasOne(\App\Models\WikiProfile::class)->latestOfMany();
188+
}
185189
}

app/WikiProfile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ public function wiki(): BelongsTo
2626
return $this->belongsTo(Wiki::class);
2727
}
2828

29-
}
29+
}

routes/api.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
$router->group(['prefix' => 'wiki', 'middleware' => ['verified']], function () use ($router) {
4040
$router->post('create', ['uses' => 'WikiController@create']);
4141
$router->post('delete', ['uses' => 'WikiController@delete']);
42+
$router->get('profile/{wiki}', ['uses' => 'WikiController@show']);
4243
$router->post('details', ['uses' => 'WikiController@getWikiDetailsForIdForOwner']);
4344
$router->post('logo/update', ['uses' => 'WikiLogoController@update']);
4445
$router->post('setting/{setting}/update', ['uses' => 'WikiSettingController@update']);

0 commit comments

Comments
 (0)