Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocKing's Localization #25

Merged
merged 26 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions app/Http/Controllers/LanguageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\LanguageIndexRequest;
use App\Http\Requests\LanguageStoreRequest;
use App\Http\Requests\LanguageUpdateRequest;
use App\Http\Resources\LanguageResource;
use App\Models\Language;
use Illuminate\Http\JsonResponse;

class LanguageController extends Controller
{
public function index(LanguageIndexRequest $request): JsonResponse
{
$fonts = $request->buildQueryBuilder()
->get();

return LanguageResource::collection($fonts)->response();
}

public function show(Language $language): JsonResponse
{
return LanguageResource::make($language)->response();
}

public function store(LanguageStoreRequest $request): JsonResponse
{
$language = Language::create($request->validated());

return new JsonResponse([
'uuid' => $language->uuid,
'created' => $language->wasRecentlyCreated,
]);
}

public function update(LanguageUpdateRequest $request, Language $language): JsonResponse
{
$updateStatus = $language->update($request->validated());

return new JsonResponse([
'uuid' => $language->uuid,
'updated' => $updateStatus,
]);
}

public function destroy(Language $language): JsonResponse
{
$deleteResult = $language->delete();

return new JsonResponse([
'uuid' => $language->uuid,
'deleted' => $deleteResult,
]);
}
}
67 changes: 67 additions & 0 deletions app/Http/Controllers/TranslationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\TranslationIndexRequest;
use App\Http\Requests\TranslationStoreRequest;
use App\Http\Requests\TranslationUpdateRequest;
use App\Http\Resources\TranslationResource;
use App\Models\Translation;
use App\Models\TranslationGroup;
use Illuminate\Http\JsonResponse;

class TranslationController extends Controller
{
public function index(TranslationIndexRequest $request): JsonResponse
{
$translations = $request->buildQueryBuilder()
->with(['translationGroup'])
->paginate();

return TranslationResource::collection($translations)->response();
}

public function show(Translation $translation): JsonResponse
{
return TranslationResource::make($translation)->response();
}

public function store(TranslationStoreRequest $request): JsonResponse
{
$translationGroup = TranslationGroup::find($request->validated('translation_group_id'));
$translation = Translation::create([
...$request->validated(),
'key' => "{$translationGroup->key}.{$request->input('key')}",
]);

return new JsonResponse([
'uuid' => $translation->uuid,
'created' => $translation->wasRecentlyCreated,
]);
}

public function update(TranslationUpdateRequest $request, Translation $translation): JsonResponse
{
$translationGroup = TranslationGroup::find($request->validated('translation_group_id'));

$updateStatus = $translation->update([
...$request->validated(),
'key' => "{$translationGroup->key}.{$request->input('key')}",
]);

return new JsonResponse([
'uuid' => $translation->uuid,
'updated' => $updateStatus,
]);
}

public function destroy(Translation $translation): JsonResponse
{
$deleteResult = $translation->delete();

return new JsonResponse([
'uuid' => $translation->uuid,
'deleted' => $deleteResult,
]);
}
}
61 changes: 61 additions & 0 deletions app/Http/Controllers/TranslationGroupController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\TranslationGroupIndexRequest;
use App\Http\Requests\TranslationGroupStoreRequest;
use App\Http\Requests\TranslationGroupUpdateRequest;
use App\Http\Resources\TranslationGroupResource;
use App\Models\TranslationGroup;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\DB;

class TranslationGroupController extends Controller
{
public function index(TranslationGroupIndexRequest $request): JsonResponse
{
$translationGroups = $request->buildQueryBuilder()
->paginate();

return TranslationGroupResource::collection($translationGroups)->response();
}

public function show(TranslationGroup $translationGroup): JsonResponse
{
return TranslationGroupResource::make($translationGroup)->response();
}

public function store(TranslationGroupStoreRequest $request): JsonResponse
{
$translationGroup = TranslationGroup::create($request->validated());

return new JsonResponse([
'uuid' => $translationGroup->uuid,
'created' => $translationGroup->wasRecentlyCreated,
]);
}

public function update(TranslationGroupUpdateRequest $request, TranslationGroup $translationGroup): JsonResponse
{
$updateStatus = $translationGroup->update($request->validated());

return new JsonResponse([
'uuid' => $translationGroup->uuid,
'updated' => $updateStatus,
]);
}

public function destroy(TranslationGroup $translationGroup): JsonResponse
{
$deleteResult = DB::transaction(function () use ($translationGroup) {
$translationGroup->translations()->delete();

return $translationGroup->delete();
});

return new JsonResponse([
'uuid' => $translationGroup->uuid,
'deleted' => $deleteResult,
]);
}
}
2 changes: 2 additions & 0 deletions app/Http/Requests/DocumentTemplateStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function rules(): array
],
'title' => 'required|string',
'category' => 'required|string',
'translation_groups' => 'nullable|array',
'translation_groups.*' => 'uuid|exists:translation_groups,uuid',
];
}
}
2 changes: 2 additions & 0 deletions app/Http/Requests/DocumentTemplateUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public function rules(): array
'template' => 'required|string',
'default_variables' => 'required|array',
'metadata' => 'required|array',
'translation_groups' => 'nullable|array',
'translation_groups.*' => 'uuid|exists:translation_groups,uuid',
];
}
}
23 changes: 23 additions & 0 deletions app/Http/Requests/LanguageIndexRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Http\Requests;

use App\Models\Language;
use Illuminate\Database\Eloquent\Model;

class LanguageIndexRequest extends AbstractIndexRequest
{
protected function getModel(): Model
{
return new Language();
}

protected function getAllowedSortColumns(): array
{
return [
'code',
'name',
'created_at',
];
}
}
22 changes: 22 additions & 0 deletions app/Http/Requests/LanguageStoreRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Requests;

use App\Models\Language;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class LanguageStoreRequest extends FormRequest
{
public function rules(): array
{
return [
'code' => [
'required',
'string',
Rule::unique((new Language())->getTable()),
],
'name' => 'required|string',
];
}
}
17 changes: 17 additions & 0 deletions app/Http/Requests/LanguageUpdateRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Http\Requests;

use App\Models\Language;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class LanguageUpdateRequest extends FormRequest
{
public function rules(): array
{
return [
'name' => 'required|string',
];
}
}
6 changes: 6 additions & 0 deletions app/Http/Requests/PdfRenderRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace App\Http\Requests;

use App\Enums\PdfService;
use App\Models\Language;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class PdfRenderRequest extends FormRequest
{
Expand All @@ -16,6 +18,10 @@ public function rules(): array
'nullable',
PdfService::getRequestRule(),
],
'metadata.language' => [
'nullable',
Rule::in(Language::pluck('code')),
],
];
}

Expand Down
23 changes: 23 additions & 0 deletions app/Http/Requests/TranslationGroupIndexRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Http\Requests;

use App\Models\TranslationGroup;
use Illuminate\Database\Eloquent\Model;

class TranslationGroupIndexRequest extends AbstractIndexRequest
{
protected function getModel(): Model
{
return new TranslationGroup();
}

protected function getAllowedSortColumns(): array
{
return [
'key',
'name',
'created_at',
];
}
}
23 changes: 23 additions & 0 deletions app/Http/Requests/TranslationGroupStoreRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Http\Requests;

use App\Models\TranslationGroup;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class TranslationGroupStoreRequest extends FormRequest
{
public function rules(): array
{
return [
'key' => [
'required',
'string',
Rule::unique((new TranslationGroup())->getTable()),
],
'name' => 'required|string',
'description' => 'nullable|string',
];
}
}
18 changes: 18 additions & 0 deletions app/Http/Requests/TranslationGroupUpdateRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Requests;

use App\Models\TranslationGroup;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class TranslationGroupUpdateRequest extends FormRequest
{
public function rules(): array
{
return [
'name' => 'required|string',
'description' => 'nullable|string',
];
}
}
23 changes: 23 additions & 0 deletions app/Http/Requests/TranslationIndexRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Http\Requests;

use App\Models\Translation;
use Illuminate\Database\Eloquent\Model;

class TranslationIndexRequest extends AbstractIndexRequest
{
protected function getModel(): Model
{
return new Translation();
}

protected function getAllowedSortColumns(): array
{
return [
'key',
'name',
'created_at',
];
}
}
Loading