Skip to content

Commit

Permalink
feat(api): added post func to add new ATM and get for searching ATMs
Browse files Browse the repository at this point in the history
  • Loading branch information
FinnbarHome committed Jan 23, 2024
1 parent 6825ddd commit d347a0b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions api/api_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ app.delete("/api/atms/:id", async (req, res) => {
}
});

// POST a new ATM
app.post("/api/atms", async (req, res) => {
try {
const newAtm = await db.collection("ATMs").insertOne(req.body);
console.log(newAtm);
res.status(201).json(newAtm);
} catch (error) {
res.status(500).json({ error: error.message });
}
});

// GET ATMs with search functionality
app.get("/api/atms/search", async (req, res) => {
try {
const query = {}; // Construct query based on req.query parameters
// Example: if (req.query.location) query['Location.TownName'] = req.query.location;
const atms = await db.collection("ATMs").find(query).toArray();
res.json(atms);
} catch (error) {
res.status(500).json({ error: error.message });
}
});


// BRANCH ENDPOINTS

Expand Down

0 comments on commit d347a0b

Please sign in to comment.