Start moving data server handling from pinia store to server

This commit is contained in:
2024-10-03 19:03:36 +02:00
parent e177cf53e6
commit 14766fb39b
27 changed files with 401 additions and 215 deletions

View File

@@ -0,0 +1,12 @@
import axios from "axios"
const BASE_URL = "http://localhost:3000/events"
export async function fetchEvents(city: string = "", genre: string = "") {
let url = BASE_URL + "?"
url += (city.length > 0) ? "city=" + city : ""
url += (genre.length > 0) ? "genre=" + genre : ""
console.log(url)
return await axios.get(url)
}

View File

@@ -0,0 +1,11 @@
import { BandModel } from "./bandModel"
import { ConcertModel } from "./concertModel"
export class EventModel {
id: number
name: string
offered: boolean
image: string
band: BandModel
concerts: Array<ConcertModel>
}

View File

@@ -1,6 +1,9 @@
import { BandModel } from "./bandModel"
import { ConcertModel } from "./concertModel"
/**
* @deprecated Use EventModel!
*/
export class TourModel {
id: number
name: string

View File

@@ -0,0 +1,19 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import { EventModel } from "../models/acts/eventModel";
import { fetchEvents } from "../api/eventApi";
export const useShoppingStore = defineStore("shoppingStore", {
state: () => ({
events: ref<Array<EventModel>>([])
}),
actions: {
getEvents(city: string = "", genre: string = "") {
fetchEvents(city, genre)
.then(result => {
this.events = result.data
})
}
}
})