From 4f85be9b85db484ff200d0cf4549fa69d5cf2dd9 Mon Sep 17 00:00:00 2001 From: Seth Phat Date: Sun, 17 Sep 2023 15:21:58 +0700 Subject: [PATCH] Translation Group Console UI --- .../TranslationGroupController.php | 7 +- .../translationGroup.repository.js | 27 +++-- resources/js/console/router.js | 8 ++ .../components/UpdateLanguageButton.vue | 1 - .../TranslationGroupsListScreen.vue | 94 +++++++++++++++ .../components/CreateNewTranslationGroup.vue | 102 ++++++++++++++++ .../DeleteTranslationGroupButton.vue | 85 +++++++++++++ .../UpdateTranslationGroupButton.vue | 113 ++++++++++++++++++ .../TranslationGroupControllerTest.php | 11 +- 9 files changed, 436 insertions(+), 12 deletions(-) create mode 100644 resources/js/console/screens/TranslationGroupsList/TranslationGroupsListScreen.vue create mode 100644 resources/js/console/screens/TranslationGroupsList/components/CreateNewTranslationGroup.vue create mode 100644 resources/js/console/screens/TranslationGroupsList/components/DeleteTranslationGroupButton.vue create mode 100644 resources/js/console/screens/TranslationGroupsList/components/UpdateTranslationGroupButton.vue diff --git a/app/Http/Controllers/TranslationGroupController.php b/app/Http/Controllers/TranslationGroupController.php index 664d6d6..947e617 100644 --- a/app/Http/Controllers/TranslationGroupController.php +++ b/app/Http/Controllers/TranslationGroupController.php @@ -8,6 +8,7 @@ use App\Http\Resources\TranslationGroupResource; use App\Models\TranslationGroup; use Illuminate\Http\JsonResponse; +use Illuminate\Support\Facades\DB; class TranslationGroupController extends Controller { @@ -46,7 +47,11 @@ public function update(TranslationGroupUpdateRequest $request, TranslationGroup public function destroy(TranslationGroup $translationGroup): JsonResponse { - $deleteResult = $translationGroup->delete(); + $deleteResult = DB::transaction(function () use ($translationGroup) { + $translationGroup->translations()->delete(); + + return $translationGroup->delete(); + }); return new JsonResponse([ 'uuid' => $translationGroup->uuid, diff --git a/resources/js/console/repositories/translationGroup.repository.js b/resources/js/console/repositories/translationGroup.repository.js index 7018054..5a9422c 100644 --- a/resources/js/console/repositories/translationGroup.repository.js +++ b/resources/js/console/repositories/translationGroup.repository.js @@ -3,7 +3,7 @@ import { catchError, getData } from './helper'; const httpClient = authenticatedInstance; -export const fontRepository = { +export const translationGroupRepository = { index({ limit = 20, page = 1, @@ -11,7 +11,7 @@ export const fontRepository = { sortDirection = 'asc', }) { return httpClient - .get('fonts', { + .get('translation-groups', { params: { limit, page, @@ -24,19 +24,30 @@ export const fontRepository = { }, /** - * - * @param {FormData} data + * @param {{name: string, description: string, key: string}} data */ create(data) { return httpClient - .post(`fonts`, data, { - headers: { 'Content-Type': 'multipart/form-data' }, - }) + .post(`translation-groups`, data) + .then(getData) + .catch(catchError); + }, + + /** + * @param {String} id + * @param {{name: string, description: string}} data + */ + update(id, data) { + return httpClient + .put(`translation-groups/${id}`, data) .then(getData) .catch(catchError); }, destroy(id) { - return httpClient.delete(`fonts/${id}`).then(getData).catch(catchError); + return httpClient + .delete(`translation-groups/${id}`) + .then(getData) + .catch(catchError); }, }; diff --git a/resources/js/console/router.js b/resources/js/console/router.js index 422f82d..d81df90 100644 --- a/resources/js/console/router.js +++ b/resources/js/console/router.js @@ -39,6 +39,14 @@ export const router = createRouter({ component: () => import('./screens/LanguagesList/LanguaguesListScreen.vue'), }, + { + path: '/translation-groups', + name: 'translation-groups-list', + component: () => + import( + './screens/TranslationGroupsList/TranslationGroupsListScreen.vue' + ), + }, { path: '/translations', name: 'translations-list', diff --git a/resources/js/console/screens/LanguagesList/components/UpdateLanguageButton.vue b/resources/js/console/screens/LanguagesList/components/UpdateLanguageButton.vue index 426e9af..e5987cf 100644 --- a/resources/js/console/screens/LanguagesList/components/UpdateLanguageButton.vue +++ b/resources/js/console/screens/LanguagesList/components/UpdateLanguageButton.vue @@ -79,7 +79,6 @@ const onClickCloseModal = () => { const onClickSubmit = async () => { startLoading(); - console.log(props.language); const data = await languageRepository.update(props.language.uuid, { ...formFields.value, }); diff --git a/resources/js/console/screens/TranslationGroupsList/TranslationGroupsListScreen.vue b/resources/js/console/screens/TranslationGroupsList/TranslationGroupsListScreen.vue new file mode 100644 index 0000000..f3fa41a --- /dev/null +++ b/resources/js/console/screens/TranslationGroupsList/TranslationGroupsListScreen.vue @@ -0,0 +1,94 @@ + + + diff --git a/resources/js/console/screens/TranslationGroupsList/components/CreateNewTranslationGroup.vue b/resources/js/console/screens/TranslationGroupsList/components/CreateNewTranslationGroup.vue new file mode 100644 index 0000000..344b6d7 --- /dev/null +++ b/resources/js/console/screens/TranslationGroupsList/components/CreateNewTranslationGroup.vue @@ -0,0 +1,102 @@ + + + + + diff --git a/resources/js/console/screens/TranslationGroupsList/components/DeleteTranslationGroupButton.vue b/resources/js/console/screens/TranslationGroupsList/components/DeleteTranslationGroupButton.vue new file mode 100644 index 0000000..4dbad08 --- /dev/null +++ b/resources/js/console/screens/TranslationGroupsList/components/DeleteTranslationGroupButton.vue @@ -0,0 +1,85 @@ + + + diff --git a/resources/js/console/screens/TranslationGroupsList/components/UpdateTranslationGroupButton.vue b/resources/js/console/screens/TranslationGroupsList/components/UpdateTranslationGroupButton.vue new file mode 100644 index 0000000..61befb4 --- /dev/null +++ b/resources/js/console/screens/TranslationGroupsList/components/UpdateTranslationGroupButton.vue @@ -0,0 +1,113 @@ + + + + + diff --git a/tests/Feature/TranslationGroupControllerTest.php b/tests/Feature/TranslationGroupControllerTest.php index 73544af..720d8e9 100644 --- a/tests/Feature/TranslationGroupControllerTest.php +++ b/tests/Feature/TranslationGroupControllerTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature; +use App\Models\Translation; use App\Models\TranslationGroup; use Tests\TestCase; @@ -83,7 +84,7 @@ public function testStoreReturnsErrorOnDuplicatedTranslationGroupCode() $response->assertUnprocessable(); } - public function testUpdateUpdatesAGivenLanguage() + public function testUpdateUpdatesAGivenTranslationGroup() { $invoiceGroup = TranslationGroup::factory()->create([ 'key' => 'invoice', @@ -107,12 +108,15 @@ public function testUpdateUpdatesAGivenLanguage() ]); } - public function testDestroyDeletesAGivenLanguage() + public function testDestroyDeletesAGivenTranslationGroup() { $railGroup = TranslationGroup::factory()->create([ 'key' => 'rail', 'name' => 'Rail Group', ]); + $translation = Translation::factory()->create([ + 'translation_group_id' => $railGroup->uuid, + ]); $response = $this->json('DELETE', "api/v1/translation-groups/{$railGroup->uuid}"); @@ -124,5 +128,8 @@ public function testDestroyDeletesAGivenLanguage() $this->assertDatabaseMissing((new TranslationGroup())->getTable(), [ 'key' => 'rail', ]); + $this->assertDatabaseMissing((new Translation())->getTable(), [ + 'uuid' => $translation->uuid, + ]); } }