Changed regions doc so it works with query parameters
This commit is contained in:
parent
ebb1304eeb
commit
3cccdab368
@ -23,12 +23,8 @@ const app = express();
|
|||||||
const swaggerJsdoc = require('swagger-jsdoc');
|
const swaggerJsdoc = require('swagger-jsdoc');
|
||||||
const swaggerUi = require('swagger-ui-express');
|
const swaggerUi = require('swagger-ui-express');
|
||||||
|
|
||||||
const swaggerUIOptions = {
|
|
||||||
explorer: true
|
|
||||||
};
|
|
||||||
|
|
||||||
// Swagger set up
|
// Swagger set up
|
||||||
const swaggerJSOptions = {
|
const swaggerOptions = {
|
||||||
swaggerDefinition: {
|
swaggerDefinition: {
|
||||||
openapi: "3.0.0",
|
openapi: "3.0.0",
|
||||||
info: {
|
info: {
|
||||||
@ -39,7 +35,7 @@ const swaggerJSOptions = {
|
|||||||
"No API Key required.",
|
"No API Key required.",
|
||||||
license: {
|
license: {
|
||||||
name: "Licensing Pending",
|
name: "Licensing Pending",
|
||||||
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
|
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&feature=youtu.be"
|
||||||
},
|
},
|
||||||
contact: {
|
contact: {
|
||||||
name: "travOpti",
|
name: "travOpti",
|
||||||
@ -48,22 +44,22 @@ const swaggerJSOptions = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
servers: [
|
servers: [
|
||||||
|
{
|
||||||
|
url: "http://localhost:3000/api/v1"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
url: "https://travopti.de/api/v1"
|
url: "https://travopti.de/api/v1"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
apis: [
|
apis: [
|
||||||
"./Routes/search.js",
|
"./Routes/*.js",
|
||||||
"./Routes/regions.js",
|
"./Models/handleClimateUpdate.js",
|
||||||
"./Routes/place.js",
|
"./Models/handleClimateUpdateV2.js",
|
||||||
"./Routes/countries.js",
|
|
||||||
"./Routes/climate.js", "./Models/handleClimateUpdate.js", "./Models/handleClimateUpdateV2.js",
|
|
||||||
"./Routes/update.js"
|
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const specs = swaggerJsdoc(swaggerJSOptions);
|
const swaggerDocs = swaggerJsdoc(swaggerOptions);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
@ -74,7 +70,7 @@ const specs = swaggerJsdoc(swaggerJSOptions);
|
|||||||
app.use(express.static(path.join(__dirname, "../../dist")));
|
app.use(express.static(path.join(__dirname, "../../dist")));
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use('/api/v1/doc', swaggerUi.serve, swaggerUi.setup(specs, swaggerUIOptions));
|
app.use('/api/v1/doc', swaggerUi.serve, swaggerUi.setup(swaggerDocs, {explorer: true}));
|
||||||
|
|
||||||
// Express routes
|
// Express routes
|
||||||
app.use(search(dbConn));
|
app.use(search(dbConn));
|
||||||
|
|||||||
@ -21,18 +21,13 @@ const sqlSanitzer = require("../util/sqlstring_sanitizer.js")
|
|||||||
module.exports = dbConn => {
|
module.exports = dbConn => {
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
* path:
|
|
||||||
* /regions:
|
* /regions:
|
||||||
* get:
|
* get:
|
||||||
* summary: Get all regions
|
* summary: Get all regions
|
||||||
* tags: [Regions]
|
* tags: [Regions]
|
||||||
* responses:
|
* responses:
|
||||||
* "200":
|
* "200":
|
||||||
* description: Returns all regions and aviable data
|
* description: Returns aviable data for all regions
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: ''
|
|
||||||
*/
|
*/
|
||||||
router.get("/api/v1/regions", async (req, res) => {
|
router.get("/api/v1/regions", async (req, res) => {
|
||||||
const data = await getRegions(dbConn)
|
const data = await getRegions(dbConn)
|
||||||
@ -46,18 +41,18 @@ module.exports = dbConn => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
* path:
|
* /regions/{id}:
|
||||||
* /regions/:id:
|
|
||||||
* get:
|
* get:
|
||||||
* summary: Get a specific region
|
* summary: Get a specific region by id
|
||||||
* tags: [Regions]
|
* tags: [Regions]
|
||||||
|
* parameters:
|
||||||
|
* - name: "id"
|
||||||
|
* in: "path"
|
||||||
|
* required: true
|
||||||
|
* type: int
|
||||||
* responses:
|
* responses:
|
||||||
* "200":
|
* "200":
|
||||||
* description: Returns the specific region and aviable data
|
* description: Returns aviable data for the region
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: ''
|
|
||||||
*/
|
*/
|
||||||
router.get("/api/v1/regions/:id", async (req, res) => {
|
router.get("/api/v1/regions/:id", async (req, res) => {
|
||||||
console.log(typeof req.params.id)
|
console.log(typeof req.params.id)
|
||||||
@ -68,41 +63,46 @@ module.exports = dbConn => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
* path:
|
* /regions/{id}/image:
|
||||||
* /regions/:id/image:
|
|
||||||
* get:
|
* get:
|
||||||
* summary: Get all country
|
* summary: Get image for specific region
|
||||||
* tags: [Regions]
|
* tags: [Regions]
|
||||||
|
* parameters:
|
||||||
|
* - name: "id"
|
||||||
|
* in: "path"
|
||||||
|
* required: true
|
||||||
|
* type: int
|
||||||
* responses:
|
* responses:
|
||||||
* "200":
|
* "200":
|
||||||
* description: Returns the image for a specific region
|
* description: Returns the image for a specific region
|
||||||
* content:
|
* "404":
|
||||||
* application/json:
|
* description: Returns a placeholder image for the region
|
||||||
* schema:
|
|
||||||
* $ref: ''
|
|
||||||
*/
|
*/
|
||||||
router.get('/api/v1/regions/:id/image', (req, res) => {
|
router.get('/api/v1/regions/:id/image', (req, res) => {
|
||||||
|
console.log("HERE")
|
||||||
if (fs.existsSync(path.join(__dirname, `../data/regions/images/${req.params.id}.jpg`))) {
|
if (fs.existsSync(path.join(__dirname, `../data/regions/images/${req.params.id}.jpg`))) {
|
||||||
res.sendFile(path.join(__dirname, `../data/regions/images/${req.params.id}.jpg`))
|
console.log("EXISTS")
|
||||||
|
res.status(200).sendFile(path.join(__dirname, `../data/regions/images/${req.params.id}.jpg`))
|
||||||
} else {
|
} else {
|
||||||
res.sendFile(path.join(__dirname, `../data/regions/images/x.png`))
|
console.log("NOT EXISTS")
|
||||||
|
res.status(404).sendFile(path.join(__dirname, `../data/regions/images/x.png`))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
* path:
|
* /regions/{id}/nearby:
|
||||||
* /regions/:id/nearby:
|
|
||||||
* get:
|
* get:
|
||||||
* summary: Get nearby places for a specific region
|
* summary: Get nearby places of a specific region by id
|
||||||
* tags: [Regions]
|
* tags: [Regions]
|
||||||
|
* parameters:
|
||||||
|
* - name: "id"
|
||||||
|
* in: "path"
|
||||||
|
* required: true
|
||||||
|
* type: int
|
||||||
* responses:
|
* responses:
|
||||||
* "200":
|
* "200":
|
||||||
* description: Returns nearby places for a specific region
|
* description: Returns all nearby places for the region
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: ''
|
|
||||||
*/
|
*/
|
||||||
router.get("/api/v1/regions/:id/nearby", async (req,res) => {
|
router.get("/api/v1/regions/:id/nearby", async (req,res) => {
|
||||||
const id = sqlSanitzer(req.params.id);
|
const id = sqlSanitzer(req.params.id);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user