-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
691 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
{ | ||
"name": "jadwal-adzan-api", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "src/index.js", | ||
"devDependencies": {}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"axios": "^1.3.4", | ||
"cheerio": "^1.0.0-rc.12", | ||
"dotenv": "^16.0.3" | ||
} | ||
"name": "jadwal-adzan-api", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "src/index.js", | ||
"devDependencies": { | ||
"nodemon": "^2.0.22" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "node src/index.js", | ||
"dev": "nodemon src/index.js" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"axios": "^1.3.4", | ||
"cheerio": "^1.0.0-rc.12", | ||
"cors": "^2.8.5", | ||
"dotenv": "^16.0.3", | ||
"express": "^4.18.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { data: cities } = require("../data/city.json"); | ||
|
||
class CityController { | ||
static getAllCity(req, res) { | ||
return res.status(200).send({ statusCode: 200, data: cities }); | ||
} | ||
|
||
static getCity(req, res) { | ||
let id = req.params.id; | ||
id = parseInt(id); | ||
|
||
const city = cities.find((item) => item.id === id); | ||
|
||
if (!city) { | ||
return res.status(400).send({ statusCode: 400, message: "City not found" }); | ||
} | ||
|
||
return res.status(200).send({ statusCode: 200, data: city }); | ||
} | ||
} | ||
|
||
module.exports = CityController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require("dotenv").config(); | ||
|
||
const express = require("express"); | ||
const cors = require("cors"); | ||
const routes = require("./routes"); | ||
|
||
const port = process.env.PORT || 3000; | ||
const server = express(); | ||
|
||
server.set("trust proxy", 1); | ||
server.use(cors()); | ||
server.use(express.json()); | ||
|
||
server.use(routes); | ||
|
||
server.listen(port, () => { | ||
console.log("Server running at port:", port); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { Router } = require("express"); | ||
const CityController = require("./controllers/city"); | ||
|
||
const router = Router(); | ||
|
||
router.get("/", (req, res) => { | ||
res.status(200).send({ message: "success" }); | ||
}); | ||
|
||
router.get("/city", CityController.getAllCity); | ||
router.get("/city/:id", CityController.getCity); | ||
|
||
module.exports = router; |
Oops, something went wrong.