Add ToursTable, update API documentation
This commit is contained in:
9
software/backend/data/cities.json
Normal file
9
software/backend/data/cities.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "Hannover",
|
||||
"country": "Germany"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
{
|
||||
"id": 0,
|
||||
"orderId": 0,
|
||||
"productId": 0,
|
||||
"showId": 0,
|
||||
"quantity": 2,
|
||||
"orderPrice": 184
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
20
software/backend/data/tours.json
Normal file
20
software/backend/data/tours.json
Normal 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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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!")
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 183 KiB After Width: | Height: | Size: 183 KiB |
@@ -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
|
||||
}
|
||||
17
software/backend/models/acts/city.model.ts
Normal file
17
software/backend/models/acts/city.model.ts
Normal 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[]
|
||||
}
|
||||
28
software/backend/models/acts/location.model.ts
Normal file
28
software/backend/models/acts/location.model.ts
Normal 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
|
||||
}
|
||||
@@ -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 })
|
||||
@@ -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[]
|
||||
}
|
||||
24
software/backend/models/acts/tour.model.ts
Normal file
24
software/backend/models/acts/tour.model.ts
Normal 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[]
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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,
|
||||
@@ -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
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
44
software/backend/routes/tour.routes.ts
Normal file
44
software/backend/routes/tour.routes.ts
Normal 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)
|
||||
})
|
||||
})
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user