Filterable tours
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import { GenreModel } from "./genreModel"
|
||||
import { MemberModel } from "./memberModel"
|
||||
import { RatingModel } from "./ratingModel"
|
||||
|
||||
export class BandModel {
|
||||
@@ -11,8 +9,11 @@ export class BandModel {
|
||||
images: Array<string>
|
||||
logo: string
|
||||
ratings: Array<RatingModel>
|
||||
members: Array<MemberModel>
|
||||
genres: {
|
||||
members: Array<{
|
||||
name: string,
|
||||
image: string
|
||||
}>
|
||||
genres: Array<{
|
||||
name: string
|
||||
}
|
||||
}>
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import { MemberModel } from "./memberModel"
|
||||
import { RatingModel } from "./ratingModel"
|
||||
|
||||
export class GenreModel {
|
||||
@@ -7,13 +6,9 @@ export class GenreModel {
|
||||
bands: Array<
|
||||
{
|
||||
name: string
|
||||
foundingYear: number
|
||||
descriptionEn: string
|
||||
descriptionDe: string
|
||||
images: Array<string>
|
||||
logo: string
|
||||
ratings: Array<RatingModel>
|
||||
members: Array<MemberModel>
|
||||
}
|
||||
>
|
||||
}
|
||||
@@ -4,7 +4,6 @@ export class LocationModel {
|
||||
address: string
|
||||
image: string
|
||||
city: {
|
||||
id: number
|
||||
name: string
|
||||
country: string
|
||||
}
|
||||
@@ -7,5 +7,5 @@ export class TourModel {
|
||||
offered: boolean
|
||||
band: BandModel
|
||||
image: string
|
||||
shows: Array<ConcertModel>
|
||||
concerts: Array<ConcertModel>
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { BandModel } from "./bandModel"
|
||||
|
||||
export class MemberModel {
|
||||
id: Number
|
||||
name: string
|
||||
image: string
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ConcertModel } from "./concertModel"
|
||||
import { ConcertModel } from "../acts/concertModel"
|
||||
|
||||
export class BasketItemModel {
|
||||
id: number = -1
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ConcertModel } from "./concertModel"
|
||||
import { ConcertModel } from "../acts/concertModel"
|
||||
|
||||
export class OrderItemModel {
|
||||
orderId: number = -1
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AddressModel } from "./addressModel"
|
||||
import { AddressModel } from "../user/addressModel"
|
||||
import { OrderItemModel } from "./orderItemModel"
|
||||
import { PaymentModel } from "./paymentModel"
|
||||
import { PaymentModel } from "../user/paymentModel"
|
||||
|
||||
export class OrderModel {
|
||||
id: number
|
||||
@@ -1,13 +1,13 @@
|
||||
import { useLocalStorage } from "@vueuse/core";
|
||||
import { defineStore } from "pinia";
|
||||
import { AccountModel } from "../models/accountModel";
|
||||
import { OrderModel } from "../models/orderModel";
|
||||
import { AccountModel } from "../models/user/accountModel";
|
||||
import { OrderModel } from "../models/ordering/orderModel";
|
||||
import { useFeedbackStore } from "./feedbackStore";
|
||||
import { loginAccount, registerAccount, updateAccount } from "../api/accountApi";
|
||||
import { getUserOrders } from "../api/orderApi";
|
||||
import { BannerStateEnum } from "../enums/bannerStateEnum";
|
||||
import { AddressModel } from "../models/addressModel";
|
||||
import { PaymentModel } from "../models/paymentModel";
|
||||
import { AddressModel } from "../models/user/addressModel";
|
||||
import { PaymentModel } from "../models/user/paymentModel";
|
||||
|
||||
export const useAccountStore = defineStore("accountStore", {
|
||||
state: () => ({
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { useLocalStorage } from "@vueuse/core";
|
||||
import { BasketItemModel } from "../models/basketItemModel";
|
||||
import { BasketItemModel } from "../models/ordering/basketItemModel";
|
||||
import { useFeedbackStore } from "./feedbackStore";
|
||||
import { BannerStateEnum } from "../enums/bannerStateEnum";
|
||||
import { addOrder } from "../api/orderApi";
|
||||
import { useAccountStore } from "./accountStore";
|
||||
import { ConcertModel } from "../models/concertModel";
|
||||
import { AddressModel } from "../models/addressModel";
|
||||
import { PaymentModel } from "../models/paymentModel";
|
||||
import { ConcertModel } from "../models/acts/concertModel";
|
||||
import { AddressModel } from "../models/user/addressModel";
|
||||
import { PaymentModel } from "../models/user/paymentModel";
|
||||
|
||||
export const useBasketStore = defineStore('basketStore', {
|
||||
state: () => ({
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
import { useLocalStorage } from "@vueuse/core";
|
||||
import { defineStore } from "pinia";
|
||||
import { TourModel } from "../models/tourModel";
|
||||
import { TourModel } from "../models/acts/tourModel";
|
||||
import { getAllTours } from "../api/tourApi";
|
||||
import { GenreModel } from "../models/genreModel";
|
||||
import { GenreModel } from "../models/acts/genreModel";
|
||||
import { getAllBands } from "../api/bandApi";
|
||||
import { BandModel } from "../models/bandModel";
|
||||
import { LocationModel } from "../models/locationModel";
|
||||
import { BandModel } from "../models/acts/bandModel";
|
||||
import { LocationModel } from "../models/acts/locationModel";
|
||||
import { getAllLocations } from "../api/locationApi";
|
||||
import { getAllGenres } from "../api/genreApi";
|
||||
import { CityModel } from "../models/cityModel";
|
||||
import { CityModel } from "../models/acts/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", [])
|
||||
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: {
|
||||
@@ -27,8 +32,12 @@ export const useConcertStore = defineStore("concertStore", {
|
||||
this.tours = result.data
|
||||
|
||||
this.tours.sort((a, b) => {
|
||||
return new Date(a.shows[0].date) < new Date(b.shows[0].date) ? -1 : 1
|
||||
return new Date(a.concerts[0].date) < new Date(b.concerts[0].date) ? -1 : 1
|
||||
})
|
||||
|
||||
this.filteredTours = this.tours
|
||||
|
||||
this.filterTours()
|
||||
})
|
||||
|
||||
await getAllBands()
|
||||
@@ -50,6 +59,60 @@ export const useConcertStore = defineStore("concertStore", {
|
||||
.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user