Changed to better JSDoc Syntax

This commit is contained in:
Timo John 2020-07-02 15:49:17 +02:00
parent 4fa241ad60
commit 531f133875
8 changed files with 125 additions and 176 deletions

View File

@ -14,7 +14,6 @@ const port = process.env.PORT
const search = require("./routes/search");
const regions = require("./routes/regions");
const countries = require("./routes/countries");
const climate = require("./routes/climate");
const places = require("./routes/place");
const update = require("./routes/update");
@ -70,13 +69,12 @@ const swaggerDocs = swaggerJsdoc(swaggerOptions);
app.use(express.static(path.join(__dirname, "../../dist")));
app.use(bodyParser.json());
app.use(cors());
app.use('/api/v1/doc', swaggerUi.serve, swaggerUi.setup(swaggerDocs, {explorer: true}));
app.use('/api/v1/doc', swaggerUi.serve, swaggerUi.setup(swaggerDocs, {explorer: false, docExpansion: "list"}));
// Express routes
app.use(search(dbConn));
app.use(regions(dbConn));
app.use(countries(dbConn));
app.use(climate(dbConn));
app.use(places(dbConn));
app.use(update(dbConn))

View File

@ -1626,9 +1626,9 @@
}
},
"swagger-ui-dist": {
"version": "3.27.0",
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.27.0.tgz",
"integrity": "sha512-dlbH4L8+UslXVeYvCulicmJP2cnHLoabQGfeav5lx74fM+tMQW53M8iqpH5wbBqBbFkZwza+IIWoPrenqO/F2g=="
"version": "3.28.0",
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.28.0.tgz",
"integrity": "sha512-aPkfTzPv9djSiZI1NUkWr5HynCUsH+jaJ0WSx+/t19wq7MMGg9clHm9nGoIpAtqml1G51ofI+I75Ym72pukzFg=="
},
"swagger-ui-express": {
"version": "4.1.4",

View File

@ -1,49 +0,0 @@
/**
* @swagger
* tags:
* name: Climate
* description: Climate data acquiration
*/
const router = require("express").Router()
// Models
const handleClimateUpdate = require("../models/handleClimateUpdate.js")
const handleClimateUpdateV2 = require("../models/handleClimateUpdateV2.js")
module.exports = dbConn => {
/**
* @swagger
* path:
* /climate/update:
* patch:
* summary: Pull monthly data from meteostat API V1
* tags: [Climate]
* responses:
* "200":
* description: Update information is logged in backend
*/
router.patch("/api/v1/climate/update", async (req, res) => {
const update = await handleClimateUpdate(dbConn)
res.json(update)
});
/**
* @swagger
* path:
* /climate/update/v2:
* patch:
* summary: Pull daily data from meteostat API V2
* tags: [Climate]
* responses:
* "200":
* description: Update information is logged in backend
*/
router.patch("/api/v1/climate/update/v2", async (req, res) => {
const update = await handleClimateUpdateV2(dbConn)
res.json(update)
});
return router;
};

View File

@ -2,7 +2,7 @@
* @swagger
* tags:
* name: Countries
* description: Access country data
* description: Access country data.
*/
const router = require("express").Router();
@ -40,9 +40,11 @@ module.exports = dbConn => {
* in: "path"
* required: true
* type: int
* example: 23
* responses:
* "200":
* description: Returns aviable data for the country
* example: test
*/
router.get("/api/v1/countries/:id", async (req, res) => {
const id = sqlSanitzer(req.params.id);

View File

@ -2,7 +2,7 @@
* @swagger
* tags:
* name: Places
* description: Access to the Google Place API
* description: Access to the Google Place API via the Key used in backend. Only for manual use in the prototype application!
*/
const router = require("express").Router()
@ -28,6 +28,7 @@ module.exports = dbConn => {
* required: true
* type: int
* description: "Querystring, by which the place is searched"
* example: Berlin
* responses:
* "200":
* description: Returns a place from the google places API.
@ -49,11 +50,13 @@ module.exports = dbConn => {
* required: true
* type: float
* description: "Latitiude"
* example: 52.520365
* - name: "lng"
* in: "query"
* required: true
* type: float
* description: "Longitude"
* example: 13.403509
* responses:
* "200":
* description: Returns nearby places from the google places API.
@ -65,21 +68,6 @@ module.exports = dbConn => {
res.json(place)
});
/**
* @swagger
* path:
* /place/photo:
* get:
* summary: Get a photo for a place
* tags: [Places]
* responses:
* "200":
* description: Returns the matching photo for a photo_reference.
* content:
* application/json:
* schema:
* $ref: ''
*/
/**
* @swagger
* /place/photo:
@ -92,9 +80,10 @@ module.exports = dbConn => {
* required: true
* type: int
* description: "Photo_Reference which is returned for a place by Google Places API"
* example: CmRaAAAAbupojmH94negtiCnLGdfx2azxhVTEDI1rtTrYnQ7KclEI-Yy9_YGxN9h63AKrCzd22kk5z-UiK7fS4-zXnO5OqfNRZu2hrmfcp8b77rItediibAVovOOA5LnyJ9YYuofEhAAr0Im0zuiAtbDKPjbPUSBGhTFkSrH6FZxenbo1bCkdCXaUMhOug
* responses:
* "200":
* description: Returns the matching photo for a photo_reference.
* description: Returns the matching url to the photo.
*/
router.get("/api/v1/place/photo", async (req, res) => {
const photoref = req.query.photoref

View File

@ -2,7 +2,7 @@
* @swagger
* tags:
* name: Regions
* description: Access region data
* description: Access region data.
*/
const router = require("express").Router();
@ -27,7 +27,7 @@ module.exports = dbConn => {
* tags: [Regions]
* responses:
* "200":
* description: Returns aviable data for all regions
* description: Returns available data for all regions
*/
router.get("/api/v1/regions", async (req, res) => {
const data = await getRegions(dbConn)
@ -52,7 +52,7 @@ module.exports = dbConn => {
* type: int
* responses:
* "200":
* description: Returns aviable data for the region
* description: Returns available data for the region
*/
router.get("/api/v1/regions/:id", async (req, res) => {
console.log(typeof req.params.id)

View File

@ -2,7 +2,7 @@
* @swagger
* tags:
* name: Search
* description: Access the information for the search
* description: Access the search algorithm and the data provided for searching.
*/
const router = require("express").Router();
@ -21,52 +21,44 @@ const { getUniqueTags } = require("../models/getTags.js");
module.exports = dbConn => {
/**
* @swagger
* path:
* /search:
* get:
* summary: Get Searchresults
* tags: [Search]
* responses:
* "200":
* description: Returns the region information and scores for the searchresults
* content:
* application/json:
* schema:
* $ref: ''
* /search:
* get:
* summary: Get Searchresults
* tags: [Search]
* parameters:
* - name: "q"
* in: "query"
* required: true
* type: int
* description: "Base64 encoded JS-Object with searchparameters"
* example: eyJmcm9tIjoxNTkzNjQ4MDAwMDAwLCJ0byI6MTU5NDI1MjgwMDAwMCwidGFncyI6W119
* responses:
* "200":
* description: Returns the region information and scores for the searchresults
*/
router.get("/api/v1/search", searchHandler(dbConn));
/**
* @swagger
* path:
* /search/presets:
* get:
* summary: Get the presets for the search parameters
* tags: [Search]
* responses:
* "200":
* description: Returns all presets for the search parameters
* content:
* application/json:
* schema:
* $ref: ''
* /search/presets:
* get:
* summary: Get the presets for the search parameters
* tags: [Search]
* responses:
* "200":
* description: Returns all presets for the search parameters
*/
router.get("/api/v1/search/presets", presetHandler(dbConn));
/**
* @swagger
* path:
* /search/tags:
* get:
* summary: Get the existing searchtags
* tags: [Search]
* responses:
* "200":
* description: Returns all existing searchtags
* content:
* application/json:
* schema:
* $ref: ''
* /search/tags:
* get:
* summary: Get the existing searchtags
* tags: [Search]
* responses:
* "200":
* description: Returns all existing searchtags
*/
router.get("/api/v1/search/tags", tagsHandler(dbConn));

View File

@ -2,12 +2,14 @@
* @swagger
* tags:
* name: Update
* description: Endpoint for updating region specific data
* description: Endpoint for updating region specific data. Only for manual use in the prototype application!
*/
const router = require("express").Router();
// Models
const handleClimateUpdate = require("../models/handleClimateUpdate.js")
const handleClimateUpdateV2 = require("../models/handleClimateUpdateV2.js")
const handleUpdateRegionNearby = require("../models/handleUpdateRegionNearby.js")
const handleUpdateRegionNearbyById = require("../models/handleUpdateRegionNearbyById.js")
const handleUpdateRegionNearbyImgUrl = require("../models/handleUpdateRegionNearbyImgUrl.js")
@ -19,18 +21,43 @@ const sqlSanitzer = require("../util/sqlstring_sanitizer.js")
module.exports = dbConn => {
/**
* @swagger
* path:
* /update/regions/all/nearby:
* patch:
* summary: Updates all nearby data for all regions
* tags: [Update]
* responses:
* "200":
* description: Updates all nearby data for all regions
* content:
* application/json:
* schema:
* $ref: ''
* /update/climate/v1:
* patch:
* summary: Pull monthly data from meteostat API V2
* tags: [Update]
* responses:
* "200":
* description: Update information is logged in backend
*/
router.patch("/api/v1/update/climate/v1", async (req, res) => {
const update = await handleClimateUpdate(dbConn)
res.json(update)
});
/**
* @swagger
* /update/climate/v2:
* patch:
* summary: Pull daily data from meteostat API V2
* tags: [Update]
* responses:
* "200":
* description: Update information is logged in backend
*/
router.patch("/api/v1/update/climate/v2", async (req, res) => {
const update = await handleClimateUpdateV2(dbConn)
res.json(update)
});
/**
* @swagger
* /update/regions/all/nearby:
* patch:
* summary: Updates all nearby data for all regions
* tags: [Update]
* responses:
* "200":
* description: Updates all nearby data for all regions
*/
router.patch("/api/v1/update/regions/all/nearby", async (req, res) => {
res.json(await handleUpdateRegionNearby(dbConn))
@ -38,18 +65,13 @@ module.exports = dbConn => {
/**
* @swagger
* path:
* /update/regions/all/lonlat:
* patch:
* summary: Updates all coordinate data for all regions
* tags: [Update]
* responses:
* "200":
* description: Updates all coordinate data for all regions
* content:
* application/json:
* schema:
* $ref: ''
* /update/regions/all/lonlat:
* patch:
* summary: Updates all coordinate data for all regions
* tags: [Update]
* responses:
* "200":
* description: Updates all coordinate data for all regions
*/
router.patch("/api/v1/update/regions/all/lonlat", async (req,res) => {
res.json(await handleRegionLonLat(dbConn))
@ -57,37 +79,32 @@ module.exports = dbConn => {
/**
* @swagger
* path:
* /update/regions/all/nearby/imgurl:
* patch:
* summary: Updates the nearby imgurls for all regions
* tags: [Update]
* responses:
* "200":
* description: Updates the nearby imgurls for all regions
* content:
* application/json:
* schema:
* $ref: ''
* /update/regions/all/nearby/image:
* patch:
* summary: Updates the nearby image urls for all regions
* tags: [Update]
* responses:
* "200":
* description: Updates the nearby image urls for all regions
*/
router.patch("/api/v1/update/regions/all/nearby/imgurl", async (req, res) => {
router.patch("/api/v1/update/regions/all/nearby/image", async (req, res) => {
res.json(await handleUpdateRegionNearbyImgUrl(dbConn))
});
/**
* @swagger
* path:
* /update/regions/:id/nearby:
* patch:
* summary: Updates the nearby data for a specific region
* tags: [Update]
* responses:
* "200":
* description: Updates the nearby data for a specific region
* content:
* application/json:
* schema:
* $ref: ''
* /update/regions/{id}/nearby:
* patch:
* summary: Updates the nearby data for a specific region
* tags: [Update]
* parameters:
* - name: "id"
* in: "path"
* required: true
* type: int
* responses:
* "200":
* description: Updates the nearby data for a specific region
*/
router.patch("/api/v1/update/regions/:id/nearby", async (req, res) => {
const id = sqlSanitzer(req.params.id);
@ -96,20 +113,20 @@ module.exports = dbConn => {
/**
* @swagger
* path:
* /update/regions/:id/nearby/imgurl:
* patch:
* summary: Updates the nearby imgurls for a specific region
* tags: [Update]
* responses:
* "200":
* description: Updates the nearby imgurls for a specific region
* content:
* application/json:
* schema:
* $ref: ''
* /update/regions/{id}/nearby/image:
* patch:
* summary: Updates the nearby image urls for a specific region
* tags: [Update]
* parameters:
* - name: "id"
* in: "path"
* required: true
* type: int
* responses:
* "200":
* description: Updates the nearby image urls for a specific region
*/
router.patch("/api/v1/update/regions/:id/nearby/imgurl", async (req, res) => {
router.patch("/api/v1/update/regions/:id/nearby/image", async (req, res) => {
const id = sqlSanitzer(req.params.id);
res.json(await handleUpdateRegionNearbyImgUrlById(dbConn, id))
});