More swagger documentation
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
/**
|
||||
* @swagger
|
||||
* tags:
|
||||
* name: Concerts
|
||||
* description: API to manage the concerts
|
||||
*/
|
||||
import { Location } from "../models/locations/location.model";
|
||||
import { Concert } from "../models/acts/concert.model";
|
||||
import { Request, Response, Router } from "express";
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
/**
|
||||
* @swagger
|
||||
* tags:
|
||||
* name: Genres
|
||||
* description: API to manage the music genres
|
||||
*/
|
||||
import { Band } from "../models/acts/band.model";
|
||||
import { Genre } from "../models/acts/genre.model";
|
||||
import { Request, Response, Router } from "express";
|
||||
@@ -5,7 +11,20 @@ import { Request, Response, Router } from "express";
|
||||
export const genre = Router()
|
||||
|
||||
/**
|
||||
* Get all available Genres
|
||||
* @swagger
|
||||
* /genres:
|
||||
* get:
|
||||
* summary: Get all available genres
|
||||
* tags: [Genres]
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/genre'
|
||||
* 500:
|
||||
* description: Internal Server Error
|
||||
*/
|
||||
genre.get("/", (req: Request, res: Response) => {
|
||||
Genre.findAll({
|
||||
@@ -19,8 +38,22 @@ genre.get("/", (req: Request, res: Response) => {
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* Update a Genre entry
|
||||
* @swagger
|
||||
* /genres:
|
||||
* patch:
|
||||
* summary: Update the dataset of a genre
|
||||
* tags: [Genres]
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/genre'
|
||||
* 500:
|
||||
* description: Internal Server Error
|
||||
*/
|
||||
genre.patch("/", (req: Request, res: Response) => {
|
||||
Genre.update(req.body, {
|
||||
@@ -36,8 +69,22 @@ genre.patch("/", (req: Request, res: Response) => {
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Genre entry
|
||||
* @swagger
|
||||
* /genres:
|
||||
* post:
|
||||
* summary: Add a new dataset of a genre
|
||||
* tags: [Genres]
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/genre'
|
||||
* 500:
|
||||
* description: Internal Server Error
|
||||
*/
|
||||
genre.post("/", (req: Request, res: Response) => {
|
||||
Genre.create(req.body)
|
||||
@@ -49,8 +96,22 @@ genre.post("/", (req: Request, res: Response) => {
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Genre entry
|
||||
* @swagger
|
||||
* /genres:
|
||||
* delete:
|
||||
* summary: Delete the dataset of a genre
|
||||
* tags: [Genres]
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/genre'
|
||||
* 500:
|
||||
* description: Internal Server Error
|
||||
*/
|
||||
genre.delete("/", (req: Request, res: Response) => {
|
||||
Genre.destroy({
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
/**
|
||||
* @swagger
|
||||
* tags:
|
||||
* name: Locations
|
||||
* description: API to manage the event locations
|
||||
*/
|
||||
import { Concert } from "../models/acts/concert.model";
|
||||
import { City } from "../models/locations/city.model";
|
||||
import { Location } from "../models/locations/location.model";
|
||||
@@ -10,24 +16,57 @@ import { Op } from "sequelize";
|
||||
|
||||
export const location = Router()
|
||||
|
||||
// Response include rules
|
||||
const locationStructure = [
|
||||
City,
|
||||
{
|
||||
model: Concert,
|
||||
include: [ Band ]
|
||||
},
|
||||
{
|
||||
model: SeatGroup,
|
||||
include: [
|
||||
{
|
||||
model: SeatRow,
|
||||
include: [ Seat ]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
/**
|
||||
* Get all available Locations
|
||||
*
|
||||
* @query sort Sort results ascending (asc) or descending (desc)
|
||||
* @query count Limit number of results
|
||||
* @swagger
|
||||
* /locations:
|
||||
* get:
|
||||
* summary: Get all available locations
|
||||
* tags: [Locations]
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: sort
|
||||
* schema:
|
||||
* type: string
|
||||
* required: false
|
||||
* description: Sort locations by number of concerts ascending (asc) or descending (desc)
|
||||
* - 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/location'
|
||||
*/
|
||||
location.get("/", (req: Request, res: Response) => {
|
||||
let sort = req.query.sort
|
||||
let count = req.query.count
|
||||
|
||||
Location.findAll({
|
||||
include: [
|
||||
City,
|
||||
{
|
||||
model: Concert,
|
||||
include: [ Band ],
|
||||
}
|
||||
],
|
||||
include: locationStructure,
|
||||
attributes: {
|
||||
exclude: [ "cityId" ]
|
||||
}
|
||||
@@ -60,29 +99,32 @@ location.get("/", (req: Request, res: Response) => {
|
||||
|
||||
|
||||
/**
|
||||
* Get all data about a specific location
|
||||
*
|
||||
* @param urlName UrlName of the band (e.g. Red Hot Chili Peppers => red-hot-chili-peppers)
|
||||
* @swagger
|
||||
* /locations/{urlName}:
|
||||
* get:
|
||||
* summary: Download all available informations about a specific locations
|
||||
* tags: [Locations]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: urlName
|
||||
* schema:
|
||||
* type: string
|
||||
* required: true
|
||||
* description: Url name of the location to request for
|
||||
* responses:
|
||||
* 200:
|
||||
* description: List of band objects
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/location'
|
||||
* 500:
|
||||
* description: Internal server error
|
||||
*/
|
||||
location.get("/location/:urlName", (req: Request, res: Response) => {
|
||||
Location.findOne({
|
||||
where: { urlName: req.params.urlName },
|
||||
include: [
|
||||
City,
|
||||
{
|
||||
model: Concert,
|
||||
include: [ Band ],
|
||||
},
|
||||
{
|
||||
model: SeatGroup,
|
||||
include: [
|
||||
{
|
||||
model: SeatRow,
|
||||
include: [ Seat ]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
include: locationStructure,
|
||||
attributes: {
|
||||
exclude: [ "cityId" ]
|
||||
}
|
||||
@@ -105,9 +147,27 @@ location.get("/location/:urlName", (req: Request, res: Response) => {
|
||||
|
||||
|
||||
/**
|
||||
* Search for Locations
|
||||
*
|
||||
* @query value Search term to look for
|
||||
* @swagger
|
||||
* /locations/search:
|
||||
* get:
|
||||
* summary: Search for locations
|
||||
* tags: [Locations]
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: value
|
||||
* schema:
|
||||
* type: string
|
||||
* required: true
|
||||
* description: Search term
|
||||
* responses:
|
||||
* 200:
|
||||
* description: List of band objects
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/location'
|
||||
* 500:
|
||||
* description: Internal server error
|
||||
*/
|
||||
location.get("/search", (req: Request, res: Response) => {
|
||||
Location.findAll({
|
||||
@@ -128,7 +188,7 @@ location.get("/search", (req: Request, res: Response) => {
|
||||
}
|
||||
]
|
||||
},
|
||||
include: [ City, Concert ]
|
||||
include: locationStructure
|
||||
})
|
||||
.then(locations => {
|
||||
res.status(200).json(locations)
|
||||
|
||||
Reference in New Issue
Block a user