restructured - added data and inventory routes/controllers
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
// controllers/itemLookup.js
|
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import fetchEbayToken from "../utils/fetchEbayToken.js"; // Adjust the import path according to your project structure
|
import fetchEbayToken from "../utils/fetchEbayToken.js"; // Adjust the import path according to your project structure
|
||||||
|
|
||||||
const itemLookup = async (req, res) => {
|
export const itemLookup = async (req, res) => {
|
||||||
const productCode = req.body.productCode;
|
const productCode = req.query.productCode;
|
||||||
const oauthToken = await fetchEbayToken();
|
const oauthToken = await fetchEbayToken();
|
||||||
console.log(productCode);
|
console.log(productCode);
|
||||||
try {
|
try {
|
||||||
@@ -22,15 +21,14 @@ const itemLookup = async (req, res) => {
|
|||||||
throw new Error("Failed to fetch data from eBay Browse API");
|
throw new Error("Failed to fetch data from eBay Browse API");
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
const price = [];
|
||||||
data.itemSummaries.forEach((item) => {
|
data.itemSummaries.forEach((item) => {
|
||||||
console.log(item.price, item.condition);
|
price.push(item.price, item.condition);
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200).send("Data fetched successfully");
|
res.status(200).send(price);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching data from eBay Browse API:", error);
|
console.error("Error fetching data from eBay Browse API:", error);
|
||||||
res.status(500).send("Internal Server Error");
|
res.status(500).send("Internal Server Error");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default itemLookup;
|
|
||||||
0
api/controllers/inventoryController.js
Normal file
0
api/controllers/inventoryController.js
Normal file
12
api/routes/dataRoutes.js
Normal file
12
api/routes/dataRoutes.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// routes/dataRoutes.js
|
||||||
|
import express from "express";
|
||||||
|
import { itemLookup } from "../controllers/dataController.js"; // Adjust the import path according to your project structure
|
||||||
|
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
// Use the itemLookup function from dataController for the GET request to '/item-lookup'
|
||||||
|
router.get("/item-lookup", itemLookup);
|
||||||
|
|
||||||
|
// You can add more data-related routes here in the future
|
||||||
|
|
||||||
|
export default router;
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
// routes/itemLookup.js
|
|
||||||
import express from "express";
|
|
||||||
import itemLookup from "../controllers/itemLookup.js";
|
|
||||||
|
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
// Use the itemLookup controller for the POST request to '/item-lookup'
|
|
||||||
router.post("/item-lookup", itemLookup);
|
|
||||||
|
|
||||||
export default router;
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import itemLookupRoute from "./routes/itemLookup.js"; // Named after the route file
|
import dataRoutes from "./routes/dataRoutes.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ app.use(cors());
|
|||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
// Use the itemLookupRoute with a base path, e.g., '/api'
|
// Use the itemLookupRoute with a base path, e.g., '/api'
|
||||||
app.use("/api", itemLookupRoute);
|
app.use("/api/data", dataRoutes);
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
|
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
|
||||||
|
|||||||
Reference in New Issue
Block a user