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

Feature/integrate with backend #13

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
18 changes: 17 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
"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
}],
"max-len": ["error", {"code": 120}],
}
}
21 changes: 16 additions & 5 deletions composables/useBlockService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Block[]>(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<Block>(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) {
Expand Down
11 changes: 7 additions & 4 deletions composables/useRegattaService.ts
Original file line number Diff line number Diff line change
@@ -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<Regatta[]>(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<RegattaDetail>(url);
},

Expand Down
7 changes: 7 additions & 0 deletions middleware/a_token.global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default defineNuxtRouteMiddleware((to, from) => {
const { token: token } = to.query;

if (token as string) {
localStorage.setItem('IdToken', token as string);
}
});
7 changes: 4 additions & 3 deletions stores/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
},
Expand All @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions stores/regatta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
},
Expand Down