Implement global search

This commit is contained in:
2024-10-11 12:59:21 +02:00
parent 49b436d588
commit cfb8fb9d7d
24 changed files with 262 additions and 209 deletions

View File

@@ -7,5 +7,9 @@ export async function getAllBands() {
}
export async function getBand(bandName: string) {
return await axios.get(BASE_URL + '/' + bandName)
return await axios.get(BASE_URL + '/band/' + bandName)
}
export async function searchBand(searchTerm: string) {
return await axios.get(BASE_URL + '/search?value=' + searchTerm)
}

View File

@@ -2,13 +2,9 @@ import axios from "axios"
let BASE_URL = "http://localhost:3000/concerts"
export async function getAllConcerts() {
return await axios.get(BASE_URL)
}
export async function getConcert(id: number) {
if (id != undefined) {
return await axios.get(BASE_URL + "/" + id)
return await axios.get(BASE_URL + "/concert/" + id)
} else {
return null
}

View File

@@ -14,4 +14,8 @@ export async function getTopEvents(nrOfEvents) {
let url = BASE_URL + "?sort=desc&count=" + nrOfEvents
return await axios.get(url)
}
export async function searchEvent(searchTerm: string) {
return await axios.get(BASE_URL + "/search?value=" + searchTerm)
}

View File

@@ -7,11 +7,15 @@ export async function getAllLocations() {
}
export async function getLocation(locationName: string) {
return await axios.get(BASE_URL + "/" + locationName)
return await axios.get(BASE_URL + "/location/" + locationName)
}
export async function getTopLocations(nrOfLocations: number) {
let url = BASE_URL + "?sort=desc&count=" + nrOfLocations
return await axios.get(url)
}
export async function searchLocation(searchTerm: string) {
return await axios.get(BASE_URL + "/search?value=" + searchTerm)
}

View File

@@ -1,10 +0,0 @@
import axios from "axios"
let BASE_URL = "http://localhost:3000/tours"
/**
* Fetch all tours from API
*/
export async function getAllTours() {
//return await axios.get(BASE_URL)
}

View File

@@ -1,122 +0,0 @@
import { useLocalStorage } from "@vueuse/core";
import { defineStore } from "pinia";
import { TourModel } from "../models/acts/tourModel";
import { getAllTours } from "../api/tourApi";
import { GenreModel } from "../models/acts/genreModel";
import { getAllBands } from "../api/bandApi";
import { BandModel } from "../models/acts/bandModel";
import { LocationModel } from "../models/locations/locationModel";
import { getAllLocations } from "../api/locationApi";
import { getAllGenres } from "../api/genreApi";
import { CityModel } from "../models/locations/cityModel";
import { getAllCities } from "../api/cityApi";
export const useConcertStore = defineStore("concertStore", {
state: () => ({
tours: useLocalStorage<Array<TourModel>>("hackmycart/concertStore/tours", []),
filteredTours: useLocalStorage<Array<TourModel>>("hackmycart/concertStore/filteredTours", []),
bands: useLocalStorage<Array<BandModel>>("hackmycart/concertStore/bands", []),
locations: useLocalStorage<Array<LocationModel>>("hackmycart/concertStore/locations", []),
filteredLocations: useLocalStorage<Array<LocationModel>>("hackmycart/concertStore/filteredLocations", []),
cities: useLocalStorage<Array<CityModel>>("hackmycart/concertStore/cities", []),
genres: useLocalStorage<Array<GenreModel>>("hackmycart/concertStore/genres", []),
cityFilter: useLocalStorage<CityModel>("hackmycart/concertStore/cityFilter", new CityModel()),
locationFilter: useLocalStorage<LocationModel>("hackmycart/concertStore/locationFilter", new LocationModel),
genreFilter: useLocalStorage<GenreModel>("hackmycart/concertStore/genreFilter", new GenreModel())
}),
actions: {
async fetchAllTours() {
await getAllTours()
.then(result => {
// this.tours = result.data
// this.tours.sort((a, b) => {
// return new Date(a.concerts[0].date) < new Date(b.concerts[0].date) ? -1 : 1
// })
// this.filteredTours = this.tours
// this.filterTours()
})
await getAllBands()
.then(result => {
this.bands = result.data
})
await getAllLocations()
.then(result => {
this.locations = result.data
})
await getAllGenres()
.then(result => {
this.genres = result.data
this.genres.sort((a, b) => {
return a.name > b.name
})
})
await getAllCities()
.then(result => {
this.cities = result.data
})
},
filterTours() {
this.filteredTours = []
// Filter tours by city, location and genre
for (let tour of this.tours) {
let rightGenre = false
let rightCity = false
let rightLocation = false
// Genre filter
if (this.genreFilter == null || this.genreFilter.id == undefined) {
rightGenre = true
} else {
for (let genre of tour.band.genres) {
if (genre.name == this.genreFilter.name) {
rightGenre = true
}
}
}
// City filter
if (this.cityFilter == null || this.cityFilter.id == undefined) {
rightCity = true
} else {
for (let concert of tour.concerts) {
if (concert.location.city.name == this.cityFilter.name) {
rightCity = true
}
}
// Filter locations by city
this.filteredLocations = this.cities.find(city =>
city.id == this.cityFilter.id
).locations
}
// Location filter
if (this.locationFilter == null || this.locationFilter.id == undefined) {
rightLocation = true
} else {
for (let concert of tour.concerts) {
if (concert.location.id == this.locationFilter.id) {
rightLocation = true
}
}
}
if (rightGenre && rightCity && rightLocation) {
this.filteredTours.push(tour)
}
}
}
}
})

View File

@@ -1,11 +0,0 @@
import { useLocalStorage } from "@vueuse/core";
import { defineStore } from "pinia";
const useScoreStore = defineStore("scoreStore", {
state: () => ({
progressGroup0: useLocalStorage("hackmycart/scoreStore/progressGroup0", 0),
progressGroup1: useLocalStorage("hackmycart/scoreStore/progressGroup1", 0),
progressGroup2: useLocalStorage("hackmycart/scoreStore/progressGroup2", 0),
progressGroup3: useLocalStorage("hackmycart/scoreStore/progressGroup3", 0),
})
})

View File

@@ -0,0 +1,43 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import { searchBand } from "../api/bandApi";
import { searchLocation } from "../api/locationApi";
import { searchEvent } from "../api/eventApi";
export const useSearchStore = defineStore("searchStore", {
state: () => ({
searchTerm: ref(""),
bands: ref(),
locations: ref(),
events: ref(),
alreadySearched: ref(false),
searchInProgress: ref(false)
}),
actions: {
/**
* Search for the termin in all bands, locations, events
*/
async startSearch() {
this.alreadySearched = true
this.searchInProgress = true
await searchBand(this.searchTerm)
.then(result => {
this.bands = result.data
})
await searchLocation(this.searchTerm)
.then(result => {
this.locations = result.data
})
await searchEvent(this.searchTerm)
.then(result => {
this.events = result.data
})
this.searchInProgress = false
}
}
})