From bf6247775f0219a07349cf27ad425b1782cc4a3b Mon Sep 17 00:00:00 2001 From: Waliston Belles Date: Fri, 28 Jan 2022 21:03:00 -0300 Subject: [PATCH 01/48] [FRONT] refactor: organized frontend structure folders --- frontend/components/molecules/news/LastnewsList.vue | 1 - .../organisms/{ => authentication}/CreateAccountDialog.vue | 0 .../organisms/{ => authentication}/LoginDialog.vue | 0 .../organisms/dashboard/{ => home}/DashboardAccountsInfo.vue | 0 .../organisms/dashboard/{ => home}/DashboardServerStatus.vue | 0 frontend/components/organisms/dashboard/news/NewsEdit.vue | 4 +--- frontend/components/organisms/{ => layout}/Sidebar.vue | 0 .../dashboard/accounts/DashboardAccountsTemplate.vue | 5 +++++ .../templates/dashboard/{ => home}/HomeDashboardTemplate.vue | 0 frontend/components/templates/{ => home}/HomeTemplate.vue | 0 .../components/templates/{ => layout}/FooterTemplate.vue | 0 .../components/templates/{ => layout}/HeaderTemplate.vue | 0 frontend/pages/dashboard/{ => accounts}/accounts.vue | 4 +--- frontend/routes/dashboard/account.ts | 2 +- 14 files changed, 8 insertions(+), 8 deletions(-) rename frontend/components/organisms/{ => authentication}/CreateAccountDialog.vue (100%) rename frontend/components/organisms/{ => authentication}/LoginDialog.vue (100%) rename frontend/components/organisms/dashboard/{ => home}/DashboardAccountsInfo.vue (100%) rename frontend/components/organisms/dashboard/{ => home}/DashboardServerStatus.vue (100%) rename frontend/components/organisms/{ => layout}/Sidebar.vue (100%) create mode 100644 frontend/components/templates/dashboard/accounts/DashboardAccountsTemplate.vue rename frontend/components/templates/dashboard/{ => home}/HomeDashboardTemplate.vue (100%) rename frontend/components/templates/{ => home}/HomeTemplate.vue (100%) rename frontend/components/templates/{ => layout}/FooterTemplate.vue (100%) rename frontend/components/templates/{ => layout}/HeaderTemplate.vue (100%) rename frontend/pages/dashboard/{ => accounts}/accounts.vue (74%) diff --git a/frontend/components/molecules/news/LastnewsList.vue b/frontend/components/molecules/news/LastnewsList.vue index 15eee3d..453b514 100644 --- a/frontend/components/molecules/news/LastnewsList.vue +++ b/frontend/components/molecules/news/LastnewsList.vue @@ -79,7 +79,6 @@ export default Vue.extend({ if (response.status === 200) { this.$set(this, 'newsData', response.data); - console.log(response.total); this.total = response.total; this.isLoading = false; } diff --git a/frontend/components/organisms/CreateAccountDialog.vue b/frontend/components/organisms/authentication/CreateAccountDialog.vue similarity index 100% rename from frontend/components/organisms/CreateAccountDialog.vue rename to frontend/components/organisms/authentication/CreateAccountDialog.vue diff --git a/frontend/components/organisms/LoginDialog.vue b/frontend/components/organisms/authentication/LoginDialog.vue similarity index 100% rename from frontend/components/organisms/LoginDialog.vue rename to frontend/components/organisms/authentication/LoginDialog.vue diff --git a/frontend/components/organisms/dashboard/DashboardAccountsInfo.vue b/frontend/components/organisms/dashboard/home/DashboardAccountsInfo.vue similarity index 100% rename from frontend/components/organisms/dashboard/DashboardAccountsInfo.vue rename to frontend/components/organisms/dashboard/home/DashboardAccountsInfo.vue diff --git a/frontend/components/organisms/dashboard/DashboardServerStatus.vue b/frontend/components/organisms/dashboard/home/DashboardServerStatus.vue similarity index 100% rename from frontend/components/organisms/dashboard/DashboardServerStatus.vue rename to frontend/components/organisms/dashboard/home/DashboardServerStatus.vue diff --git a/frontend/components/organisms/dashboard/news/NewsEdit.vue b/frontend/components/organisms/dashboard/news/NewsEdit.vue index 6b69383..5d3f22c 100644 --- a/frontend/components/organisms/dashboard/news/NewsEdit.vue +++ b/frontend/components/organisms/dashboard/news/NewsEdit.vue @@ -42,9 +42,7 @@ export default Vue.extend({ }, methods: { - async onUpdate(this: any): Promise { - console.log(dashboardNews.$post); - + async onUpdate(this: any): Promise { const result: { status: Number, message: String} = await dashboardNews.editPost(dashboardNews.$post); if (result.status === 200) { diff --git a/frontend/components/organisms/Sidebar.vue b/frontend/components/organisms/layout/Sidebar.vue similarity index 100% rename from frontend/components/organisms/Sidebar.vue rename to frontend/components/organisms/layout/Sidebar.vue diff --git a/frontend/components/templates/dashboard/accounts/DashboardAccountsTemplate.vue b/frontend/components/templates/dashboard/accounts/DashboardAccountsTemplate.vue new file mode 100644 index 0000000..72cbfa9 --- /dev/null +++ b/frontend/components/templates/dashboard/accounts/DashboardAccountsTemplate.vue @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/frontend/components/templates/dashboard/HomeDashboardTemplate.vue b/frontend/components/templates/dashboard/home/HomeDashboardTemplate.vue similarity index 100% rename from frontend/components/templates/dashboard/HomeDashboardTemplate.vue rename to frontend/components/templates/dashboard/home/HomeDashboardTemplate.vue diff --git a/frontend/components/templates/HomeTemplate.vue b/frontend/components/templates/home/HomeTemplate.vue similarity index 100% rename from frontend/components/templates/HomeTemplate.vue rename to frontend/components/templates/home/HomeTemplate.vue diff --git a/frontend/components/templates/FooterTemplate.vue b/frontend/components/templates/layout/FooterTemplate.vue similarity index 100% rename from frontend/components/templates/FooterTemplate.vue rename to frontend/components/templates/layout/FooterTemplate.vue diff --git a/frontend/components/templates/HeaderTemplate.vue b/frontend/components/templates/layout/HeaderTemplate.vue similarity index 100% rename from frontend/components/templates/HeaderTemplate.vue rename to frontend/components/templates/layout/HeaderTemplate.vue diff --git a/frontend/pages/dashboard/accounts.vue b/frontend/pages/dashboard/accounts/accounts.vue similarity index 74% rename from frontend/pages/dashboard/accounts.vue rename to frontend/pages/dashboard/accounts/accounts.vue index 5ba6eda..c690704 100644 --- a/frontend/pages/dashboard/accounts.vue +++ b/frontend/pages/dashboard/accounts/accounts.vue @@ -1,7 +1,5 @@ \ No newline at end of file diff --git a/frontend/components/organisms/dashboard/accounts/DashboardAccounts.vue b/frontend/components/organisms/dashboard/accounts/DashboardAccounts.vue new file mode 100644 index 0000000..1e2527e --- /dev/null +++ b/frontend/components/organisms/dashboard/accounts/DashboardAccounts.vue @@ -0,0 +1,5 @@ + \ No newline at end of file From 7af81fac8d4d5f40f06a84422f5774eadda36acb Mon Sep 17 00:00:00 2001 From: Waliston Belles Date: Fri, 28 Jan 2022 21:35:59 -0300 Subject: [PATCH 03/48] [BACK] refactor: changed search method to total accounts --- backend/app/Controllers/Dashboard/Accounts.ts | 2 +- backend/start/routes/dashboard.ts | 2 +- .../molecules/dashboard/home/DashboardPlayersStatus.vue | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/app/Controllers/Dashboard/Accounts.ts b/backend/app/Controllers/Dashboard/Accounts.ts index b4ca8f7..0e42406 100644 --- a/backend/app/Controllers/Dashboard/Accounts.ts +++ b/backend/app/Controllers/Dashboard/Accounts.ts @@ -2,7 +2,7 @@ import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' import Database from '@ioc:Adonis/Lucid/Database' export default class AccountsController { - public async show({ response, bouncer }: HttpContextContract) { + public async index({ response, bouncer }: HttpContextContract) { try { await bouncer.with('DashboardPolicy').authorize('viewList'); diff --git a/backend/start/routes/dashboard.ts b/backend/start/routes/dashboard.ts index 157d004..2cae231 100644 --- a/backend/start/routes/dashboard.ts +++ b/backend/start/routes/dashboard.ts @@ -1,6 +1,6 @@ import Route from '@ioc:Adonis/Core/Route'; -Route.get('/dashboard/accounts', 'Dashboard/Accounts.show').middleware('auth'); +Route.get('/dashboard/accounts', 'Dashboard/Accounts.index').middleware('auth'); Route.get('/dashboard/players', 'Dashboard/Players.show').middleware('auth'); Route.get('/dashboard/guilds', 'Dashboard/Guilds.show').middleware('auth'); Route.get('/dashboard/premium-points', 'Dashboard/PremiumPoints.show').middleware('auth'); diff --git a/frontend/components/molecules/dashboard/home/DashboardPlayersStatus.vue b/frontend/components/molecules/dashboard/home/DashboardPlayersStatus.vue index 719cd81..ab3f353 100644 --- a/frontend/components/molecules/dashboard/home/DashboardPlayersStatus.vue +++ b/frontend/components/molecules/dashboard/home/DashboardPlayersStatus.vue @@ -1,7 +1,7 @@ + + \ No newline at end of file diff --git a/frontend/components/templates/dashboard/accounts/DashboardAccountsTemplate.vue b/frontend/components/templates/dashboard/accounts/DashboardAccountsTemplate.vue index 72cbfa9..c5c9a20 100644 --- a/frontend/components/templates/dashboard/accounts/DashboardAccountsTemplate.vue +++ b/frontend/components/templates/dashboard/accounts/DashboardAccountsTemplate.vue @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/frontend/components/templates/dashboard/accounts/DashboardEditAccountTemplate.vue b/frontend/components/templates/dashboard/accounts/DashboardEditAccountTemplate.vue index 8cad59a..16ef8ca 100644 --- a/frontend/components/templates/dashboard/accounts/DashboardEditAccountTemplate.vue +++ b/frontend/components/templates/dashboard/accounts/DashboardEditAccountTemplate.vue @@ -47,7 +47,7 @@ export default Vue.extend({ async accountExists(): Promise { this.$set(this, 'isLoading', true); - const response = await dashboardAccounts.findAccount(this.getAccountName); + const response = await dashboardAccounts.find(this.getAccountName); if (!response || !response.data.length) { this.$set(this, 'accountInvalid', true); diff --git a/frontend/components/templates/dashboard/news/PostCreateTemplate.vue b/frontend/components/templates/dashboard/news/PostCreateTemplate.vue index 81a4d20..7719e73 100644 --- a/frontend/components/templates/dashboard/news/PostCreateTemplate.vue +++ b/frontend/components/templates/dashboard/news/PostCreateTemplate.vue @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/frontend/components/templates/dashboard/news/PostEditTemplate.vue b/frontend/components/templates/dashboard/news/PostEditTemplate.vue index 0220dd8..015379e 100644 --- a/frontend/components/templates/dashboard/news/PostEditTemplate.vue +++ b/frontend/components/templates/dashboard/news/PostEditTemplate.vue @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/frontend/components/organisms/dashboard/accounts/DashboardAccounts.vue b/frontend/components/organisms/dashboard/accounts/DashboardAccounts.vue index 8b5af94..064c67d 100644 --- a/frontend/components/organisms/dashboard/accounts/DashboardAccounts.vue +++ b/frontend/components/organisms/dashboard/accounts/DashboardAccounts.vue @@ -1,5 +1,9 @@ + + diff --git a/frontend/layouts/dashboard.vue b/frontend/layouts/dashboard.vue index 37ee2de..5647a49 100644 --- a/frontend/layouts/dashboard.vue +++ b/frontend/layouts/dashboard.vue @@ -79,7 +79,7 @@ \ No newline at end of file diff --git a/frontend/components/organisms/dashboard/characters/DashboardEditCharacter.vue b/frontend/components/organisms/dashboard/characters/DashboardEditCharacter.vue index de71819..efc3f7f 100644 --- a/frontend/components/organisms/dashboard/characters/DashboardEditCharacter.vue +++ b/frontend/components/organisms/dashboard/characters/DashboardEditCharacter.vue @@ -9,6 +9,7 @@ > @@ -30,9 +31,7 @@ :key="item.text" > -
- Characteristics -
+
Skills
@@ -136,4 +135,14 @@ export default Vue.extend({ } } }) - \ No newline at end of file + + + \ No newline at end of file From 20695fe1f8e596aa17c6fe8738ce45fd4bb5ec00 Mon Sep 17 00:00:00 2001 From: Waliston Belles Date: Tue, 1 Feb 2022 20:12:08 -0300 Subject: [PATCH 17/48] [BACK] feat: added endpoint to fetch character skills --- backend/README.md | 9 +- .../app/Controllers/Dashboard/PlayerSkills.ts | 23 +++++ backend/app/Controllers/Dashboard/Players.ts | 88 +++++++------------ .../app/Services/Dashboard/PlayerService.ts | 31 +++++++ .../Services/Dashboard/PlayerSkillsService.ts | 7 ++ backend/start/routes/dashboard/character.ts | 3 +- 6 files changed, 98 insertions(+), 63 deletions(-) create mode 100644 backend/app/Controllers/Dashboard/PlayerSkills.ts create mode 100644 backend/app/Services/Dashboard/PlayerService.ts create mode 100644 backend/app/Services/Dashboard/PlayerSkillsService.ts diff --git a/backend/README.md b/backend/README.md index 2fb162b..b71c6ab 100644 --- a/backend/README.md +++ b/backend/README.md @@ -133,7 +133,8 @@ $ npm run start ## 🕵🏾‍♂️ Routes Dashboard - Characters -| METHOD | ENDPOINT | DESCRIPTION | -| :----- | :------------------------- | :-----------------------------------------| -| GET | /dashboard/character/:name | Find character | -| POST | /dashboard/character | Update character | \ No newline at end of file +| METHOD | ENDPOINT | DESCRIPTION | +| :----- | :-------------------------------| :-----------------------------------------| +| GET | /dashboard/character/:name | Find character | +| GET | /dashboard/character-skills/:id | Find character | +| POST | /dashboard/character | Update character | \ No newline at end of file diff --git a/backend/app/Controllers/Dashboard/PlayerSkills.ts b/backend/app/Controllers/Dashboard/PlayerSkills.ts new file mode 100644 index 0000000..96e72cd --- /dev/null +++ b/backend/app/Controllers/Dashboard/PlayerSkills.ts @@ -0,0 +1,23 @@ +import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' +import PlayerSkillsService from 'App/Services/Dashboard/PlayerSkillsService'; + +export default class PlayersController { + public playerSkillsService: PlayerSkillsService = new PlayerSkillsService(); + + public async show(ctx: HttpContextContract) { + try { + await ctx.bouncer.with('DashboardPolicy').authorize('viewList'); + + const skills = await this.playerSkillsService.find(ctx.request.param('id')); + + if (!skills.length) { + return ctx.response.status(404).send({ message: "Character not found!" }); + } + + return ctx.response.status(200).send({ status: 200, result: skills }); + } catch(err) { + console.log('Error findCharacterSkills Query: ', err); + return ctx.response.status(400).send({ message: 'An error occurred, check the api console.'}) + } + } +} diff --git a/backend/app/Controllers/Dashboard/Players.ts b/backend/app/Controllers/Dashboard/Players.ts index 52ff2e4..b0f8211 100644 --- a/backend/app/Controllers/Dashboard/Players.ts +++ b/backend/app/Controllers/Dashboard/Players.ts @@ -1,86 +1,58 @@ -import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' -import Database from '@ioc:Adonis/Lucid/Database' +import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; import { UpdateValidator } from 'App/Validators/Dashboard/Characters'; +import PlayerService from 'App/Services/Dashboard/PlayerService'; export default class PlayersController { - public async index({ response, bouncer }: HttpContextContract) { + public playerService: PlayerService = new PlayerService(); + + public async index(ctx: HttpContextContract) { try { - await bouncer.with('DashboardPolicy').authorize('viewList'); + await ctx.bouncer.with('DashboardPolicy').authorize('viewList'); - const accounts = await Database - .from('players') - .count('* as total'); + const accounts = await this.playerService.index(); - return response.status(200).send({ result: accounts}); - } catch(err) { + return ctx.response.status(200).send({ result: accounts }); + } + catch(err) { console.log('Error getTotalPlayers Query: ', err); - return response.status(400).send({ message: 'An error occurred, check the api console.'}) + return ctx.response.status(400).send({ message: 'An error occurred, check the api console.'}) } } - public async show({ request, response, bouncer }: HttpContextContract) { + public async show(ctx: HttpContextContract) { try { - await bouncer.with('DashboardPolicy').authorize('viewList'); - - let name = request.param('name'); - - name = await name - .replace(/%20/g, " ") - .replace(/'+'/g, " ") - .replace(/'/g, "") - .replace(/%27/g, "") - .replace(/-/g, "") - .replace(/"/g, "") - .replace(/%22/g, ""); + await ctx.bouncer.with('DashboardPolicy').authorize('viewList'); - const character = await Database - .from('players') - .select('*') - .where('name', '=', name); + const character = await this.playerService.find(ctx.request.param('name')); if (!character.length) { - return response.status(404).send({ message: "Character not found!"}); + return ctx.response.status(404).send({ message: "Character not found!" }); } - return response.status(200).send({ status: 200, result: character[0]}); - } catch(err) { + return ctx.response.status(200).send({ status: 200, result: character[0] }); + } + catch(err) { console.log('Error findCharacter Query: ', err); - return response.status(400).send({ message: 'An error occurred, check the api console.'}) + return ctx.response.status(400).send({ message: 'An error occurred, check the api console.'}) } } - public async edit({}: HttpContextContract) {} - - public async update({ request, response, bouncer}: HttpContextContract) { + public async update(ctx: HttpContextContract) { try { - await bouncer.with('DashboardPolicy').authorize('viewList'); + await ctx.bouncer.with('DashboardPolicy').authorize('viewList'); - const data = await request.validate(UpdateValidator); - - const character = await Database - .from('players') - .select('id') - .where('name', '=', data.name) - .andWhere('id', '<>', data.id); + const data = await ctx.request.validate(UpdateValidator); - if (character.length) { - return response.status(404).send({ message: "Error. The username is already used."}); - } + const character = await this.playerService.update(data); - const affectedRows = await Database.from('players') - .where('id', '=', data.id) - .update(data); - - if (!affectedRows) { - return response.status(404).send({ message: "Character not found."}); - } - - return response.status(200).send({ status: 200, message: "Character successfully updated." }); - } catch (err) { + if (character !== "Character successfully updated.") + return ctx.response.status(404).send({ message: character }); + + return ctx.response.status(200).send({ status: 200, message: character }); + } + catch (err) { console.log('Error updateAccount Query: ', err); - return response.status(400).send({ message: err}) + return ctx.response.status(400).send({ message: err}) } } - - public async destroy({}: HttpContextContract) {} } diff --git a/backend/app/Services/Dashboard/PlayerService.ts b/backend/app/Services/Dashboard/PlayerService.ts new file mode 100644 index 0000000..ada8156 --- /dev/null +++ b/backend/app/Services/Dashboard/PlayerService.ts @@ -0,0 +1,31 @@ +import Database from '@ioc:Adonis/Lucid/Database' + +export default class PlayerService { + + public async index(): Promise { + return await Database.from('players').count('* as total'); + } + + public async find(name: string): Promise { + return await Database.from('players').select('*').where('name', '=', name); + } + + public async update(data: { id: number, name: string }) { + const character = await Database + .from('players') + .select('id') + .where('name', '=', data.name) + .andWhere('id', '<>', data.id); + + if (character.length) + return "Error. The username is already used."; + + const affectedRows = await Database.from('players').where('id', '=', data.id).update(data); + + if (!affectedRows) + return "Character not found."; + + return "Character successfully updated."; + } + +} \ No newline at end of file diff --git a/backend/app/Services/Dashboard/PlayerSkillsService.ts b/backend/app/Services/Dashboard/PlayerSkillsService.ts new file mode 100644 index 0000000..9be438f --- /dev/null +++ b/backend/app/Services/Dashboard/PlayerSkillsService.ts @@ -0,0 +1,7 @@ +import Database from '@ioc:Adonis/Lucid/Database' + +export default class PlayerSkillsService { + public async find(id: number): Promise { + return await Database.from('player_skills').select('*').where('player_id', '=', id); + } +} \ No newline at end of file diff --git a/backend/start/routes/dashboard/character.ts b/backend/start/routes/dashboard/character.ts index c91d46b..c3649c0 100644 --- a/backend/start/routes/dashboard/character.ts +++ b/backend/start/routes/dashboard/character.ts @@ -1,4 +1,5 @@ import Route from '@ioc:Adonis/Core/Route'; Route.get('/dashboard/character/:name', 'Dashboard/Players.show').middleware('auth'); -Route.post('/dashboard/character/', 'Dashboard/Players.update').middleware('auth'); \ No newline at end of file +Route.get('/dashboard/character-skills/:id', 'Dashboard/PlayerSkills.show').middleware('auth'); +Route.post('/dashboard/character', 'Dashboard/Players.update').middleware('auth'); \ No newline at end of file From 1849eab2a28bd2c0c4fa7c8ea549efd4176f122d Mon Sep 17 00:00:00 2001 From: Waliston Belles Date: Tue, 1 Feb 2022 20:39:54 -0300 Subject: [PATCH 18/48] [BACK] feat: added endpoint to update skills --- backend/README.md | 3 ++- .../app/Controllers/Dashboard/PlayerSkills.ts | 25 ++++++++++++++++--- .../app/Services/Dashboard/PlayerService.ts | 2 +- .../Services/Dashboard/PlayerSkillsService.ts | 19 +++++++++++++- .../CharacterSkills/UpdateValidator.ts | 20 +++++++++++++++ .../Dashboard/CharacterSkills/index.ts | 1 + backend/start/routes/dashboard/character.ts | 3 ++- 7 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 backend/app/Validators/Dashboard/CharacterSkills/UpdateValidator.ts create mode 100644 backend/app/Validators/Dashboard/CharacterSkills/index.ts diff --git a/backend/README.md b/backend/README.md index b71c6ab..574154f 100644 --- a/backend/README.md +++ b/backend/README.md @@ -137,4 +137,5 @@ $ npm run start | :----- | :-------------------------------| :-----------------------------------------| | GET | /dashboard/character/:name | Find character | | GET | /dashboard/character-skills/:id | Find character | -| POST | /dashboard/character | Update character | \ No newline at end of file +| POST | /dashboard/character | Update character | +| POST | /dashboard/character-skills | Update characterSkills | \ No newline at end of file diff --git a/backend/app/Controllers/Dashboard/PlayerSkills.ts b/backend/app/Controllers/Dashboard/PlayerSkills.ts index 96e72cd..4d8b4f6 100644 --- a/backend/app/Controllers/Dashboard/PlayerSkills.ts +++ b/backend/app/Controllers/Dashboard/PlayerSkills.ts @@ -1,4 +1,5 @@ -import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' +import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; +import { UpdateValidator } from 'App/Validators/Dashboard/CharacterSkills'; import PlayerSkillsService from 'App/Services/Dashboard/PlayerSkillsService'; export default class PlayersController { @@ -14,9 +15,27 @@ export default class PlayersController { return ctx.response.status(404).send({ message: "Character not found!" }); } - return ctx.response.status(200).send({ status: 200, result: skills }); + return ctx.response.status(200).send({ status: 200, result: skills }); } catch(err) { - console.log('Error findCharacterSkills Query: ', err); + console.log('Error findCharacterSkills: ', err); + return ctx.response.status(400).send({ message: 'An error occurred, check the api console.'}) + } + } + + public async update(ctx: HttpContextContract) { + try { + await ctx.bouncer.with('DashboardPolicy').authorize('viewList'); + + const data = await ctx.request.validate(UpdateValidator); + + const updateSkills = await this.playerSkillsService.update(data); + + if (updateSkills !== "Skills successfully updated.") + return ctx.response.status(404).send({ message: updateSkills }); + + return ctx.response.status(200).send({ status: 200, message: updateSkills }); + } catch (err) { + console.log('Error updateCharacterSkills: ', err); return ctx.response.status(400).send({ message: 'An error occurred, check the api console.'}) } } diff --git a/backend/app/Services/Dashboard/PlayerService.ts b/backend/app/Services/Dashboard/PlayerService.ts index ada8156..61bfc4f 100644 --- a/backend/app/Services/Dashboard/PlayerService.ts +++ b/backend/app/Services/Dashboard/PlayerService.ts @@ -10,7 +10,7 @@ export default class PlayerService { return await Database.from('players').select('*').where('name', '=', name); } - public async update(data: { id: number, name: string }) { + public async update(data: { id: number, name: string }): Promise { const character = await Database .from('players') .select('id') diff --git a/backend/app/Services/Dashboard/PlayerSkillsService.ts b/backend/app/Services/Dashboard/PlayerSkillsService.ts index 9be438f..149ffcf 100644 --- a/backend/app/Services/Dashboard/PlayerSkillsService.ts +++ b/backend/app/Services/Dashboard/PlayerSkillsService.ts @@ -1,7 +1,24 @@ -import Database from '@ioc:Adonis/Lucid/Database' +import Database from '@ioc:Adonis/Lucid/Database'; export default class PlayerSkillsService { public async find(id: number): Promise { return await Database.from('player_skills').select('*').where('player_id', '=', id); } + + public async update(data: any): Promise { + try { + for(let i = 0; i < 7; i++) { + await Database.table('player_skills').insert({ + player_id: data.id, + skillid: i, + value: data[i].value, + count: data[i].count + }); + } + + return "Skills successfully updated."; + } catch(err) { + return err; + } + } } \ No newline at end of file diff --git a/backend/app/Validators/Dashboard/CharacterSkills/UpdateValidator.ts b/backend/app/Validators/Dashboard/CharacterSkills/UpdateValidator.ts new file mode 100644 index 0000000..637bc17 --- /dev/null +++ b/backend/app/Validators/Dashboard/CharacterSkills/UpdateValidator.ts @@ -0,0 +1,20 @@ +import { schema, rules } from '@ioc:Adonis/Core/Validator' +import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' + +export default class UpdateValidator { + constructor(protected ctx: HttpContextContract) {} + + public schema = schema.create({ + id: schema.number([rules.required(), rules.exists({ table: 'players', column: 'id' })]), + skills: schema.array().members( + schema.object().members({ + player_id: schema.number(), + skillid: schema.number(), + value: schema.number(), + count: schema.number() + }) + ), + }) + + public messages = {}; +} diff --git a/backend/app/Validators/Dashboard/CharacterSkills/index.ts b/backend/app/Validators/Dashboard/CharacterSkills/index.ts new file mode 100644 index 0000000..cfeb80b --- /dev/null +++ b/backend/app/Validators/Dashboard/CharacterSkills/index.ts @@ -0,0 +1 @@ +export { default as UpdateValidator } from './UpdateValidator' \ No newline at end of file diff --git a/backend/start/routes/dashboard/character.ts b/backend/start/routes/dashboard/character.ts index c3649c0..078d658 100644 --- a/backend/start/routes/dashboard/character.ts +++ b/backend/start/routes/dashboard/character.ts @@ -2,4 +2,5 @@ import Route from '@ioc:Adonis/Core/Route'; Route.get('/dashboard/character/:name', 'Dashboard/Players.show').middleware('auth'); Route.get('/dashboard/character-skills/:id', 'Dashboard/PlayerSkills.show').middleware('auth'); -Route.post('/dashboard/character', 'Dashboard/Players.update').middleware('auth'); \ No newline at end of file +Route.post('/dashboard/character', 'Dashboard/Players.update').middleware('auth'); +Route.post('/dashboard/character-skills', 'Dashboard/PlayerSkills.update').middleware('auth'); \ No newline at end of file From 71c128081466ad645d2948a9e0c96ce8e3ef645e Mon Sep 17 00:00:00 2001 From: Waliston Belles Date: Wed, 2 Feb 2022 21:41:37 -0300 Subject: [PATCH 19/48] [FRONT] feat: added model and store to upgrade character skills --- frontend/models/Dashboard.ts | 7 ++ frontend/models/index.ts | 3 +- frontend/store/dashboard/character.ts | 14 +++- frontend/store/dashboard/characterSkills.ts | 80 +++++++++++++++++++++ frontend/store/dashboard/index.ts | 3 +- frontend/utils/store-util.ts | 6 +- 6 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 frontend/store/dashboard/characterSkills.ts diff --git a/frontend/models/Dashboard.ts b/frontend/models/Dashboard.ts index a65a500..b8fd60b 100644 --- a/frontend/models/Dashboard.ts +++ b/frontend/models/Dashboard.ts @@ -98,4 +98,11 @@ export interface Character { offlinetraining_skill: number, broadcasting: number, viewers: number +} + +export interface CharacterSkills { + player_id: number, + skillid: number, + value: number, + count: number } \ No newline at end of file diff --git a/frontend/models/index.ts b/frontend/models/index.ts index e3aedca..2480026 100644 --- a/frontend/models/index.ts +++ b/frontend/models/index.ts @@ -18,7 +18,8 @@ export { export { TopPremiumPoints, Vocations, - Character + Character, + CharacterSkills } from './Dashboard'; export { diff --git a/frontend/store/dashboard/character.ts b/frontend/store/dashboard/character.ts index 47a3d01..b107a5b 100644 --- a/frontend/store/dashboard/character.ts +++ b/frontend/store/dashboard/character.ts @@ -6,7 +6,7 @@ import { } from 'vuex-module-decorators' import { $axios } from '@/utils/nuxt-instance' -import { Character } from '@/models' +import { Character, CharacterSkills } from '@/models' @Module({ name: 'dashboard/character', @@ -107,14 +107,25 @@ export default class Characters extends VuexModule { viewers: undefined } as unknown as Character; + private skills: CharacterSkills[] = []; + public get $character(): Character { return this.character; } + + public get $skills(): CharacterSkills[] { + return this.skills; + } @Mutation private UPDATE_CHARACTERS(this: any, payload: Character) { this.character = Object.assign(this.character, payload); } + + @Mutation + private UPDATE_SKILLS(this: any, payload: CharacterSkills) { + this.skills = Object.assign(this.skills, payload); + } @Action public async find(name: String) { @@ -125,6 +136,7 @@ export default class Characters extends VuexModule { throw new Error(response); this.context.commit('UPDATE_CHARACTERS', response.result); + // this.context.commit('UPDATE_SKILLS', response.result.skills); return { status: response.status, diff --git a/frontend/store/dashboard/characterSkills.ts b/frontend/store/dashboard/characterSkills.ts new file mode 100644 index 0000000..d42b409 --- /dev/null +++ b/frontend/store/dashboard/characterSkills.ts @@ -0,0 +1,80 @@ +import { + Module, + VuexModule, + Mutation, + Action +} from 'vuex-module-decorators' + +import { $axios } from '@/utils/nuxt-instance' +import { CharacterSkills } from '@/models' + +interface UpdatePayload { + id: number, + skills: CharacterSkills[] +} + +@Module({ + name: 'dashboard/characterSkills', + stateFactory: true, + namespaced: true +}) + +export default class CharacterSkill extends VuexModule { + private skills: CharacterSkills[] = []; + + public get $skills(): CharacterSkills[] { + return this.skills; + } + + @Mutation + private UPDATE_SKILLS(this: any, payload: CharacterSkills) { + this.skills = Object.assign(this.skills, payload); + } + + @Action + public async find(id: Number) { + try { + return await $axios.$get(`dashboard/character-skills/${id}`) + .then((response) => { + if (response.status !== 200) + throw new Error(response); + + this.context.commit('UPDATE_SKILLS', response.result); + + return { + status: response.status, + data: response.result + }; + }) + .catch(({ response }) => { + return { + data: [], + status: response + }; + }); + } catch(err) { + return err; + } + } + + @Action + public async update(payload: UpdatePayload) { + try { + return await $axios.$post('dashboard/character-skills', payload) + .then((response) => { + if (!response) + throw new Error(response); + + return response; + }) + .catch(({ response }) => { + return { + data: response, + status: response.status + }; + }); + } catch(err) { + return err; + } + } +} diff --git a/frontend/store/dashboard/index.ts b/frontend/store/dashboard/index.ts index 78e2dad..5d517c4 100644 --- a/frontend/store/dashboard/index.ts +++ b/frontend/store/dashboard/index.ts @@ -1,4 +1,5 @@ export { default as Home } from './home'; export { default as News } from './news'; export { default as Accounts } from './accounts'; -export { default as Character } from './character'; \ No newline at end of file +export { default as Character } from './character'; +export { default as CharacterSkills } from './characterSkills'; \ No newline at end of file diff --git a/frontend/utils/store-util.ts b/frontend/utils/store-util.ts index bdc5fa6..1cd7465 100644 --- a/frontend/utils/store-util.ts +++ b/frontend/utils/store-util.ts @@ -7,7 +7,8 @@ import { Home as DashboardHome, News as DashboardNews, Accounts as DashboardAccounts, - Character as DashboardCharacters + Character as DashboardCharacters, + CharacterSkills as DashboardCharacterSkills } from '@/store/dashboard' import { @@ -49,6 +50,7 @@ let dashboardHome: DashboardHome; let dashboardNews: DashboardNews; let dashboardAccounts: DashboardAccounts; let dashboardCharacters: DashboardCharacters; +let dashboardCharacterSkills: DashboardCharacterSkills; let news: News; @@ -77,6 +79,7 @@ const initializeStores = (store: Store) => { dashboardNews = getModule(DashboardNews, store); dashboardAccounts = getModule(DashboardAccounts, store); dashboardCharacters = getModule(DashboardCharacters, store); + dashboardCharacterSkills = getModule(DashboardCharacterSkills, store); // Store News news = getModule(News, store); @@ -112,6 +115,7 @@ export { dashboardNews, dashboardAccounts, dashboardCharacters, + dashboardCharacterSkills, auth, From f0776ec4c49f6f55373195d40a9c2bfeecf57670 Mon Sep 17 00:00:00 2001 From: Waliston Belles Date: Wed, 2 Feb 2022 21:42:23 -0300 Subject: [PATCH 20/48] [BACK] fix: fixed problem in the update skills query --- backend/app/Services/Dashboard/PlayerSkillsService.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/app/Services/Dashboard/PlayerSkillsService.ts b/backend/app/Services/Dashboard/PlayerSkillsService.ts index 149ffcf..98f7781 100644 --- a/backend/app/Services/Dashboard/PlayerSkillsService.ts +++ b/backend/app/Services/Dashboard/PlayerSkillsService.ts @@ -8,16 +8,16 @@ export default class PlayerSkillsService { public async update(data: any): Promise { try { for(let i = 0; i < 7; i++) { - await Database.table('player_skills').insert({ - player_id: data.id, + await Database.from('player_skills').where('player_id', '=', data.id).andWhere('skillid', '=', data.skills[i].skillid).update({ skillid: i, - value: data[i].value, - count: data[i].count + value: data.skills[i].value, + count: data.skills[i].count }); } return "Skills successfully updated."; } catch(err) { + console.log('Entrou aqui, 21: ', err); return err; } } From e242f5f87b1e47dabc665d29be662b9adc89f1bb Mon Sep 17 00:00:00 2001 From: Waliston Belles Date: Wed, 2 Feb 2022 21:43:23 -0300 Subject: [PATCH 21/48] [FRONT] feat: added component to update skills --- .../characters/DashboardCharacterForm.vue | 22 +++--- .../characters/DashboardCharacterSkills.vue | 74 +++++++++++++++++++ .../characters/DashboardCharacterStats.vue | 28 ++++--- .../characters/DashboardEditCharacter.vue | 41 ++++++---- .../DashboardEditCharacterTemplate.vue | 3 +- 5 files changed, 133 insertions(+), 35 deletions(-) create mode 100644 frontend/components/molecules/dashboard/characters/DashboardCharacterSkills.vue diff --git a/frontend/components/molecules/dashboard/characters/DashboardCharacterForm.vue b/frontend/components/molecules/dashboard/characters/DashboardCharacterForm.vue index e5a2e7b..ee0d08e 100644 --- a/frontend/components/molecules/dashboard/characters/DashboardCharacterForm.vue +++ b/frontend/components/molecules/dashboard/characters/DashboardCharacterForm.vue @@ -1,6 +1,6 @@ + + \ No newline at end of file diff --git a/frontend/components/molecules/dashboard/characters/DashboardCharacterStats.vue b/frontend/components/molecules/dashboard/characters/DashboardCharacterStats.vue index 97e7d9b..7c9aa3c 100644 --- a/frontend/components/molecules/dashboard/characters/DashboardCharacterStats.vue +++ b/frontend/components/molecules/dashboard/characters/DashboardCharacterStats.vue @@ -1,6 +1,6 @@