diff --git a/controllers/serviceController.js b/controllers/serviceController.js index fd820cc..fca3cea 100644 --- a/controllers/serviceController.js +++ b/controllers/serviceController.js @@ -1,8 +1,24 @@ const transformer = require("../helpers/transformer") -const fs = require('fs'); +const fs = require("fs"); + exports.addService = async (params) => { return await transformer.makeService(params); } - -exports.postCodeSearch = async (params) => { +exports.postCodeSearch = (params) => { + return new Promise((resolve, reject) => { + fs.readdir(__dirname + "/../files/", (err, files) => { + if(err) reject() + fs.readdir(__dirname + `/../files/${params.postcode}/gebouwen/`, (err, files) => { + if(err) reject("Geen gebouwen gevonden voor psotcode"); + let response = {} + files.forEach(file => { + fs.readFile(__dirname + `/../files/${params.postcode}/gebouwen/${file}`, (err, data) => { + if(err) reject("Problemen bij het openen van gebouwfile"); + response.push(JSON.parse(data)); + }) + }) + resolve(response); + }) + }) + }) } \ No newline at end of file diff --git a/files/service-example.json b/files/service-example.json index cc0bed7..3c541d5 100644 --- a/files/service-example.json +++ b/files/service-example.json @@ -1,5 +1,5 @@ [{ - "@context": "http://schema.org/", + "@context": "https://schema.org/", "@id": "https://stad.gent/id/products/123", "@type": "Service", "name": "Public toilet library", diff --git a/helpers/transformer.js b/helpers/transformer.js index d53da5b..54d7360 100644 --- a/helpers/transformer.js +++ b/helpers/transformer.js @@ -164,7 +164,7 @@ function jsonLDBuilding(gebouwId, adresId, location) { "xsd": "http://www.w3.org/2001/XMLSchema#" }, "@id": "gebouw:" + gebouwId, - "type": "gebouw:Gebouw", + "@type": "gebouw:Gebouw", "gebouw:Gebouw.adres": { "@id": "http://data.vlaanderen.be/id/adres/" + adresId, "@type": "http://www.w3.org/ns/locn#Address", diff --git a/routes.js b/routes.js index d757cd8..26333b5 100644 --- a/routes.js +++ b/routes.js @@ -74,7 +74,14 @@ router.get('/postcode', async (req, res, next) => { }); router.post('/service/postcode', async (req, res, next) => { - await serviceController + try { + res.status(200) + var response = await serviceController.postCodeSearch(req.body); + } catch (error) { + res.status(304) + var response = error.message; + } + res.send(response); }) router.post('/services', async (req, res, next) => { try {