From 8642722ebe4114998bd7963d6839acf03588f581 Mon Sep 17 00:00:00 2001 From: Nicolas Vargas Ortega Date: Tue, 12 Jan 2021 21:18:43 +0100 Subject: [PATCH] Add deletion for admins --- CHANGELOG.md | 6 +++ kemenu-admin-backend/pom.xml | 1 - .../src/admin/AdminManagement.vue | 37 +++++++++++++------ .../src/admin/AdminService.ts | 15 ++++++++ kemenu-admin-frontend/src/admin/index.ts | 24 ++++++++++++ kemenu-admin-frontend/src/router/index.ts | 22 ++--------- pom.xml | 1 + 7 files changed, 75 insertions(+), 31 deletions(-) create mode 100644 kemenu-admin-frontend/src/admin/AdminService.ts create mode 100644 kemenu-admin-frontend/src/admin/index.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d55d65..f3806ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.0.45 (12-01-2021) + +### Frontend + +* Add deletion for admins. + ## 1.0.44 (11-01-2021) ### Frontend diff --git a/kemenu-admin-backend/pom.xml b/kemenu-admin-backend/pom.xml index 46347da..30931fa 100644 --- a/kemenu-admin-backend/pom.xml +++ b/kemenu-admin-backend/pom.xml @@ -10,7 +10,6 @@ kemenu-admin-backend - 1.4.21 6.6 3.12.0 1.4.2 diff --git a/kemenu-admin-frontend/src/admin/AdminManagement.vue b/kemenu-admin-frontend/src/admin/AdminManagement.vue index 0107da2..3e96240 100644 --- a/kemenu-admin-frontend/src/admin/AdminManagement.vue +++ b/kemenu-admin-frontend/src/admin/AdminManagement.vue @@ -21,6 +21,7 @@ import BorderBottomTitle from '@/layout/BorderBottomTitle.vue'; import ResponsiveTable from '@/responsive_table/ResponsiveTable.vue'; import HttpClient from '@/http/HttpClient'; import AdminResponse from '@/admin/AdminResponse'; +import AdminService from '@/admin/AdminService'; export default defineComponent({ name: 'AdminManagement', @@ -34,26 +35,40 @@ export default defineComponent({ const loading = ref(true); const router = useRouter(); - HttpClient.get('/v1/admins', store.getters.getAccessToken).then((response: Response) => { - response.json().then((adminResponse: AdminResponse[]) => { - admins.value = adminResponse; - loading.value = false; - }).catch((error) => { - console.log(error); - loading.value = false; - }); - }); + AdminService.findAll(store.getters.getAccessToken) + .then(response => { + admins.value = response; + loading.value = false; + }) + .catch(error => { + console.log(error); + loading.value = false; + }); const onEdit = (admin: AdminResponse) => { router.push('/admin/user/' + admin.id); }; const onDelete = (admin: AdminResponse) => { - console.log('Deleting: ' + admin.email); + HttpClient.delete('/v1/admins', admin.id, store.getters.getAccessToken) + .then(() => { + AdminService.findAll(store.getters.getAccessToken) + .then(response => { + admins.value = response; + loading.value = false; + }) + .catch(error => { + console.log(error); + loading.value = false; + }); + }) + .catch(error => { + console.log(error); + }); }; const createAdmin = () => { - router.push('/create/admin'); + router.push({name: 'CreateAdminUser'}); } return {store, admins, loading, onEdit, onDelete, createAdmin}; diff --git a/kemenu-admin-frontend/src/admin/AdminService.ts b/kemenu-admin-frontend/src/admin/AdminService.ts new file mode 100644 index 0000000..fb31b80 --- /dev/null +++ b/kemenu-admin-frontend/src/admin/AdminService.ts @@ -0,0 +1,15 @@ +import AdminResponse from '@/admin/AdminResponse'; +import HttpClient from '@/http/HttpClient'; + +export default class AdminService { + private static ENDPOINT = '/v1/admins'; + + private constructor() { + // Utility class, does not make sense to have an instance + } + + static async findAll(token: string): Promise { + const response = await HttpClient.get(AdminService.ENDPOINT, token); + return await response.json(); + } +} \ No newline at end of file diff --git a/kemenu-admin-frontend/src/admin/index.ts b/kemenu-admin-frontend/src/admin/index.ts new file mode 100644 index 0000000..b9b5771 --- /dev/null +++ b/kemenu-admin-frontend/src/admin/index.ts @@ -0,0 +1,24 @@ +import {RouteRecordRaw} from 'vue-router'; + +const adminRoutes: Array = [ + { + path: '/admin/management', + name: 'AdminManagement', + component: () => import(/* webpackChunkName: "adminManagement" */ './AdminManagement.vue'), + meta: {requiresAuth: true} + }, + { + path: '/admin/create', + name: 'CreateAdminUser', + component: () => import(/* webpackChunkName: "createAdminUser" */ './CreateAdminUser.vue'), + meta: {requiresAuth: true} + }, + { + path: '/admin/user/:id', + name: 'EditAdminUser', + component: () => import(/* webpackChunkName: "editAdminUser" */ './EditAdminUser.vue'), + meta: {requiresAuth: true} + } +]; + +export default adminRoutes; diff --git a/kemenu-admin-frontend/src/router/index.ts b/kemenu-admin-frontend/src/router/index.ts index 4dcd6a1..77a5413 100644 --- a/kemenu-admin-frontend/src/router/index.ts +++ b/kemenu-admin-frontend/src/router/index.ts @@ -1,6 +1,7 @@ import {createRouter, createWebHashHistory, RouteRecordRaw} from 'vue-router'; import blog from '@/blog'; import customers from '@/customers'; +import admin from '@/admin'; const routes: Array = [ { @@ -13,30 +14,13 @@ const routes: Array = [ name: 'Dashboard', component: () => import(/* webpackChunkName: "dashboard" */ '../dashboard/Dashboard.vue'), meta: {requiresAuth: true} - }, - { - path: '/admin/management', - name: 'AdminManagement', - component: () => import(/* webpackChunkName: "adminManagement" */ '../admin/AdminManagement.vue'), - meta: {requiresAuth: true} - }, - { - path: '/create/admin', - name: 'CreateAdminUser', - component: () => import(/* webpackChunkName: "createAdminUser" */ '../admin/CreateAdminUser.vue'), - meta: {requiresAuth: true} - }, - { - path: '/admin/user/:id', - name: 'EditAdminUser', - component: () => import(/* webpackChunkName: "editAdminUser" */ '../admin/EditAdminUser.vue'), - meta: {requiresAuth: true} } ]; const finalRoutes = routes .concat(blog) - .concat(customers); + .concat(customers) + .concat(admin); const router = createRouter({ history: createWebHashHistory(), diff --git a/pom.xml b/pom.xml index 9e39d31..38c7564 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ 15 + 1.4.21 3.0.0-M1