From 4c31ccd0213f96c57d35bb6fa3d49d2b74afc46c Mon Sep 17 00:00:00 2001 From: Tobias Zoghaib Date: Mon, 30 Dec 2024 23:13:41 +0100 Subject: [PATCH] Backend documentation --- backend/routes/band.routes.ts | 2 - backend/routes/concert.routes.ts | 152 +++++++---- backend/routes/location.routes.ts | 2 +- backend/routes/order.routes.ts | 26 +- backend/swagger.json | 422 ++++++++++-------------------- 5 files changed, 267 insertions(+), 337 deletions(-) diff --git a/backend/routes/band.routes.ts b/backend/routes/band.routes.ts index cc8a8a7..6419996 100644 --- a/backend/routes/band.routes.ts +++ b/backend/routes/band.routes.ts @@ -166,8 +166,6 @@ band.get("/band/:name", (req: Request, res: Response) => { */ band.get("/search", async (req: Request, res: Response) => { // Workaround, because SQLite can't handle stacked queries - console.log(1) - console.log(req.query.value) let prompts = decodeURI(String(req.query.value)).split(";") // On stacked prompts, execute last prompt diff --git a/backend/routes/concert.routes.ts b/backend/routes/concert.routes.ts index 70dfad0..1a568bf 100644 --- a/backend/routes/concert.routes.ts +++ b/backend/routes/concert.routes.ts @@ -17,18 +17,68 @@ import { Op } from "sequelize"; export const concert = Router() +const concertStructure = [ + { + model: Band + }, + { + model: Location, + include: [ + { + model: City + }, + { + model: SeatGroup, + include: [ + { + model: SeatRow, + include: [ + { + model: Seat, + include: [ + { + model: Ticket + } + ] + } + ] + } + ] + } + ], + attributes: { + exclude: [ "cityId" ] + } + } +] + +/** + * @swagger + * /concerts: + * get: + * summary: Get all available concerts + * tags: [Concerts] + * parameters: + * - in: query + * name: count + * schema: + * type: number + * required: false + * description: Limit number of results + * responses: + * 200: + * description: OK + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/concert' + */ concert.get("/", (req: Request, res: Response) => { let count = req.query.count Concert.findAll({ - include: [ - { - model: Location, - include: [ City ] - }, - Band - ], + include: concertStructure, order: [ [ 'date', 'ASC' ] ] @@ -47,47 +97,31 @@ concert.get("/", (req: Request, res: Response) => { }) -// Get all available data about a band by it's ID +/** + * @swagger + * /concerts/concert/{id}: + * get: + * summary: Download all available informations about a specific concert + * tags: [Concerts] + * parameters: + * - in: path + * name: id + * schema: + * type: number + * required: true + * description: ID of concert in database + * responses: + * 200: + * description: Single concert object + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/concert' + * 404: + * description: Not found + */ concert.get("/concert/:id", (req: Request, res: Response) => { - Concert.findByPk(req.params.id, { - include: [ - { - model: Band, - }, - { - model: Location, - include: [ - { - model: City - }, - { - model: SeatGroup, - include: [ - { - model: SeatRow, - include: [ - { - model: Seat, - include: [ - { - model: Ticket - } - ] - } - ] - } - ] - } - ], - attributes: { - exclude: [ "cityId" ] - } - } - ], - attributes: { - exclude: [ "locationId", "tourId" ] - } - }) + Concert.findByPk(req.params.id, { include: concertStructure }) .then(concert => { concert.dataValues["capacity"] = 0 @@ -125,7 +159,29 @@ concert.get("/concert/:id", (req: Request, res: Response) => { }) -// Concert search +/** + * @swagger + * /concerts/search: + * get: + * summary: Search for concerts + * tags: [Concerts] + * parameters: + * - in: query + * name: value + * schema: + * type: string + * required: true + * description: Search term + * responses: + * 200: + * description: List of concert objects + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/concert' + * 500: + * description: Internal server error + */ concert.get("/search", (req: Request, res: Response) => { Concert.findAll({ where: { diff --git a/backend/routes/location.routes.ts b/backend/routes/location.routes.ts index 54dad3c..39a6aa1 100644 --- a/backend/routes/location.routes.ts +++ b/backend/routes/location.routes.ts @@ -113,7 +113,7 @@ location.get("/", (req: Request, res: Response) => { * description: Url name of the location to request for * responses: * 200: - * description: List of band objects + * description: Single of location objects * content: * application/json: * schema: diff --git a/backend/routes/order.routes.ts b/backend/routes/order.routes.ts index f18d48d..11b32da 100644 --- a/backend/routes/order.routes.ts +++ b/backend/routes/order.routes.ts @@ -129,8 +129,6 @@ order.get("/", verifyToken, (req: Request, res: Response) => { order.post("/", verifyToken, (req: Request, res: Response) => { req.body["accountId"] = req["id"] - console.log(req.body) - Order.create(req.body) .then(async order => { for (let ticket of req.body.tickets) { @@ -158,6 +156,30 @@ order.post("/", verifyToken, (req: Request, res: Response) => { }) }) + +/** + * @swagger + * /orders: + * patch: + * summary: Update an order + * tags: [Orders] + * parameters: + * - in: body + * name: order + * schema: + * type: object + * required: true + * description: Updated order object + * responses: + * 200: + * description: OK + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/order' + * 500: + * description: Internal server error + */ order.patch("/", (req: Request, res: Response) => { Order.update(req.body, { where: { diff --git a/backend/swagger.json b/backend/swagger.json index 693f003..7ca6d8f 100644 --- a/backend/swagger.json +++ b/backend/swagger.json @@ -162,291 +162,60 @@ "description": "Bands with this genre object" } }, - "example": { - "id": 849, - "urlName": "palladium", - "name": "Palladium", - "address": "Schanzenstraße 40", - "imageIndoor": "http://localhost:3000/static/locations/palladium-indoor.jpg", - "imageOutdoor": "http://localhost:3000/static/locations/palladium-outdoor.jpg", - "layout": 1, - "capacity": 50, - "city": { - "id": 250, - "name": "Köln", - "country": "Germany" - }, - "seatGroups": [ - { - "id": 3949, - "name": "A", - "surcharge": 30, - "capacity": 50, - "standingArea": true, - "locationId": 849, - "seatRows": [ - { - "id": 14999, - "row": 0, - "seatGroupId": 3949, - "seats": [ - { - "id": 108411, - "seatNr": 1, - "seatRowId": 14999 - }, - { - "id": 108412, - "seatNr": 2, - "seatRowId": 14999 - }, - { - "id": 108413, - "seatNr": 3, - "seatRowId": 14999 - }, - { - "id": 108414, - "seatNr": 4, - "seatRowId": 14999 - }, - { - "id": 108415, - "seatNr": 5, - "seatRowId": 14999 - }, - { - "id": 108416, - "seatNr": 6, - "seatRowId": 14999 - }, - { - "id": 108417, - "seatNr": 7, - "seatRowId": 14999 - }, - { - "id": 108418, - "seatNr": 8, - "seatRowId": 14999 - }, - { - "id": 108419, - "seatNr": 9, - "seatRowId": 14999 - }, - { - "id": 108420, - "seatNr": 10, - "seatRowId": 14999 - }, - { - "id": 108421, - "seatNr": 11, - "seatRowId": 14999 - }, - { - "id": 108422, - "seatNr": 12, - "seatRowId": 14999 - }, - { - "id": 108423, - "seatNr": 13, - "seatRowId": 14999 - }, - { - "id": 108424, - "seatNr": 14, - "seatRowId": 14999 - }, - { - "id": 108425, - "seatNr": 15, - "seatRowId": 14999 - }, - { - "id": 108426, - "seatNr": 16, - "seatRowId": 14999 - }, - { - "id": 108427, - "seatNr": 17, - "seatRowId": 14999 - }, - { - "id": 108428, - "seatNr": 18, - "seatRowId": 14999 - }, - { - "id": 108429, - "seatNr": 19, - "seatRowId": 14999 - }, - { - "id": 108430, - "seatNr": 20, - "seatRowId": 14999 - }, - { - "id": 108431, - "seatNr": 21, - "seatRowId": 14999 - }, - { - "id": 108432, - "seatNr": 22, - "seatRowId": 14999 - }, - { - "id": 108433, - "seatNr": 23, - "seatRowId": 14999 - }, - { - "id": 108434, - "seatNr": 24, - "seatRowId": 14999 - }, - { - "id": 108435, - "seatNr": 25, - "seatRowId": 14999 - }, - { - "id": 108436, - "seatNr": 26, - "seatRowId": 14999 - }, - { - "id": 108437, - "seatNr": 27, - "seatRowId": 14999 - }, - { - "id": 108438, - "seatNr": 28, - "seatRowId": 14999 - }, - { - "id": 108439, - "seatNr": 29, - "seatRowId": 14999 - }, - { - "id": 108440, - "seatNr": 30, - "seatRowId": 14999 - }, - { - "id": 108441, - "seatNr": 31, - "seatRowId": 14999 - }, - { - "id": 108442, - "seatNr": 32, - "seatRowId": 14999 - }, - { - "id": 108443, - "seatNr": 33, - "seatRowId": 14999 - }, - { - "id": 108444, - "seatNr": 34, - "seatRowId": 14999 - }, - { - "id": 108445, - "seatNr": 35, - "seatRowId": 14999 - }, - { - "id": 108446, - "seatNr": 36, - "seatRowId": 14999 - }, - { - "id": 108447, - "seatNr": 37, - "seatRowId": 14999 - }, - { - "id": 108448, - "seatNr": 38, - "seatRowId": 14999 - }, - { - "id": 108449, - "seatNr": 39, - "seatRowId": 14999 - }, - { - "id": 108450, - "seatNr": 40, - "seatRowId": 14999 - }, - { - "id": 108451, - "seatNr": 41, - "seatRowId": 14999 - }, - { - "id": 108452, - "seatNr": 42, - "seatRowId": 14999 - }, - { - "id": 108453, - "seatNr": 43, - "seatRowId": 14999 - }, - { - "id": 108454, - "seatNr": 44, - "seatRowId": 14999 - }, - { - "id": 108455, - "seatNr": 45, - "seatRowId": 14999 - }, - { - "id": 108456, - "seatNr": 46, - "seatRowId": 14999 - }, - { - "id": 108457, - "seatNr": 47, - "seatRowId": 14999 - }, - { - "id": 108458, - "seatNr": 48, - "seatRowId": 14999 - }, - { - "id": 108459, - "seatNr": 49, - "seatRowId": 14999 - }, - { - "id": 108460, - "seatNr": 50, - "seatRowId": 14999 - } - ] + "example": [ + { + "id": 562, + "name": "Funk Rock", + "bands": [ + { + "images": [ + "http://localhost:3000/static/bands/red-hot-chili-peppers-1.jpg", + "http://localhost:3000/static/bands/red-hot-chili-peppers-2.jpg", + "http://localhost:3000/static/bands/red-hot-chili-peppers-3.jpg", + "http://localhost:3000/static/bands/red-hot-chili-peppers-4.jpg" + ], + "id": 265, + "name": "Red Hot Chili Peppers", + "foundingYear": 1983, + "descriptionEn": "The Red Hot Chili Peppers are an American rock band formed in Los Angeles in 1983, comprising vocalist Anthony Kiedis, bassist Flea, drummer Chad Smith, and guitarist John Frusciante. Their music incorporates elements of alternative rock, funk, punk rock, hard rock, hip hop, and psychedelic rock. Their eclectic range has influenced genres such as funk metal, rap metal, rap rock, and nu metal. With over 120 million records sold worldwide, the Red Hot Chili Peppers are one of the top-selling bands of all time.", + "descriptionDe": "Red Hot Chili Peppers (Abkürzung: RHCP) ist eine 1983 gegründete US-amerikanische Funk- und Alternative-Rockband. Sie zählt zu den kommerziell erfolgreichsten Vertretern des Crossover. Ihr Album Blood Sugar Sex Magik gilt als eines der bedeutendsten dieses Genres.", + "imageMembers": "http://localhost:3000/static/bands/red-hot-chili-peppers-members.jpg", + "logo": "http://localhost:3000/static/bands/red-hot-chili-peppers-logo.png", + "BandGenre": { + "id": 793, + "genreId": 562, + "bandId": 265 } - ] - } - ], - "nrOfConcerts": 0 - } + } + ] + }, + { + "id": 563, + "name": "Alternative Rock", + "bands": [ + { + "images": [ + "http://localhost:3000/static/bands/red-hot-chili-peppers-1.jpg", + "http://localhost:3000/static/bands/red-hot-chili-peppers-2.jpg", + "http://localhost:3000/static/bands/red-hot-chili-peppers-3.jpg", + "http://localhost:3000/static/bands/red-hot-chili-peppers-4.jpg" + ], + "id": 265, + "name": "Red Hot Chili Peppers", + "foundingYear": 1983, + "descriptionEn": "The Red Hot Chili Peppers are an American rock band formed in Los Angeles in 1983, comprising vocalist Anthony Kiedis, bassist Flea, drummer Chad Smith, and guitarist John Frusciante. Their music incorporates elements of alternative rock, funk, punk rock, hard rock, hip hop, and psychedelic rock. Their eclectic range has influenced genres such as funk metal, rap metal, rap rock, and nu metal. With over 120 million records sold worldwide, the Red Hot Chili Peppers are one of the top-selling bands of all time.", + "descriptionDe": "Red Hot Chili Peppers (Abkürzung: RHCP) ist eine 1983 gegründete US-amerikanische Funk- und Alternative-Rockband. Sie zählt zu den kommerziell erfolgreichsten Vertretern des Crossover. Ihr Album Blood Sugar Sex Magik gilt als eines der bedeutendsten dieses Genres.", + "imageMembers": "http://localhost:3000/static/bands/red-hot-chili-peppers-members.jpg", + "logo": "http://localhost:3000/static/bands/red-hot-chili-peppers-logo.png", + "BandGenre": { + "id": 794, + "genreId": 563, + "bandId": 265 + } + } + ] + } + ] }, "location": { "type": "object", @@ -799,6 +568,91 @@ } } }, + "concert": { + "type": "object", + "properties": { + "id": { + "type": "number", + "description": "The auto-generated id" + }, + "date": { + "type": "string", + "description": "Date of the concert" + }, + "name": { + "type": "string", + "description": "Name of concert" + }, + "price": { + "type": "string", + "description": "Lowest price of concert" + }, + "image": { + "type": "number", + "description": "Concert image" + }, + "inStock": { + "type": "string", + "description": "Amount of available tickets" + }, + "offered": { + "type": "string", + "description": "Display concert in UI" + }, + "band": { + "type": "object", + "description": "Band object" + }, + "location": { + "type": "object", + "description": "Location object" + } + }, + "example": [ + { + "id": 892, + "date": "2024-11-30", + "name": "Unlimited Love", + "price": 92, + "image": "http://localhost:3000/static/concerts/unlimited-love-tour.jpg", + "inStock": 169, + "offered": true, + "bandId": 265, + "locationId": 834, + "band": { + "images": [ + "http://localhost:3000/static/bands/red-hot-chili-peppers-1.jpg", + "http://localhost:3000/static/bands/red-hot-chili-peppers-2.jpg", + "http://localhost:3000/static/bands/red-hot-chili-peppers-3.jpg", + "http://localhost:3000/static/bands/red-hot-chili-peppers-4.jpg" + ], + "id": 265, + "name": "Red Hot Chili Peppers", + "foundingYear": 1983, + "descriptionEn": "The Red Hot Chili Peppers are an American rock band formed in Los Angeles in 1983, comprising vocalist Anthony Kiedis, bassist Flea, drummer Chad Smith, and guitarist John Frusciante. Their music incorporates elements of alternative rock, funk, punk rock, hard rock, hip hop, and psychedelic rock. Their eclectic range has influenced genres such as funk metal, rap metal, rap rock, and nu metal. With over 120 million records sold worldwide, the Red Hot Chili Peppers are one of the top-selling bands of all time.", + "descriptionDe": "Red Hot Chili Peppers (Abkürzung: RHCP) ist eine 1983 gegründete US-amerikanische Funk- und Alternative-Rockband. Sie zählt zu den kommerziell erfolgreichsten Vertretern des Crossover. Ihr Album Blood Sugar Sex Magik gilt als eines der bedeutendsten dieses Genres.", + "imageMembers": "http://localhost:3000/static/bands/red-hot-chili-peppers-members.jpg", + "logo": "http://localhost:3000/static/bands/red-hot-chili-peppers-logo.png" + }, + "location": { + "id": 834, + "urlName": "swiss-life-hall", + "name": "Swiss Life Hall", + "address": "Ferdinand-Wilhelm-Fricke-Weg 8", + "imageIndoor": "http://localhost:3000/static/locations/swiss-life-hall-indoor.jpg", + "imageOutdoor": "http://localhost:3000/static/locations/swiss-life-hall-outdoor.jpg", + "layout": 2, + "capacity": 180, + "city": { + "id": 246, + "name": "Hannover", + "country": "Germany" + }, + "seatGroups": [] + } + } + ] + }, "band": { "type": "object", "properties": {