-
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.
feat(Coordinate): New API End-Point. Controller and Router
- Loading branch information
1 parent
c50a16e
commit 7215786
Showing
2 changed files
with
47 additions
and
0 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
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,45 @@ | ||
import { Router, Request, Response } from "express"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
import * as coordController from "../controllers/coordinate.controller"; | ||
|
||
interface Coordinate { | ||
id: string; | ||
createdAt: string; | ||
lat: number; | ||
lng: number; | ||
} | ||
|
||
const coordRouter = Router(); | ||
|
||
coordRouter.get("/", async (req: Request, res: Response) => { | ||
try { | ||
const data = await coordController.getCoordinates(); | ||
res.status(200).send(data); | ||
} catch (error) { | ||
res.status(500).send(error); | ||
} | ||
}); | ||
|
||
coordRouter.post("/", async (req: Request, res: Response) => { | ||
try { | ||
const Cord = req.body; | ||
Cord.id = uuidv4(); | ||
Cord.createdAt = new Date().toISOString(); | ||
const data = await coordController.createCoordinate(Cord); | ||
res.status(200).send(data); | ||
} catch (error) { | ||
res.status(500).send(error); | ||
} | ||
}); | ||
|
||
coordRouter.delete("/:id", async (req: Request, res: Response) => { | ||
try { | ||
const id = req.params.id; | ||
const data = await coordController.deleteCoordinate(id); | ||
res.status(200).send(data); | ||
} catch (error) { | ||
res.status(500).send(error); | ||
} | ||
}); | ||
|
||
export default coordRouter; |