From 8cb958eb29f67e878cb1bd1595fd6995c951cf65 Mon Sep 17 00:00:00 2001 From: Jake Meyer Date: Thu, 30 Nov 2017 04:45:37 -0600 Subject: [PATCH] officially removed v1 endpoints --- app.js | 16 ----- v1-routes/v1-home.js | 16 ----- v1-routes/v1-info.js | 16 ----- v1-routes/v1-launches.js | 148 -------------------------------------- v1-routes/v1-launchpad.js | 26 ------- v1-routes/v1-parts.js | 61 ---------------- v1-routes/v1-upcoming.js | 33 --------- v1-routes/v1-vehicles.js | 56 --------------- 8 files changed, 372 deletions(-) delete mode 100644 v1-routes/v1-home.js delete mode 100644 v1-routes/v1-info.js delete mode 100644 v1-routes/v1-launches.js delete mode 100644 v1-routes/v1-launchpad.js delete mode 100644 v1-routes/v1-parts.js delete mode 100644 v1-routes/v1-upcoming.js delete mode 100644 v1-routes/v1-vehicles.js diff --git a/app.js b/app.js index bf19deb9..f3624034 100644 --- a/app.js +++ b/app.js @@ -8,14 +8,6 @@ const config = require("./config.json") const MongoClient = require("mongodb") const app = express() -const home = require("./v1-routes/v1-home") -const info = require("./v1-routes/v1-info") -const vehicles = require("./v1-routes/v1-vehicles") -const launchpad = require("./v1-routes/v1-launchpad") -const launches = require("./v1-routes/v1-launches") -const upcoming = require("./v1-routes/v1-upcoming") -const parts = require("./v1-routes/v1-parts") - const v2_home = require("./v2-routes/v2-home") const v2_info = require("./v2-routes/v2-info") const v2_vehicles = require("./v2-routes/v2-vehicles") @@ -36,14 +28,6 @@ app.use((req, res, next) => { next() }) -app.use("/v1", home) -app.use("/v1/info", info) -app.use("/v1/vehicles", vehicles) -app.use("/v1/launchpads", launchpad) -app.use("/v1/launches", launches) -app.use("/v1/launches/upcoming", upcoming) -app.use("/v1/parts", parts) - app.use("/v2", v2_home) app.use("/v2/info", v2_info) app.use("/v2/vehicles", v2_vehicles) diff --git a/v1-routes/v1-home.js b/v1-routes/v1-home.js deleted file mode 100644 index e11d60ec..00000000 --- a/v1-routes/v1-home.js +++ /dev/null @@ -1,16 +0,0 @@ -// Home Info Endpoint - -const express = require("express") -const v1 = express.Router() - -// Returns API Info -v1.get("/", (req, res, next) => { - global.db.collection("home").find({},{"_id": 0 }).toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc[0]) - }) -}) - -module.exports = v1 diff --git a/v1-routes/v1-info.js b/v1-routes/v1-info.js deleted file mode 100644 index 0c7a74a7..00000000 --- a/v1-routes/v1-info.js +++ /dev/null @@ -1,16 +0,0 @@ -// Basic Info Endpoints - -const express = require("express") -const v1 = express.Router() - -// Returns company info -v1.get("/", (req, res, next) => { - global.db.collection("info").find({},{"_id": 0 }).toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc[0]) - }) -}) - -module.exports = v1 diff --git a/v1-routes/v1-launches.js b/v1-routes/v1-launches.js deleted file mode 100644 index 7a9aca09..00000000 --- a/v1-routes/v1-launches.js +++ /dev/null @@ -1,148 +0,0 @@ -// Launches Endpoints - -const express = require("express") -const v1 = express.Router() -const error = {error: "No results found"} - -// Get most recent launch -v1.get("/latest", (req, res, next) => { - global.db.collection("launch").find({},{"_id": 0 }).sort({"flight_number": -1}).limit(1) - .toArray((err, doc) => { - if (err) { - return next(err) - } - if (doc.length == 0) { - res.status(404) - return res.json(error) - } - res.json(doc[0]) - }) -}) - -// All launches by date, year, or default to all launches -v1.get("/", (req, res, next) => { - const year = req.query.year - const start = req.query.start - const final = req.query.final - const site = req.query.site - if (year) { - global.db.collection("launch").find({"launch_year": `${year}`}, {"_id": 0 }).sort({"flight_number": -1}) - .toArray((err, doc) => { - res.json(doc) - }) - } else if (start && final) { - global.db.collection("launch").find({ "launch_date_utc": {"$gte": `${start}T00:00:00Z`, "$lte": `${final}T00:00:00Z`}}, {"_id": 0 }) - .sort({"flight_number": 1}) - .toArray((err, doc) => { - res.json(doc) - }) - } else if (site) { - global.db.collection("launch").find({ "launch_site.site_id": `${site}`}, {"_id": 0 }) - .sort({"flight_number": 1}) - .toArray((err, doc) => { - res.json(doc) - }) - } else { - global.db.collection("launch").find({},{"_id": 0 }).sort({"flight_number": 1}) - .toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc) - }) - } -}) - -// Returns launches by core serial # -v1.get("/cores/:core", (req, res, next) => { - const core = req.params.core - const year = req.query.year - const start = req.query.start - const final = req.query.final - const site = req.query.site - if (year && core) { - global.db.collection("launch").find({"core_serial": `${core}`, "launch_year": `${year}`}, {"_id": 0 }).sort({"flight_number": -1}) - .toArray((err, doc) => { - res.json(doc) - }) - } else if (start && final && core) { - global.db.collection("launch").find({ "core_serial": `${core}`, "launch_date_utc": {"$gte": `${start}T00:00:00Z`, "$lte": `${final}T00:00:00Z`}}, {"_id": 0 }) - .sort({"flight_number": 1}) - .toArray((err, doc) => { - res.json(doc) - }) - } else if (site && core) { - global.db.collection("launch").find({ "core_serial": `${core}`, "launch_site.site_id": `${site}`}, {"_id": 0 }) - .sort({"flight_number": 1}) - .toArray((err, doc) => { - res.json(doc) - }) - } else if (core) { - global.db.collection("launch").find({"core_serial": `${core}`},{"_id": 0}).sort({"core_serial": 1}) - .toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc) - }) - } -}) - -// Returns launches by capsule serial # -v1.get("/caps/:cap", (req, res, next) => { - const cap = req.params.cap - const year = req.query.year - const start = req.query.start - const final = req.query.final - const site = req.query.site - if (year && cap) { - global.db.collection("launch").find({"cap_serial": `${cap}`, "launch_year": `${year}`}, {"_id": 0 }).sort({"flight_number": -1}) - .toArray((err, doc) => { - res.json(doc) - }) - } else if (start && final && cap) { - global.db.collection("launch").find({ "cap_serial": `${cap}`, "launch_date_utc": {"$gte": `${start}T00:00:00Z`, "$lte": `${final}T00:00:00Z`}}, {"_id": 0 }) - .sort({"flight_number": 1}) - .toArray((err, doc) => { - res.json(doc) - }) - } else if (site && cap) { - global.db.collection("launch").find({ "cap_serial": `${cap}`, "launch_site.site_id": `${site}`}, {"_id": 0 }) - .sort({"flight_number": 1}) - .toArray((err, doc) => { - res.json(doc) - }) - } else { - global.db.collection("launch").find({"cap_serial": `${cap}`},{"_id": 0}).sort({"capsule_serial": 1}) - .toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc) - }) - } -}) - -// Returns all ASDS launches -v1.get("/asds", (req, res, next) => { - global.db.collection("launch").find({"landing_type": "ASDS"},{"_id": 0}).sort({"flight_number": 1}) - .toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc) - }) -}) - -// Returns all RTLS launches -v1.get("/rtls", (req, res, next) => { - global.db.collection("launch").find({"landing_type": "RTLS"},{"_id": 0}).sort({"flight_number": 1}) - .toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc) - }) -}) - -module.exports = v1 diff --git a/v1-routes/v1-launchpad.js b/v1-routes/v1-launchpad.js deleted file mode 100644 index 9e3307a4..00000000 --- a/v1-routes/v1-launchpad.js +++ /dev/null @@ -1,26 +0,0 @@ -// Launchpad Endpoints - -const express = require("express") -const v1 = express.Router() -const error = {error: "No results found"} - -// Get all launchpads -v1.get("/", (req, res) => { - global.db.collection("launchpad").find({},{"_id": 0 }).toArray((err, doc) => { - res.json(doc) - }) -}) - -// Return all launchpads -v1.get("/:pad", (req, res) => { - const id = req.params.pad - global.db.collection("launchpad").find({"id": `${id}`}, {"_id": 0 }).toArray((err, doc) => { - if (doc.length == 0) { - res.status(404) - return res.json(error) - } - res.json(doc[0]) - }) -}) - -module.exports = v1 diff --git a/v1-routes/v1-parts.js b/v1-routes/v1-parts.js deleted file mode 100644 index 01bb3a78..00000000 --- a/v1-routes/v1-parts.js +++ /dev/null @@ -1,61 +0,0 @@ -// Parts Endpoints - -const express = require("express") -const v1 = express.Router() -const error = {error: "No results found"} - -// Returns all capsule information -v1.get("/caps", (req, res, next) => { - global.db.collection("capsule").find({},{"_id": 0}).sort({"capsule_serial": 1}) - .toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc) - }) -}) - -// Returns capsule info by serial # -v1.get("/caps/:cap", (req, res, next) => { - const cap = req.params.cap - global.db.collection("capsule").find({"capsule_serial": `${cap}`},{"_id": 0}).sort({"capsule_serial": 1}) - .toArray((err, doc) => { - if (err) { - return next(err) - } - if (doc.length == 0) { - res.status(404) - return res.json(error) - } - res.json(doc[0]) - }) -}) - -// Returns all core information -v1.get("/cores", (req, res, next) => { - global.db.collection("core").find({},{"_id": 0}).sort({"core_serial": 1}) - .toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc) - }) -}) - -// Returns core info by serial # -v1.get("/cores/:core", (req, res, next) => { - const core = req.params.core - global.db.collection("core").find({"core_serial": `${core}`},{"_id": 0}).sort({"core_serial": 1}) - .toArray((err, doc) => { - if (err) { - return next(err) - } - if (doc.length == 0) { - res.status(404) - return res.json(error) - } - res.json(doc[0]) - }) -}) - -module.exports = v1 diff --git a/v1-routes/v1-upcoming.js b/v1-routes/v1-upcoming.js deleted file mode 100644 index 82a98482..00000000 --- a/v1-routes/v1-upcoming.js +++ /dev/null @@ -1,33 +0,0 @@ -// Upcoming Endpoints - -const express = require("express") -const v1 = express.Router() - -// Upcoming launches by date, year, or all -v1.get("/", (req, res, next) => { - const year = req.query.year - const start = req.query.start - const final = req.query.final - if (year) { - global.db.collection("upcoming").find({"launch_year": `${year}`}, {"_id": 0 }).sort({"flight_number": -1}) - .toArray((err, doc) => { - res.json(doc) - }) - } else if (start && final) { - global.db.collection("upcoming").find({ "launch_date_utc": {"$gte": `${start}T00:00:00Z`, "$lte": `${final}T00:00:00Z`}}, {"_id": 0 }) - .sort({"flight_number": 1}) - .toArray((err, doc) => { - res.json(doc) - }) - } else { - global.db.collection("upcoming").find({},{"_id": 0 }).sort({"flight_number": 1}) - .toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc) - }) - } -}) - -module.exports = v1 diff --git a/v1-routes/v1-vehicles.js b/v1-routes/v1-vehicles.js deleted file mode 100644 index 65daf38c..00000000 --- a/v1-routes/v1-vehicles.js +++ /dev/null @@ -1,56 +0,0 @@ -// Vehicle Endpoints - -const express = require("express") -const v1 = express.Router() - -// Returns all vehicle info -v1.get("/", (req, res, next) => { - global.db.collection("vehicle").find({},{"_id": 0 }).toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc) - }) -}) - -// Returns Falcon 1 info -v1.get("/falcon1", (req, res, next) => { - global.db.collection("vehicle").find({"id": "falcon1"},{"_id": 0 }).toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc[0]) - }) -}) - -// Returns Falcon 9 info -v1.get("/falcon9", (req, res, next) => { - global.db.collection("vehicle").find({"id": "falcon9"},{"_id": 0 }).toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc[0]) - }) -}) - -// Returns Falcon Heavy info -v1.get("/falconheavy", (req, res, next) => { - global.db.collection("vehicle").find({"id": "falcon_heavy"},{"_id": 0 }).toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc[0]) - }) -}) - -// Returns Dragon info -v1.get("/dragon", (req, res, next) => { - global.db.collection("vehicle").find({"id": "dragon"},{"_id": 0 }).toArray((err, doc) => { - if (err) { - return next(err) - } - res.json(doc[0]) - }) -}) - -module.exports = v1