second commit
This commit is contained in:
parent
37baf861d3
commit
b2401c4354
18
index.js
18
index.js
|
|
@ -10,7 +10,7 @@ app.use(bodyParser.json());
|
||||||
// In-memory data store for demonstration
|
// In-memory data store for demonstration
|
||||||
let cartData = {
|
let cartData = {
|
||||||
cart: {
|
cart: {
|
||||||
accessoreis: {},
|
accessories: {},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -46,10 +46,10 @@ app.get("/cart", (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// READ - Get a specific item in the cart
|
// READ - Get a specific item in the cart
|
||||||
app.get("/cart/accessoreis/:key", (req, res) => {
|
app.get("/cart/accessories/:key", (req, res) => {
|
||||||
const { key } = req.params;
|
const { key } = req.params;
|
||||||
|
|
||||||
const item = cartData.cart.accessoreis[key];
|
const item = cartData.cart.accessories[key];
|
||||||
|
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return res.status(404).json({ error: `Item with key '${key}' not found` });
|
return res.status(404).json({ error: `Item with key '${key}' not found` });
|
||||||
|
|
@ -62,7 +62,7 @@ app.get("/cart/accessoreis/:key", (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// UPDATE - Update a specific item in the cart
|
// UPDATE - Update a specific item in the cart
|
||||||
app.put("/cart/accessoreis/:key", (req, res) => {
|
app.put("/cart/accessories/:key", (req, res) => {
|
||||||
const { key } = req.params;
|
const { key } = req.params;
|
||||||
const { value } = req.body;
|
const { value } = req.body;
|
||||||
|
|
||||||
|
|
@ -70,12 +70,12 @@ app.put("/cart/accessoreis/:key", (req, res) => {
|
||||||
return res.status(400).json({ error: "Value is required" });
|
return res.status(400).json({ error: "Value is required" });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cartData.cart.accessoreis[key]) {
|
if (!cartData.cart.accessories[key]) {
|
||||||
return res.status(404).json({ error: `Item with key '${key}' not found` });
|
return res.status(404).json({ error: `Item with key '${key}' not found` });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the item
|
// Update the item
|
||||||
cartData.cart.accessoreis[key] = value;
|
cartData.cart.accessories[key] = value;
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
message: "Item updated successfully",
|
message: "Item updated successfully",
|
||||||
|
|
@ -84,15 +84,15 @@ app.put("/cart/accessoreis/:key", (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// DELETE - Remove a specific item from the cart
|
// DELETE - Remove a specific item from the cart
|
||||||
app.delete("/cart/accessoreis/:key", (req, res) => {
|
app.delete("/cart/accessories/:key", (req, res) => {
|
||||||
const { key } = req.params;
|
const { key } = req.params;
|
||||||
|
|
||||||
if (!cartData.cart.accessoreis[key]) {
|
if (!cartData.cart.accessories[key]) {
|
||||||
return res.status(404).json({ error: `Item with key '${key}' not found` });
|
return res.status(404).json({ error: `Item with key '${key}' not found` });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the item
|
// Delete the item
|
||||||
delete cartData.cart.accessoreis[key];
|
delete cartData.cart.accessories[key];
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
message: "Item deleted successfully",
|
message: "Item deleted successfully",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user