From e6c424e8580ca484b7a04112b36cc53d74e52154 Mon Sep 17 00:00:00 2001 From: Rens Hamburger Date: Wed, 14 Sep 2022 19:13:40 +0200 Subject: [PATCH 1/6] Update to save token --- middleware/a_token.global.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 middleware/a_token.global.ts diff --git a/middleware/a_token.global.ts b/middleware/a_token.global.ts new file mode 100644 index 0000000..989673e --- /dev/null +++ b/middleware/a_token.global.ts @@ -0,0 +1,7 @@ +export default defineNuxtRouteMiddleware((to, from) => { + const { token: token } = to.query; + + if (token as string) { + localStorage.setItem("IdToken", token as string); + } +}); From db6e0f3c35ad20dc2625d460d8e5e7866c4268c0 Mon Sep 17 00:00:00 2001 From: Rens Hamburger Date: Wed, 14 Sep 2022 21:12:36 +0200 Subject: [PATCH 2/6] Implement get regattas overview --- composables/useRegattaService.ts | 11 +++++++---- stores/regatta.ts | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/composables/useRegattaService.ts b/composables/useRegattaService.ts index fb786f9..8aa337b 100644 --- a/composables/useRegattaService.ts +++ b/composables/useRegattaService.ts @@ -1,15 +1,18 @@ import { NewRegatta, Regatta, RegattaDetail } from '~~/models/regatta'; -const BASE_URL = '/api/regattas'; +const BASE_URL = 'http://localhost:8080/regattas'; export const useRegattaService = () => { return { async loadRegattas() { - const url = BASE_URL + '/get-regattas'; - return await $fetch(url); + return await $fetch<{regattas: Regatta[]}>(BASE_URL, { + 'headers': { + 'authorization': 'bearer ' + localStorage.getItem('IdToken'), + } + }); }, async loadRegattaDetail(id: string) { - const url = BASE_URL + '/get-regatta-detail?regattaId=' + id; + const url = BASE_URL + '/view/' + id; return await $fetch(url); }, diff --git a/stores/regatta.ts b/stores/regatta.ts index 19f905d..e7be971 100644 --- a/stores/regatta.ts +++ b/stores/regatta.ts @@ -50,8 +50,8 @@ export const useRegattaStore = defineStore('regattas', { try { const loadedRegattas = await regattaService.loadRegattas(); - const regattaIds = loadedRegattas.map((regatta) => regatta.id); - const regattaEntities = loadedRegattas.reduce( + const regattaIds = loadedRegattas.regattas.map((regatta) => regatta.id); + const regattaEntities = loadedRegattas.regattas.reduce( (entities: { [id: string]: Regatta }, regatta: Regatta) => { return { ...entities, [regatta.id]: regatta }; }, From 8906b2af2064e47cc38a5e22705bf0e369e2354c Mon Sep 17 00:00:00 2001 From: Rens Hamburger Date: Wed, 14 Sep 2022 22:06:55 +0200 Subject: [PATCH 3/6] Make add block working --- composables/useBlockService.ts | 21 ++++++++++++++++----- stores/block.ts | 7 ++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/composables/useBlockService.ts b/composables/useBlockService.ts index 39976c5..ebca266 100644 --- a/composables/useBlockService.ts +++ b/composables/useBlockService.ts @@ -5,15 +5,26 @@ const BASE_URL = '/api/blocks'; export const useBlockService = () => { return { async loadBlocks(id: string) { - const url = BASE_URL + '/get-blocks?regattaId=' + id; - return await $fetch(url); + const url = 'http://localhost:8080/blocks/index/' + id; + return await $fetch<{blocks: Block[]}>(url, { + headers: { + authorization: 'bearer ' + localStorage.getItem('IdToken'), + } + }); }, - async addBlock(block: NewBlock) { - const url = BASE_URL + '/add-block'; + async addBlock(id: string, block: NewBlock) { + const url = 'http://localhost:8080/blocks/add/' + id; return await $fetch(url, { method: 'POST', - body: block + body: { + ...block, + start_time: block.start_time.toISOString().slice(11, 16), + start_date: block.start_time.toISOString().slice(0, 10) + }, + headers: { + authorization: 'bearer ' + localStorage.getItem('IdToken'), + } }); }, async editBlock(id: string, data: NewBlock) { diff --git a/stores/block.ts b/stores/block.ts index 771fc7b..bcf1d88 100644 --- a/stores/block.ts +++ b/stores/block.ts @@ -44,8 +44,8 @@ export const useBlockStore = defineStore('blocks', { try { const loadedBlocks = await blockService.loadBlocks(regattaId); - const blockIds = loadedBlocks.map((block) => block.id); - const blockEntities = loadedBlocks.reduce( + const blockIds = loadedBlocks.blocks.map((block) => block.id); + const blockEntities = loadedBlocks.blocks.reduce( (entities: { [id: string]: Block }, block: Block) => { return { ...entities, [block.id]: block }; }, @@ -63,7 +63,8 @@ export const useBlockStore = defineStore('blocks', { }, async add(newBlock: NewBlock) { try { - const block = await blockService.addBlock(newBlock); + const regattaId = useRegattaStore().selectedId; + const block = await blockService.addBlock(regattaId, newBlock); this.ids = [...this.ids, block.id]; this.entities = { From a22130e387f68b47c5938ddd11a6fbd44401f012 Mon Sep 17 00:00:00 2001 From: Rens Hamburger Date: Wed, 14 Sep 2022 22:55:40 +0200 Subject: [PATCH 4/6] Fix eslint issues --- composables/useBlockService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composables/useBlockService.ts b/composables/useBlockService.ts index ebca266..45920c3 100644 --- a/composables/useBlockService.ts +++ b/composables/useBlockService.ts @@ -6,9 +6,9 @@ export const useBlockService = () => { return { async loadBlocks(id: string) { const url = 'http://localhost:8080/blocks/index/' + id; - return await $fetch<{blocks: Block[]}>(url, { + return await $fetch<{ blocks: Block[] }>(url, { headers: { - authorization: 'bearer ' + localStorage.getItem('IdToken'), + authorization: 'bearer ' + localStorage.getItem('IdToken') } }); }, @@ -23,7 +23,7 @@ export const useBlockService = () => { start_date: block.start_time.toISOString().slice(0, 10) }, headers: { - authorization: 'bearer ' + localStorage.getItem('IdToken'), + authorization: 'bearer ' + localStorage.getItem('IdToken') } }); }, From 53dbbb46afd180f8969421daf8c089708a6a2181 Mon Sep 17 00:00:00 2001 From: Rens Hamburger Date: Wed, 14 Sep 2022 23:09:12 +0200 Subject: [PATCH 5/6] Set line length to 120 --- .eslintrc | 17 ++++++++++++++++- composables/useRegattaService.ts | 6 +++--- middleware/a_token.global.ts | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.eslintrc b/.eslintrc index a55d0e2..1d808c2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -18,6 +18,21 @@ "rules": { "no-unused-expressions": "off", "vue/no-v-html": "off", - "no-console": ["error", { "allow": ["warn", "error"] }] + "no-console": ["error", { "allow": ["warn", "error"] }], + "vue/max-len": ["error", { + "code": 120, + "template": 120, + "tabWidth": 4, + "comments": 120, + "ignorePattern": "", + "ignoreComments": false, + "ignoreTrailingComments": false, + "ignoreUrls": false, + "ignoreStrings": false, + "ignoreTemplateLiterals": false, + "ignoreRegExpLiterals": false, + "ignoreHTMLAttributeValues": false, + "ignoreHTMLTextContents": false + }] } } diff --git a/composables/useRegattaService.ts b/composables/useRegattaService.ts index 8aa337b..c58456a 100644 --- a/composables/useRegattaService.ts +++ b/composables/useRegattaService.ts @@ -5,9 +5,9 @@ const BASE_URL = 'http://localhost:8080/regattas'; export const useRegattaService = () => { return { async loadRegattas() { - return await $fetch<{regattas: Regatta[]}>(BASE_URL, { - 'headers': { - 'authorization': 'bearer ' + localStorage.getItem('IdToken'), + return await $fetch<{ regattas: Regatta[] }>(BASE_URL, { + headers: { + authorization: 'bearer ' + localStorage.getItem('IdToken') } }); }, diff --git a/middleware/a_token.global.ts b/middleware/a_token.global.ts index 989673e..4f8c0b4 100644 --- a/middleware/a_token.global.ts +++ b/middleware/a_token.global.ts @@ -2,6 +2,6 @@ export default defineNuxtRouteMiddleware((to, from) => { const { token: token } = to.query; if (token as string) { - localStorage.setItem("IdToken", token as string); + localStorage.setItem('IdToken', token as string); } }); From cfd351f03d3198f22219adb0a022ab26e2729b0a Mon Sep 17 00:00:00 2001 From: Rens Hamburger Date: Wed, 14 Sep 2022 23:27:07 +0200 Subject: [PATCH 6/6] Move to 120 line length --- .eslintrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 1d808c2..480731b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -33,6 +33,7 @@ "ignoreRegExpLiterals": false, "ignoreHTMLAttributeValues": false, "ignoreHTMLTextContents": false - }] + }], + "max-len": ["error", {"code": 120}], } }