diff --git a/README.md b/README.md index 44da621..b1cb944 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ The application host it's data in a SQLite database. The access is managed by an #### Listing existing
-GET /products/ (Get all products) +GET /bands (Get all bands) ##### Parameters @@ -83,11 +83,13 @@ The application host it's data in a SQLite database. The access is managed by an ##### Responses > | http code | content-type | response | > | :---: | --- | --- | -> | `200` | `application/json` | `Array` + `Category`, `Brand` | +> | `200` | `application/json` | `Array` |
+ +
-GET /products/:id (Get a product by it's id) +GET /bands/:id (Get all information about one band) ##### Parameters @@ -98,9 +100,72 @@ The application host it's data in a SQLite database. The access is managed by an ##### Responses > | http code | content-type | response | > | :---: | --- | --- | -> | `200` | `application/json` | `ProductModel` + `Category`, `Brand` | +> | `200` | `application/json` | `Band` + `Array` + `Array` |
+ + +
+GET /shows/:id (Get all information about one show) + + +##### Parameters +> | name | type | data type | description | +> | :---: | --- | --- | --- | +> | `id` | required | string | ID of product in the database | + +##### Responses +> | http code | content-type | response | +> | :---: | --- | --- | +> | `200` | `application/json` | `Show` + `Tour` + `Location` + `City` | +
+ + + +
+GET /tours (Get all tours) + + +##### Parameters +> None + +##### Responses +> | http code | content-type | response | +> | :---: | --- | --- | +> | `200` | `application/json` | `Array` + `Band` + `Show` + `Location` + `City` | +
+ + +
+GET /genres (Get all genres) + + +##### Parameters +> None + +##### Responses +> | http code | content-type | response | +> | :---: | --- | --- | +> | `200` | `application/json` | `Array` | +
+ + + +
+GET /locations (Get all locations) + + +##### Parameters +> None + +##### Responses +> | http code | content-type | response | +> | :---: | --- | --- | +> | `200` | `application/json` | `Array` + `City` | +
+ + +
GET /orders/:id (Get all orders of an user) @@ -116,6 +181,8 @@ The application host it's data in a SQLite database. The access is managed by an > | `200` | `application/json` | `ProductModel` + `Order`, `OrderItem`, `Product` |
+ +
GET /categories/ (Get all Categories) @@ -130,6 +197,7 @@ The application host it's data in a SQLite database. The access is managed by an
+
GET /brands (Get all Brands) @@ -143,8 +211,10 @@ The application host it's data in a SQLite database. The access is managed by an > | `200` | `application/json` | `Array` |
+ --- + #### Creating new
diff --git a/misc/database.drawio b/misc/database.drawio index 3014273..67d5b0c 100644 --- a/misc/database.drawio +++ b/misc/database.drawio @@ -1,816 +1,385 @@ - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + + + + + + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - + + - - + + - - + + - + - + - + - - + + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -820,12 +389,12 @@ - + - + @@ -835,15 +404,15 @@ - + - + - + @@ -853,39 +422,39 @@ - + - + - + - + - + - + - + - + @@ -895,17 +464,17 @@ - + - + - + @@ -915,17 +484,17 @@ - + - + - + @@ -935,82 +504,166 @@ - + - + - + - + - + - + - + - + - - + + - + - + - + - - + + - - + + - + - - + + - - + + + + - + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/misc/images/database.png b/misc/images/database.png index c06f97a..6f80c17 100644 Binary files a/misc/images/database.png and b/misc/images/database.png differ diff --git a/software/backend/data/cities.json b/software/backend/data/cities.json new file mode 100644 index 0000000..4977687 --- /dev/null +++ b/software/backend/data/cities.json @@ -0,0 +1,9 @@ +{ + "data": [ + { + "id": 0, + "name": "Hannover", + "country": "Germany" + } + ] +} \ No newline at end of file diff --git a/software/backend/data/locations.json b/software/backend/data/locations.json index 6b5289c..a9a132e 100644 --- a/software/backend/data/locations.json +++ b/software/backend/data/locations.json @@ -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" } ] diff --git a/software/backend/data/orderItems.json b/software/backend/data/orderItems.json index 61d40b3..612ce53 100644 --- a/software/backend/data/orderItems.json +++ b/software/backend/data/orderItems.json @@ -3,7 +3,7 @@ { "id": 0, "orderId": 0, - "productId": 0, + "showId": 0, "quantity": 2, "orderPrice": 184 } diff --git a/software/backend/data/shows.json b/software/backend/data/shows.json deleted file mode 100644 index f02c050..0000000 --- a/software/backend/data/shows.json +++ /dev/null @@ -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 - } - ] -} \ No newline at end of file diff --git a/software/backend/data/tours.json b/software/backend/data/tours.json new file mode 100644 index 0000000..ff4b284 --- /dev/null +++ b/software/backend/data/tours.json @@ -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 + } + ] + } + ] +} \ No newline at end of file diff --git a/software/backend/database.ts b/software/backend/database.ts index 4fce70a..86f08c9 100644 --- a/software/backend/database.ts +++ b/software/backend/database.ts @@ -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!") diff --git a/software/backend/images/red-hot-chili-peppers-logo.png b/software/backend/images/bands/red-hot-chili-peppers-logo.png similarity index 100% rename from software/backend/images/red-hot-chili-peppers-logo.png rename to software/backend/images/bands/red-hot-chili-peppers-logo.png diff --git a/software/backend/images/red-hot-chili-peppers.jpg b/software/backend/images/bands/red-hot-chili-peppers.jpg similarity index 100% rename from software/backend/images/red-hot-chili-peppers.jpg rename to software/backend/images/bands/red-hot-chili-peppers.jpg diff --git a/software/backend/models/band.model.ts b/software/backend/models/acts/band.model.ts similarity index 92% rename from software/backend/models/band.model.ts rename to software/backend/models/acts/band.model.ts index 124dec6..2885260 100644 --- a/software/backend/models/band.model.ts +++ b/software/backend/models/acts/band.model.ts @@ -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 } \ No newline at end of file diff --git a/software/backend/models/acts/city.model.ts b/software/backend/models/acts/city.model.ts new file mode 100644 index 0000000..fe574d8 --- /dev/null +++ b/software/backend/models/acts/city.model.ts @@ -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[] +} \ No newline at end of file diff --git a/software/backend/models/genre.model.ts b/software/backend/models/acts/genre.model.ts similarity index 100% rename from software/backend/models/genre.model.ts rename to software/backend/models/acts/genre.model.ts diff --git a/software/backend/models/acts/location.model.ts b/software/backend/models/acts/location.model.ts new file mode 100644 index 0000000..16706df --- /dev/null +++ b/software/backend/models/acts/location.model.ts @@ -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 +} \ No newline at end of file diff --git a/software/backend/models/member.model.ts b/software/backend/models/acts/member.model.ts similarity index 100% rename from software/backend/models/member.model.ts rename to software/backend/models/acts/member.model.ts diff --git a/software/backend/models/rating.model.ts b/software/backend/models/acts/rating.model.ts similarity index 89% rename from software/backend/models/rating.model.ts rename to software/backend/models/acts/rating.model.ts index fde0034..fe0bfc1 100644 --- a/software/backend/models/rating.model.ts +++ b/software/backend/models/acts/rating.model.ts @@ -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 }) diff --git a/software/backend/models/show.model.ts b/software/backend/models/acts/show.model.ts similarity index 50% rename from software/backend/models/show.model.ts rename to software/backend/models/acts/show.model.ts index 6c94fd3..544de49 100644 --- a/software/backend/models/show.model.ts +++ b/software/backend/models/acts/show.model.ts @@ -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[] } \ No newline at end of file diff --git a/software/backend/models/acts/tour.model.ts b/software/backend/models/acts/tour.model.ts new file mode 100644 index 0000000..dcc7e67 --- /dev/null +++ b/software/backend/models/acts/tour.model.ts @@ -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[] +} \ No newline at end of file diff --git a/software/backend/models/location.model.ts b/software/backend/models/location.model.ts deleted file mode 100644 index 9c93d01..0000000 --- a/software/backend/models/location.model.ts +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/software/backend/models/order.model.ts b/software/backend/models/ordering/order.model.ts similarity index 83% rename from software/backend/models/order.model.ts rename to software/backend/models/ordering/order.model.ts index a0c29b1..e5577fe 100644 --- a/software/backend/models/order.model.ts +++ b/software/backend/models/ordering/order.model.ts @@ -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, diff --git a/software/backend/models/orderItem.model.ts b/software/backend/models/ordering/orderItem.model.ts similarity index 88% rename from software/backend/models/orderItem.model.ts rename to software/backend/models/ordering/orderItem.model.ts index e8056f6..9be7682 100644 --- a/software/backend/models/orderItem.model.ts +++ b/software/backend/models/ordering/orderItem.model.ts @@ -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 diff --git a/software/backend/models/account.model.ts b/software/backend/models/user/account.model.ts similarity index 89% rename from software/backend/models/account.model.ts rename to software/backend/models/user/account.model.ts index 4b10b77..4b73c40 100644 --- a/software/backend/models/account.model.ts +++ b/software/backend/models/user/account.model.ts @@ -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 { diff --git a/software/backend/models/accountRole.model.ts b/software/backend/models/user/accountRole.model.ts similarity index 100% rename from software/backend/models/accountRole.model.ts rename to software/backend/models/user/accountRole.model.ts diff --git a/software/backend/models/address.model.ts b/software/backend/models/user/address.model.ts similarity index 90% rename from software/backend/models/address.model.ts rename to software/backend/models/user/address.model.ts index 52241e4..f7efc32 100644 --- a/software/backend/models/address.model.ts +++ b/software/backend/models/user/address.model.ts @@ -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 { diff --git a/software/backend/models/payment.model.ts b/software/backend/models/user/payment.model.ts similarity index 89% rename from software/backend/models/payment.model.ts rename to software/backend/models/user/payment.model.ts index 45e565a..5efaa91 100644 --- a/software/backend/models/payment.model.ts +++ b/software/backend/models/user/payment.model.ts @@ -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 { diff --git a/software/backend/routes/account.routes.ts b/software/backend/routes/account.routes.ts index 56dd252..bab0ab9 100644 --- a/software/backend/routes/account.routes.ts +++ b/software/backend/routes/account.routes.ts @@ -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() diff --git a/software/backend/routes/band.routes.ts b/software/backend/routes/band.routes.ts index 84f5382..c73aadc 100644 --- a/software/backend/routes/band.routes.ts +++ b/software/backend/routes/band.routes.ts @@ -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) + }) }) \ No newline at end of file diff --git a/software/backend/routes/genre.routes.ts b/software/backend/routes/genre.routes.ts index 9572667..9598575 100644 --- a/software/backend/routes/genre.routes.ts +++ b/software/backend/routes/genre.routes.ts @@ -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() diff --git a/software/backend/routes/location.routes.ts b/software/backend/routes/location.routes.ts index 04ee8e9..56077b6 100644 --- a/software/backend/routes/location.routes.ts +++ b/software/backend/routes/location.routes.ts @@ -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) }) diff --git a/software/backend/routes/order.routes.ts b/software/backend/routes/order.routes.ts index 1b78715..b132855 100644 --- a/software/backend/routes/order.routes.ts +++ b/software/backend/routes/order.routes.ts @@ -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() diff --git a/software/backend/routes/show.routes.ts b/software/backend/routes/show.routes.ts index c44fa61..aae9a08 100644 --- a/software/backend/routes/show.routes.ts +++ b/software/backend/routes/show.routes.ts @@ -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) }) diff --git a/software/backend/routes/tour.routes.ts b/software/backend/routes/tour.routes.ts new file mode 100644 index 0000000..6601c99 --- /dev/null +++ b/software/backend/routes/tour.routes.ts @@ -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) + }) +}) \ No newline at end of file diff --git a/software/backend/scripts/databaseHelper.ts b/software/backend/scripts/databaseHelper.ts index 5ff1da1..f72519d 100644 --- a/software/backend/scripts/databaseHelper.ts +++ b/software/backend/scripts/databaseHelper.ts @@ -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) } \ No newline at end of file diff --git a/software/backend/server.ts b/software/backend/server.ts index 1f06150..7397229 100644 --- a/software/backend/server.ts +++ b/software/backend/server.ts @@ -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 diff --git a/software/src/data/models/bandModel.ts b/software/src/data/models/bandModel.ts new file mode 100644 index 0000000..5ab3b3c --- /dev/null +++ b/software/src/data/models/bandModel.ts @@ -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 + logo: String + genre: GenreModel + ratings: Array + members: Array +} \ No newline at end of file diff --git a/software/src/data/models/brandModel.ts b/software/src/data/models/brandModel.ts deleted file mode 100644 index b30244c..0000000 --- a/software/src/data/models/brandModel.ts +++ /dev/null @@ -1,4 +0,0 @@ -export class BrandModel { - id: number = 0 - name: string = "" -} \ No newline at end of file diff --git a/software/src/data/models/categoryModel.ts b/software/src/data/models/categoryModel.ts deleted file mode 100644 index 31d829e..0000000 --- a/software/src/data/models/categoryModel.ts +++ /dev/null @@ -1,5 +0,0 @@ -export class CategoryModel { - id: number = -1 - name: string - icon: string -} \ No newline at end of file diff --git a/software/src/data/models/genreModel.ts b/software/src/data/models/genreModel.ts new file mode 100644 index 0000000..e1669a3 --- /dev/null +++ b/software/src/data/models/genreModel.ts @@ -0,0 +1,4 @@ +export class GenreModel { + id: Number + name: String +} \ No newline at end of file diff --git a/software/src/data/models/locationModel.ts b/software/src/data/models/locationModel.ts new file mode 100644 index 0000000..9d88d7a --- /dev/null +++ b/software/src/data/models/locationModel.ts @@ -0,0 +1,7 @@ +export class LocationModel { + id: Number + name: String + address: String + city: String + image: String +} \ No newline at end of file diff --git a/software/src/data/models/memberModel.ts b/software/src/data/models/memberModel.ts new file mode 100644 index 0000000..2e302c3 --- /dev/null +++ b/software/src/data/models/memberModel.ts @@ -0,0 +1,8 @@ +import { BandModel } from "./bandModel" + +export class MemberModel { + id: Number + name: String + band: BandModel + image: String +} \ No newline at end of file diff --git a/software/src/data/models/orderItemModel.ts b/software/src/data/models/orderItemModel.ts index bdf081e..6e55ed6 100644 --- a/software/src/data/models/orderItemModel.ts +++ b/software/src/data/models/orderItemModel.ts @@ -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 } \ No newline at end of file diff --git a/software/src/data/models/productModel.ts b/software/src/data/models/productModel.ts deleted file mode 100644 index dce0d9a..0000000 --- a/software/src/data/models/productModel.ts +++ /dev/null @@ -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 = [] - images: Array = [""] -} \ No newline at end of file diff --git a/software/src/data/models/ratingModel.ts b/software/src/data/models/ratingModel.ts new file mode 100644 index 0000000..70cf9a3 --- /dev/null +++ b/software/src/data/models/ratingModel.ts @@ -0,0 +1,9 @@ +import { AccountModel } from "./accountModel" +import { BandModel } from "./bandModel" + +export class RatingModel { + id: Number + account: AccountModel + rating: Number + band: BandModel +} \ No newline at end of file diff --git a/software/src/data/models/showModel.ts b/software/src/data/models/showModel.ts new file mode 100644 index 0000000..0bdb5f4 --- /dev/null +++ b/software/src/data/models/showModel.ts @@ -0,0 +1,9 @@ +import { LocationModel } from "./locationModel" + +export class ShowModel { + id: Number + inStock: Number + date: String + price: Number + location: LocationModel +} \ No newline at end of file diff --git a/software/src/data/models/tourModel.ts b/software/src/data/models/tourModel.ts new file mode 100644 index 0000000..cf3cf6c --- /dev/null +++ b/software/src/data/models/tourModel.ts @@ -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 +} \ No newline at end of file