Add ToursTable, update API documentation

This commit is contained in:
2024-09-26 14:40:41 +02:00
parent da98fc73c0
commit 169fcdf03c
46 changed files with 776 additions and 829 deletions

View File

@@ -0,0 +1,9 @@
{
"data": [
{
"id": 0,
"name": "Hannover",
"country": "Germany"
}
]
}

View File

@@ -3,7 +3,8 @@
{
"id": 0,
"name": "Swiss Life Hall",
"address": "Ferdinand-Wilhlem-Fricke-Weg 8, 30169 Hannover",
"address": "Ferdinand-Wilhlem-Fricke-Weg 8",
"cityId": 0,
"image": "swiss-life-hall.jpg"
}
]

View File

@@ -3,7 +3,7 @@
{
"id": 0,
"orderId": 0,
"productId": 0,
"showId": 0,
"quantity": 2,
"orderPrice": 184
}

View File

@@ -1,14 +0,0 @@
{
"data": [
{
"id": 0,
"name": "Unlimited Love Tour",
"bandId": 0,
"date": "2024-12-03",
"price": 92,
"inStock": 230,
"offered": true,
"locationId": 0
}
]
}

View File

@@ -0,0 +1,20 @@
{
"data": [
{
"id": 0,
"name": "Unlimited Love Tour",
"bandId": 0,
"offered": true,
"shows": [
{
"id": 0,
"date": "2024-12-03",
"price": 92,
"inStock": 230,
"locationId": 0,
"tourId": 0
}
]
}
]
}

View File

@@ -1,19 +1,21 @@
import { Sequelize } from "sequelize-typescript"
// Models
import { Order } from "./models/order.model"
import { OrderItem } from "./models/orderItem.model"
import { Account } from "./models/account.model"
import { Order } from "./models/ordering/order.model"
import { OrderItem } from "./models/ordering/orderItem.model"
import { Account } from "./models/user/account.model"
import { prepopulateDatabase } from "./scripts/databaseHelper"
import { Address } from "./models/address.model"
import { Payment } from "./models/payment.model"
import { AccountRole } from "./models/accountRole.model"
import { Genre } from "./models/genre.model"
import { Location } from "./models/location.model"
import { Band } from "./models/band.model"
import { Show } from "./models/show.model"
import { Member } from "./models/member.model"
import { Rating } from "./models/rating.model"
import { Address } from "./models/user/address.model"
import { Payment } from "./models/user/payment.model"
import { AccountRole } from "./models/user/accountRole.model"
import { Genre } from "./models/acts/genre.model"
import { Location } from "./models/acts/location.model"
import { Band } from "./models/acts/band.model"
import { Show } from "./models/acts/show.model"
import { Member } from "./models/acts/member.model"
import { Rating } from "./models/acts/rating.model"
import { Tour } from "./models/acts/tour.model"
import { City } from "./models/acts/city.model"
const dbName = "database"
const dbUser = "root"
@@ -26,12 +28,16 @@ export const sequelize = new Sequelize({
username: dbUser,
password: dbPassword,
storage: "database.sqlite",
models: [ Genre, Location, AccountRole, Account, Payment, Address, Order, Band, Show, Member, Rating, OrderItem ]
models: [
AccountRole, Account, Payment, Address,
City, Location, Genre, Band, Rating, Member, Tour, Show,
Order, OrderItem
]
})
export function startDatabase() {
// Create database and tables
sequelize.sync({ force: false })
sequelize.sync({ force: true })
.then(() => {
console.log("Database & tables created!")

View File

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 77 KiB

View File

Before

Width:  |  Height:  |  Size: 183 KiB

After

Width:  |  Height:  |  Size: 183 KiB

View File

@@ -2,6 +2,7 @@ import { BelongsTo, Column, DataType, ForeignKey, HasMany, Model, Table } from "
import { Member } from "./member.model";
import { Genre } from "./genre.model";
import { Rating } from "./rating.model";
import { Tour } from "./tour.model";
@Table({ timestamps: false })
export class Band extends Model {
@@ -44,6 +45,9 @@ export class Band extends Model {
@HasMany(() => Rating)
ratings: Rating[]
@HasMany(() => Tour)
tours: Tour[]
@BelongsTo(() => Genre)
genre: Genre
}

View File

@@ -0,0 +1,17 @@
import { Column, HasMany, Model, Table } from "sequelize-typescript";
import { Location } from "./location.model";
@Table({ timestamps: false })
export class City extends Model {
@Column
name: String
@Column
country: String
// Relations
@HasMany(() => Location)
locations: Location[]
}

View File

@@ -0,0 +1,28 @@
import { BelongsTo, Column, ForeignKey, HasMany, Model, Table } from "sequelize-typescript";
import { Show } from "./show.model";
import { City } from "./city.model";
@Table({ timestamps: false })
export class Location extends Model {
@Column
name: String
@Column
address: String
@ForeignKey(() => City)
@Column
cityId: Number
@Column
image: String
// Relations
@HasMany(() => Show)
shows: Show[]
@BelongsTo(() => City)
city: City
}

View File

@@ -1,5 +1,5 @@
import { BelongsTo, Column, ForeignKey, Model, Table } from "sequelize-typescript";
import { Account } from "./account.model";
import { Account } from "../user/account.model";
import { Band } from "./band.model";
@Table({ timestamps: false })

View File

@@ -1,15 +1,10 @@
import { BelongsTo, Column, ForeignKey, Model, Table } from "sequelize-typescript";
import { Band } from "./band.model";
import { BelongsTo, Column, ForeignKey, HasMany, Model, Table } from "sequelize-typescript";
import { Location } from "./location.model";
import { Tour } from "./tour.model";
import { OrderItem } from "../ordering/orderItem.model";
@Table({ timestamps: false })
export class Show extends Model {
@Column
name: String
@ForeignKey(() => Band)
bandId: Number
@Column
date: String
@@ -19,19 +14,22 @@ export class Show extends Model {
@Column
inStock: Number
@Column
offered: Boolean
@ForeignKey(() => Location)
@Column
locationId: Number
@ForeignKey(() => Tour)
tourId: Number
// Relations
@BelongsTo(() => Band)
band: Band
@BelongsTo(() => Tour)
tour: Tour
@BelongsTo(() => Location)
location: Location
@HasMany(() => OrderItem)
orderItems: OrderItem[]
}

View File

@@ -0,0 +1,24 @@
import { BelongsTo, Column, ForeignKey, HasMany, Model, Table } from "sequelize-typescript";
import { Band } from "./band.model";
import { Show } from "./show.model";
@Table({ timestamps: false })
export class Tour extends Model {
@Column
name: String
@ForeignKey(() => Band)
bandId: Number
@Column
offered: Boolean
// Relations
@BelongsTo(() => Band)
band: Band
@HasMany(() => Show)
shows: Show[]
}

View File

@@ -1,13 +0,0 @@
import { Column, Model, Table } from "sequelize-typescript";
@Table({ timestamps: false })
export class Location extends Model {
@Column
name: String
@Column
address: String
@Column
image: String
}

View File

@@ -1,8 +1,8 @@
import { Table, Column, Model, BelongsTo, ForeignKey, HasMany, BelongsToMany, Default } from 'sequelize-typescript';
import { Account } from './account.model';
import { Account } from '../user/account.model';
import { OrderItem } from './orderItem.model';
import { Address } from './address.model';
import { Payment } from './payment.model';
import { Address } from '../user/address.model';
import { Payment } from '../user/payment.model';
@Table({
updatedAt: false,

View File

@@ -1,5 +1,5 @@
import { Model, BelongsTo, Column, ForeignKey, HasMany, HasOne, Table } from "sequelize-typescript";
import { Show } from "./show.model";
import { Show } from "../acts/show.model";
import { Order } from "./order.model";
@Table({ timestamps: false })
@@ -16,7 +16,7 @@ export class OrderItem extends Model {
@Column
@ForeignKey(() => Show)
productId: number
showId: number
// Relations

View File

@@ -1,9 +1,9 @@
import { Table, Column, Model, HasMany, Unique, BelongsTo, ForeignKey } from 'sequelize-typescript';
import { Order } from './order.model';
import { Order } from '../ordering/order.model';
import { Address } from './address.model';
import { Payment } from './payment.model';
import { AccountRole } from './accountRole.model';
import { Rating } from './rating.model';
import { Rating } from '../acts/rating.model';
@Table({ timestamps: false })
export class Account extends Model {

View File

@@ -1,6 +1,6 @@
import { BelongsTo, Column, ForeignKey, HasMany, Model, Table } from "sequelize-typescript";
import { Account } from "./account.model";
import { Order } from "./order.model";
import { Order } from "../ordering/order.model";
@Table({ timestamps: false })
export class Address extends Model {

View File

@@ -1,6 +1,6 @@
import { BelongsTo, Column, ForeignKey, HasMany, Model, Table } from "sequelize-typescript";
import { Account } from "./account.model";
import { Order } from "./order.model";
import { Order } from "../ordering/order.model";
@Table({ timestamps: false })
export class Payment extends Model {

View File

@@ -1,9 +1,9 @@
import { Router, Request, Response } from "express";
import { Account } from "../models/account.model";
import { Account } from "../models/user/account.model";
import { validateString } from "../scripts/validateHelper";
import { Address } from "../models/address.model";
import { Payment } from "../models/payment.model";
import { AccountRole } from "../models/accountRole.model";
import { Address } from "../models/user/address.model";
import { Payment } from "../models/user/payment.model";
import { AccountRole } from "../models/user/accountRole.model";
export const account = Router()

View File

@@ -1,16 +1,42 @@
import { Member } from "../models/member.model";
import { Band } from "../models/band.model";
import { Member } from "../models/acts/member.model";
import { Band } from "../models/acts/band.model";
import { Request, Response, Router } from "express";
import { Rating } from "../models/rating.model";
import { Genre } from "../models/genre.model";
import { Rating } from "../models/acts/rating.model";
import { Genre } from "../models/acts/genre.model";
export const band = Router()
// Get all bands
band.get("/", (req: Request, res: Response) => {
Band.findAll({
include: [ Member, Rating, Genre ]
})
Band.findAll()
.then(bands => {
res.status(200).json(bands)
})
})
// Get all information about one band
band.get("/:id", (req: Request, res: Response) => {
Band.findByPk(req.params.id, {
include: [
{
model: Member,
attributes: {
exclude: [ "bandId" ]
}
},
{
model: Rating,
attributes: {
exclude: [ "bandId" ]
}
},
Genre
],
attributes: {
exclude: [ "genreId" ]
}
})
.then(band => {
res.status(200).json(band)
})
})

View File

@@ -1,4 +1,4 @@
import { Genre } from "../models/genre.model";
import { Genre } from "../models/acts/genre.model";
import { Request, Response, Router } from "express";
export const genre = Router()

View File

@@ -1,10 +1,16 @@
import { Location } from "../models/location.model";
import { City } from "../models/acts/city.model";
import { Location } from "../models/acts/location.model";
import { Request, Response, Router } from "express";
export const location = Router()
location.get("/", (req: Request, res: Response) => {
Location.findAll()
Location.findAll({
include: [ City ],
attributes: {
exclude: [ "cityId" ]
}
})
.then(locations => {
res.status(200).json(locations)
})

View File

@@ -1,11 +1,11 @@
import { Router, Request, Response } from "express";
import { Order } from "../models/order.model";
import { Show } from "../models/show.model";
import { OrderItem } from "../models/orderItem.model";
import { Payment } from "../models/payment.model";
import { Address } from "../models/address.model";
import { Band } from "../models/band.model";
import { Location } from "../models/location.model";
import { Order } from "../models/ordering/order.model";
import { Show } from "../models/acts/show.model";
import { OrderItem } from "../models/ordering/orderItem.model";
import { Payment } from "../models/user/payment.model";
import { Address } from "../models/user/address.model";
import { Band } from "../models/acts/band.model";
import { Location } from "../models/acts/location.model";
export const order = Router()

View File

@@ -1,10 +1,27 @@
import { Show } from "../models/show.model";
import { Location } from "../models/acts/location.model";
import { Show } from "../models/acts/show.model";
import { Request, Response, Router } from "express";
import { Tour } from "../models/acts/tour.model";
import { City } from "../models/acts/city.model";
export const show = Router()
show.get("/", (req: Request, res: Response) => {
Show.findAll()
show.get("/:id", (req: Request, res: Response) => {
Show.findByPk(req.params.id, {
include: [
Tour,
{
model: Location,
include: [ City ],
attributes: {
exclude: [ "cityId" ]
}
}
],
attributes: {
exclude: [ "locationId", "tourId" ]
}
})
.then(shows => {
res.status(200).json(shows)
})

View File

@@ -0,0 +1,44 @@
import { Show } from "../models/acts/show.model";
import { Band } from "../models/acts/band.model";
import { Tour } from "../models/acts/tour.model";
import { Request, Response, Router } from "express";
import { Location } from "../models/acts/location.model";
import { Genre } from "../models/acts/genre.model";
import { City } from "../models/acts/city.model";
export const tour = Router()
tour.get("/", (req: Request, res: Response) => {
Tour.findAll({
include: [
{
model: Band,
include: [ Genre ],
attributes: {
exclude: [ "genreId" ]
}
},
{
model: Show,
include: [
{
model: Location,
include: [ City ],
attributes: {
exclude: [ "cityId" ]
}
}
],
attributes: {
exclude: [ "locationId", "tourId" ]
}
},
],
attributes: {
exclude: [ "bandId" ]
}
})
.then(tours => {
res.status(200).json(tours)
})
})

View File

@@ -1,15 +1,17 @@
import { Order } from '../models/order.model'
import { OrderItem } from '../models/orderItem.model'
import { Account } from '../models/account.model'
import { Address } from '../models/address.model'
import { Payment } from '../models/payment.model'
import { AccountRole } from '../models/accountRole.model'
import { Rating } from '../models/rating.model'
import { Member } from '../models/member.model'
import { Genre } from '../models/genre.model'
import { Band } from '../models/band.model'
import { Location } from '../models/location.model'
import { Show } from '../models/show.model'
import { Order } from '../models/ordering/order.model'
import { OrderItem } from '../models/ordering/orderItem.model'
import { Account } from '../models/user/account.model'
import { Address } from '../models/user/address.model'
import { Payment } from '../models/user/payment.model'
import { AccountRole } from '../models/user/accountRole.model'
import { Rating } from '../models/acts/rating.model'
import { Member } from '../models/acts/member.model'
import { Genre } from '../models/acts/genre.model'
import { Band } from '../models/acts/band.model'
import { Location } from '../models/acts/location.model'
import { Show } from '../models/acts/show.model'
import { Tour } from '../models/acts/tour.model'
import { City } from '../models/acts/city.model'
import accounts from "./../data/accounts.json"
import orders from "./../data/orders.json"
@@ -18,7 +20,8 @@ import accountRoles from "./../data/accountRoles.json"
import bands from "./../data/bands.json"
import genres from "./../data/genres.json"
import locations from "./../data/locations.json"
import shows from "./../data/shows.json"
import tours from "./../data/tours.json"
import cities from "./../data/cities.json"
/**
@@ -47,6 +50,7 @@ export function deleteAllTables() {
export async function prepopulateDatabase() {
AccountRole.bulkCreate(accountRoles.data)
Genre.bulkCreate(genres.data)
City.bulkCreate(cities.data)
Location.bulkCreate(locations.data)
// Account & Sub tables
@@ -68,7 +72,15 @@ export async function prepopulateDatabase() {
}
Show.bulkCreate(shows.data)
for (let tour of tours.data) {
await Tour.create(tour)
.then(async dataset => {
for (let show of tour.shows) {
await Show.create(show)
}
})
}
Order.bulkCreate(orders.data)
OrderItem.bulkCreate(orderItems.data)
}

View File

@@ -9,6 +9,7 @@ import { show } from './routes/show.routes'
import { band } from './routes/band.routes'
import { genre } from './routes/genre.routes'
import { location } from './routes/location.routes'
import { tour } from './routes/tour.routes'
const app = express()
const port = 3000
@@ -27,9 +28,9 @@ const path = require('path')
app.use('/static', express.static(path.join(__dirname, 'images')))
// Add delay for more realistic response times
app.use((req, res, next) => {
setTimeout(next, Math.floor((Math.random () * 4000) + 100))
})
// app.use((req, res, next) => {
// setTimeout(next, Math.floor((Math.random () * 4000) + 100))
// })
// Routes
app.use("/api", api)
@@ -39,6 +40,7 @@ app.use("/genres", genre)
app.use("/locations", location)
app.use("/orders", order)
app.use("/accounts", account)
app.use("/tours", tour)
// Start server

View File

@@ -0,0 +1,16 @@
import { GenreModel } from "./genreModel"
import { MemberModel } from "./memberModel"
import { RatingModel } from "./ratingModel"
export class BandModel {
id: Number
name: string
foundingYear: Number
descriptionEn: String
descriptionDe: String
images: Array<String>
logo: String
genre: GenreModel
ratings: Array<RatingModel>
members: Array<MemberModel>
}

View File

@@ -1,4 +0,0 @@
export class BrandModel {
id: number = 0
name: string = ""
}

View File

@@ -1,5 +0,0 @@
export class CategoryModel {
id: number = -1
name: string
icon: string
}

View File

@@ -0,0 +1,4 @@
export class GenreModel {
id: Number
name: String
}

View File

@@ -0,0 +1,7 @@
export class LocationModel {
id: Number
name: String
address: String
city: String
image: String
}

View File

@@ -0,0 +1,8 @@
import { BandModel } from "./bandModel"
export class MemberModel {
id: Number
name: String
band: BandModel
image: String
}

View File

@@ -1,8 +1,8 @@
import { ProductModel } from "./productModel"
import { ShowModel } from "./showModel"
export class OrderItemModel {
orderId: number = -1
quantity: number = 1
orderPrice: number = 0
product: ProductModel
product: ShowModel
}

View File

@@ -1,17 +0,0 @@
import { BrandModel } from "./brandModel"
import { CategoryModel } from "./categoryModel"
export class ProductModel {
id: number = 0
category: CategoryModel = new CategoryModel()
brand: BrandModel = new BrandModel()
name: string = ""
description: string = ""
price: number = 0
discount: number = 0
rating: number = 1
inStock: number = 0
offered: boolean = true
specs: Array<string> = []
images: Array<string> = [""]
}

View File

@@ -0,0 +1,9 @@
import { AccountModel } from "./accountModel"
import { BandModel } from "./bandModel"
export class RatingModel {
id: Number
account: AccountModel
rating: Number
band: BandModel
}

View File

@@ -0,0 +1,9 @@
import { LocationModel } from "./locationModel"
export class ShowModel {
id: Number
inStock: Number
date: String
price: Number
location: LocationModel
}

View File

@@ -0,0 +1,10 @@
import { BandModel } from "./bandModel"
import { ShowModel } from "./showModel"
export class TourModel {
id: Number
name: String
band: BandModel
offered: Boolean
shows: Array<ShowModel>
}