Atomize model classes
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import axios from "axios"
|
||||
import { AccountModel } from "../models/accountModel"
|
||||
import { AccountModel } from "../models/user/accountModel"
|
||||
|
||||
const BASE_URL = "http://localhost:3000/accounts"
|
||||
|
||||
|
||||
@@ -2,6 +2,14 @@ import axios from "axios"
|
||||
|
||||
const BASE_URL = "http://localhost:3000/events"
|
||||
|
||||
/**
|
||||
* Request all events in the database
|
||||
*
|
||||
* @param city Filter by name of city where the concert is
|
||||
* @param genre Filter by genre of the band
|
||||
*
|
||||
* @returns All events which fulfill the params
|
||||
*/
|
||||
export async function fetchEvents(city: string = "", genre: string = "") {
|
||||
let url = BASE_URL + "?"
|
||||
url += (city.length > 0) ? "city=" + city + "&" : ""
|
||||
@@ -10,7 +18,14 @@ export async function fetchEvents(city: string = "", genre: string = "") {
|
||||
return await axios.get(url)
|
||||
}
|
||||
|
||||
export async function getTopEvents(nrOfEvents) {
|
||||
/**
|
||||
* Returns events with the most concerts
|
||||
*
|
||||
* @param nrOfEvents Limit number of returned objects
|
||||
*
|
||||
* @returns Limited number of objects with the most concerts in it
|
||||
*/
|
||||
export async function getTopEvents(nrOfEvents: number) {
|
||||
let url = BASE_URL + "?sort=desc&count=" + nrOfEvents
|
||||
|
||||
return await axios.get(url)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import axios from "axios"
|
||||
import { OrderModel } from "../models/orderModel"
|
||||
import { BasketItemModel } from "../models/basketItemModel"
|
||||
import { BasketItemModel } from "../models/ordering/basketItemModel"
|
||||
|
||||
const BASE_URL = "http://localhost:3000/orders"
|
||||
|
||||
|
||||
12
software/src/data/models/acts/bandApiModel.ts
Normal file
12
software/src/data/models/acts/bandApiModel.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { BandModel } from "./bandModel";
|
||||
import { EventApiModel } from "./eventApiModel";
|
||||
import { GenreModel } from "./genreModel"
|
||||
import { MemberModel } from "./memberModel"
|
||||
import { RatingModel } from "./ratingModel"
|
||||
|
||||
export class BandApiModel extends BandModel {
|
||||
ratings: Array<RatingModel> = []
|
||||
members: Array<MemberModel> = []
|
||||
genres: Array<GenreModel> = []
|
||||
events: Array<EventApiModel> = []
|
||||
}
|
||||
@@ -1,22 +1,10 @@
|
||||
import { EventModel } from "./eventModel"
|
||||
import { RatingModel } from "./ratingModel"
|
||||
|
||||
export class BandModel {
|
||||
id: number
|
||||
name: string
|
||||
foundingYear: number
|
||||
descriptionEn: string
|
||||
descriptionDe: string
|
||||
images: Array<string>
|
||||
imageMembers: string
|
||||
logo: string
|
||||
ratings: Array<RatingModel> = []
|
||||
members: Array<{
|
||||
name: string,
|
||||
image: string
|
||||
}>
|
||||
genres: Array<{
|
||||
name: string
|
||||
}> = []
|
||||
events: Array<EventModel>
|
||||
id: number = -1
|
||||
name: string = ""
|
||||
foundingYear: number = 1900
|
||||
descriptionEn: string = ""
|
||||
descriptionDe: string = ""
|
||||
images: Array<string> = []
|
||||
imageMembers: string = ""
|
||||
logo: string = ""
|
||||
}
|
||||
8
software/src/data/models/acts/concertApiModel.ts
Normal file
8
software/src/data/models/acts/concertApiModel.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { LocationApiModel } from "../locations/locationApiModel"
|
||||
import { ConcertModel } from "./concertModel"
|
||||
import { EventApiModel } from "./eventApiModel"
|
||||
|
||||
export class ConcertApiModel extends ConcertModel {
|
||||
location: LocationApiModel = new LocationApiModel()
|
||||
event: EventApiModel = new EventApiModel()
|
||||
}
|
||||
@@ -1,24 +1,6 @@
|
||||
import { LocationModel } from "./../locations/locationModel"
|
||||
import { BandModel } from "./bandModel"
|
||||
import { EventModel } from "./eventModel"
|
||||
|
||||
export class ConcertModel {
|
||||
id: number = 0
|
||||
id: number = -1
|
||||
inStock: number = 0
|
||||
date: string = ""
|
||||
price: number = 0
|
||||
location: LocationModel = new LocationModel()
|
||||
event: {
|
||||
id: number
|
||||
name: string
|
||||
offered: boolean
|
||||
image: string
|
||||
band: BandModel
|
||||
} = {
|
||||
id: 0,
|
||||
name: "",
|
||||
offered: true,
|
||||
image: "",
|
||||
band: new BandModel()
|
||||
}
|
||||
}
|
||||
8
software/src/data/models/acts/eventApiModel.ts
Normal file
8
software/src/data/models/acts/eventApiModel.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { EventModel } from "./eventModel";
|
||||
import { BandModel } from "./bandModel"
|
||||
import { ConcertApiModel } from "./concertApiModel";
|
||||
|
||||
export class EventApiModel extends EventModel {
|
||||
concerts: Array<ConcertApiModel> = []
|
||||
band: BandModel = new BandModel()
|
||||
}
|
||||
@@ -1,11 +1,6 @@
|
||||
import { BandModel } from "./bandModel"
|
||||
import { ConcertModel } from "./concertModel"
|
||||
|
||||
export class EventModel {
|
||||
id: number
|
||||
name: string
|
||||
offered: boolean
|
||||
image: string
|
||||
band: BandModel = new BandModel()
|
||||
concerts: Array<ConcertModel> = [ new ConcertModel() ]
|
||||
id: number = -1
|
||||
name: string = ""
|
||||
offered: boolean = true
|
||||
image: string = ""
|
||||
}
|
||||
6
software/src/data/models/acts/genreApiModel.ts
Normal file
6
software/src/data/models/acts/genreApiModel.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { GenreModel } from "./genreModel";
|
||||
import { BandModel } from "./bandModel"
|
||||
|
||||
export class GenreApiModel extends GenreModel {
|
||||
bands: Array<BandModel>
|
||||
}
|
||||
@@ -1,14 +1,4 @@
|
||||
import { RatingModel } from "./ratingModel"
|
||||
|
||||
export class GenreModel {
|
||||
id: number
|
||||
name: string
|
||||
bands: Array<
|
||||
{
|
||||
name: string
|
||||
images: Array<string>
|
||||
logo: string
|
||||
ratings: Array<RatingModel>
|
||||
}
|
||||
>
|
||||
id: number = -1
|
||||
name: string = ""
|
||||
}
|
||||
4
software/src/data/models/acts/memberModel.ts
Normal file
4
software/src/data/models/acts/memberModel.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export class MemberModel {
|
||||
name: string = ""
|
||||
image: string = ""
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
import { BandModel } from "./bandModel"
|
||||
|
||||
export class RatingModel {
|
||||
id: number
|
||||
rating: number
|
||||
band: BandModel
|
||||
id: number = -1
|
||||
rating: number = 1
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import { BandModel } from "./bandModel"
|
||||
import { ConcertModel } from "./concertModel"
|
||||
|
||||
/**
|
||||
* @deprecated Use EventModel!
|
||||
*/
|
||||
export class TourModel {
|
||||
id: number
|
||||
name: string
|
||||
offered: boolean
|
||||
band: BandModel
|
||||
image: string
|
||||
concerts: Array<ConcertModel>
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { ExerciseModel } from "./exerciseModel";
|
||||
import { ExerciseGroupModel } from "./exerciseGroupModel";
|
||||
|
||||
export class ExerciseGroupApiModel extends ExerciseGroupModel {
|
||||
exercises: Array<ExerciseModel>
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
import { ExerciseModel } from "./exerciseModel"
|
||||
|
||||
export class ExerciseGroupModel {
|
||||
id = -1
|
||||
nameDe: string = ""
|
||||
nameEn: string = ""
|
||||
groupNr: number = 0
|
||||
exercises: Array<ExerciseModel>
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
export class ExerciseModel {
|
||||
id = -1
|
||||
nameDe: string = ""
|
||||
nameEn: string = ""
|
||||
exerciseNr: number = 0
|
||||
|
||||
12
software/src/data/models/locations/cityApiModel.ts
Normal file
12
software/src/data/models/locations/cityApiModel.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { LocationApiModel } from "./locationApiModel"
|
||||
|
||||
/**
|
||||
* Replica of the API endpoint /cities
|
||||
*/
|
||||
export class CityApiModel {
|
||||
id: number = -1
|
||||
name: string = ""
|
||||
country: string = ""
|
||||
image: string = ""
|
||||
locations: Array<LocationApiModel>
|
||||
}
|
||||
@@ -1,24 +1,6 @@
|
||||
/**
|
||||
* Replica of the API endpoint /cities
|
||||
*/
|
||||
export class CityModel {
|
||||
id: number = -1
|
||||
name: string = ""
|
||||
country: string = ""
|
||||
image: string = ""
|
||||
locations: Array<{
|
||||
id: number
|
||||
name: string
|
||||
address: string
|
||||
imageIndoor: string
|
||||
imageOutdoor: string
|
||||
nrOfConcerts: number
|
||||
}> = [{
|
||||
id: -1,
|
||||
name: "",
|
||||
address: "",
|
||||
imageIndoor: "",
|
||||
imageOutdoor: "",
|
||||
nrOfConcerts: 0
|
||||
}]
|
||||
}
|
||||
13
software/src/data/models/locations/locationApiModel.ts
Normal file
13
software/src/data/models/locations/locationApiModel.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { ConcertApiModel } from "../acts/concertApiModel"
|
||||
import { CityModel } from "./cityModel"
|
||||
import { LocationModel } from "./locationModel"
|
||||
import { SeatGroupModel } from "./seatGroupModel"
|
||||
|
||||
/**
|
||||
* Replica of the API endpoint /locations
|
||||
*/
|
||||
export class LocationApiModel extends LocationModel {
|
||||
city: CityModel = new CityModel()
|
||||
concerts: Array<ConcertApiModel> = []
|
||||
seatGroups: Array<SeatGroupModel> = []
|
||||
}
|
||||
@@ -1,32 +1,8 @@
|
||||
import { SeatGroupModel } from "./seatGroupModel"
|
||||
|
||||
/**
|
||||
* Replica of the API endpoint /locations
|
||||
*/
|
||||
export class LocationModel {
|
||||
id: number
|
||||
name: string
|
||||
address: string
|
||||
imageIndoor: string
|
||||
imageOutdoor: string
|
||||
seatSchema: string
|
||||
layout: number
|
||||
city: {
|
||||
name: string
|
||||
country: string
|
||||
} = { name: "", country: "" }
|
||||
concerts: Array<{
|
||||
id: number
|
||||
date: string
|
||||
price: number
|
||||
inStock: number
|
||||
location: string
|
||||
event: {
|
||||
name: string
|
||||
offered: boolean
|
||||
image: string
|
||||
bandName: string
|
||||
}
|
||||
}>
|
||||
seatGroups: Array<SeatGroupModel>
|
||||
id: number = -1
|
||||
name: string = ""
|
||||
address: string = ""
|
||||
imageIndoor: string = ""
|
||||
imageOutdoor: string = ""
|
||||
layout: number = 1
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import { SeatRowModel } from "./seatRowModel"
|
||||
|
||||
export class SeatGroupModel {
|
||||
name: string
|
||||
surcharge: number
|
||||
standingArea: Boolean
|
||||
capacity: number
|
||||
name: string = ""
|
||||
surcharge: number = 0
|
||||
standingArea: Boolean = false
|
||||
capacity: number = 0
|
||||
seatRows: Array<SeatRowModel>
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
export class SeatModel {
|
||||
id: number
|
||||
seatNr: string
|
||||
id: number = -1
|
||||
seatNr: string = ""
|
||||
state: number = 0
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { SeatModel } from "./seatModel"
|
||||
|
||||
export class SeatRowModel {
|
||||
row: number
|
||||
row: number = 0
|
||||
seats: Array<SeatModel>
|
||||
}
|
||||
@@ -1,13 +1,20 @@
|
||||
import { BandApiModel } from "../acts/bandApiModel"
|
||||
import { BandModel } from "../acts/bandModel"
|
||||
import { ConcertModel } from "../acts/concertModel"
|
||||
import { EventModel } from "../acts/eventModel"
|
||||
import { SeatModel } from "../locations/seatModel"
|
||||
|
||||
export class BasketItemModel {
|
||||
concert: ConcertModel = new ConcertModel()
|
||||
concert: ConcertModel
|
||||
event: EventModel
|
||||
band: BandModel = new BandModel()
|
||||
seats: Array<SeatModel> = []
|
||||
price: number
|
||||
|
||||
constructor(concert: ConcertModel, seat: SeatModel, price: number) {
|
||||
constructor(concert: ConcertModel, event: EventModel, band: BandModel, seat: SeatModel, price: number) {
|
||||
this.concert = concert
|
||||
this.event = event
|
||||
this.band = band
|
||||
this.seats = [ seat ]
|
||||
this.price = price
|
||||
}
|
||||
|
||||
12
software/src/data/models/ordering/orderApiModel.ts
Normal file
12
software/src/data/models/ordering/orderApiModel.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { AccountModel } from "../user/accountModel"
|
||||
import { AddressModel } from "../user/addressModel"
|
||||
import { PaymentModel } from "../user/paymentModel"
|
||||
import { OrderModel } from "./orderModel"
|
||||
import { TicketApiModel } from "./ticketApiModel"
|
||||
|
||||
export class OrderApiModel extends OrderModel {
|
||||
tickets: Array<TicketApiModel>
|
||||
account: AccountModel
|
||||
payment: PaymentModel
|
||||
address: AddressModel
|
||||
}
|
||||
@@ -1,13 +1,5 @@
|
||||
import { AddressModel } from "../user/addressModel"
|
||||
import { PaymentModel } from "../user/paymentModel"
|
||||
import { TicketModel } from "./ticketModel"
|
||||
|
||||
export class OrderModel {
|
||||
id: number
|
||||
accountId: number
|
||||
shippingProgress: number
|
||||
tickets: Array<TicketModel>
|
||||
orderedAt: string
|
||||
payment: PaymentModel
|
||||
address: AddressModel
|
||||
}
|
||||
8
software/src/data/models/ordering/ticketApiModel.ts
Normal file
8
software/src/data/models/ordering/ticketApiModel.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { ConcertApiModel } from "../acts/concertApiModel";
|
||||
import { SeatModel } from "../locations/seatModel";
|
||||
import { TicketModel } from "./ticketModel";
|
||||
|
||||
export class TicketApiModel extends TicketModel {
|
||||
concert: ConcertApiModel
|
||||
seat: SeatModel
|
||||
}
|
||||
@@ -1,20 +1,5 @@
|
||||
import { ConcertModel } from "../acts/concertModel"
|
||||
import { SeatModel } from "../locations/seatModel"
|
||||
|
||||
export class TicketModel {
|
||||
id: number
|
||||
orderId: number = -1
|
||||
orderPrice: number = 0
|
||||
concert: ConcertModel
|
||||
seat: {
|
||||
seatNr: number,
|
||||
seatRow: {
|
||||
row: number,
|
||||
seatGroup: {
|
||||
name: string,
|
||||
surcharge: number,
|
||||
standingArea: boolean
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
software/src/data/models/user/accountApiModel.ts
Normal file
10
software/src/data/models/user/accountApiModel.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { AccountModel } from "./accountModel"
|
||||
import { AccountRole } from "./accountRole"
|
||||
import { AddressModel } from "./addressModel"
|
||||
import { PaymentModel } from "./paymentModel"
|
||||
|
||||
export class AccountApiModel extends AccountModel {
|
||||
addresses: Array<AddressModel>
|
||||
payments: Array<PaymentModel>
|
||||
accountRole: AccountRole
|
||||
}
|
||||
@@ -1,7 +1,3 @@
|
||||
import { AccountRole } from "./accountRole"
|
||||
import { AddressModel } from "./addressModel"
|
||||
import { PaymentModel } from "./paymentModel"
|
||||
|
||||
export class AccountModel {
|
||||
id: number
|
||||
username: string = ""
|
||||
@@ -9,7 +5,4 @@ export class AccountModel {
|
||||
email: string = ""
|
||||
firstName: string = ""
|
||||
lastName: string = ""
|
||||
addresses: Array<AddressModel> = [ new AddressModel() ]
|
||||
payments: Array<PaymentModel> = [ new PaymentModel() ]
|
||||
accountRole: AccountRole = new AccountRole()
|
||||
}
|
||||
@@ -8,10 +8,11 @@ import { getUserOrders } from "../api/orderApi";
|
||||
import { BannerStateEnum } from "../enums/bannerStateEnum";
|
||||
import { AddressModel } from "../models/user/addressModel";
|
||||
import { PaymentModel } from "../models/user/paymentModel";
|
||||
import { AccountApiModel } from "../models/user/accountApiModel";
|
||||
|
||||
export const useAccountStore = defineStore("accountStore", {
|
||||
state: () => ({
|
||||
userAccount: useLocalStorage("hackmycart/accountStore/userAccount", new AccountModel())
|
||||
userAccount: useLocalStorage("hackmycart/accountStore/userAccount", new AccountApiModel())
|
||||
}),
|
||||
|
||||
actions: {
|
||||
|
||||
@@ -8,6 +8,8 @@ import { PaymentModel } from "../models/user/paymentModel";
|
||||
import { ref } from "vue";
|
||||
import { SelectedSeatModel } from "../models/ordering/selectedSeatModel";
|
||||
import { calcPrice } from "@/scripts/concertScripts";
|
||||
import { EventModel } from "../models/acts/eventModel";
|
||||
import { BandModel } from "../models/acts/bandModel";
|
||||
|
||||
export const useBasketStore = defineStore('basketStore', {
|
||||
state: () => ({
|
||||
@@ -49,7 +51,7 @@ export const useBasketStore = defineStore('basketStore', {
|
||||
)
|
||||
},
|
||||
|
||||
moveSeatSelectionsToBasket() {
|
||||
moveSeatSelectionsToBasket(event: EventModel, band: BandModel) {
|
||||
for (let selectedSeat of this.selectedSeats) {
|
||||
let itemInBasket: BasketItemModel = this.itemsInBasket.find((basketItem: BasketItemModel) => {
|
||||
return basketItem.concert.id == selectedSeat.concert.id
|
||||
@@ -59,7 +61,13 @@ export const useBasketStore = defineStore('basketStore', {
|
||||
itemInBasket.seats.push(selectedSeat.seat)
|
||||
} else {
|
||||
this.itemsInBasket.push(
|
||||
new BasketItemModel(selectedSeat.concert, selectedSeat.seat, selectedSeat.concert.price)
|
||||
new BasketItemModel(
|
||||
selectedSeat.concert,
|
||||
event,
|
||||
band,
|
||||
selectedSeat.seat,
|
||||
selectedSeat.concert.price
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { EventModel } from "../models/acts/eventModel";
|
||||
import { fetchEvents } from "../api/eventApi";
|
||||
import { fetchAllCities } from "../api/cityApi";
|
||||
import { CityModel } from "../models/locations/cityModel";
|
||||
import { GenreModel } from "../models/acts/genreModel";
|
||||
import { fetchAllGenres } from "../api/genreApi";
|
||||
import { useFeedbackStore } from "./feedbackStore";
|
||||
import { CityApiModel } from "../models/locations/cityApiModel";
|
||||
import { EventApiModel } from "../models/acts/eventApiModel";
|
||||
import { GenreApiModel } from "../models/acts/genreApiModel";
|
||||
|
||||
export const useShoppingStore = defineStore("shoppingStore", {
|
||||
state: () => ({
|
||||
events: ref<Array<EventModel>>([]),
|
||||
cities: ref<Array<CityModel>>([]),
|
||||
genres: ref<Array<GenreModel>>([]),
|
||||
events: ref<Array<EventApiModel>>([]),
|
||||
cities: ref<Array<CityApiModel>>([]),
|
||||
genres: ref<Array<GenreApiModel>>([]),
|
||||
cityFilterName: ref<string>(),
|
||||
genreFilterName: ref<string>()
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user