feat: initial setup backend with default routes and db connection
This commit is contained in:
74
server/src/controller/ttnGatewayReceptionController.ts
Normal file
74
server/src/controller/ttnGatewayReceptionController.ts
Normal file
@ -0,0 +1,74 @@
|
||||
import express, { Request, Response } from "express";
|
||||
import { TtnGatewayReceptionService } from "../services/ttnGatewayReceptionService";
|
||||
import { container } from "tsyringe";
|
||||
|
||||
const ttnGatewayReceptionService = container.resolve(
|
||||
TtnGatewayReceptionService
|
||||
);
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const gatewayReceptions =
|
||||
await ttnGatewayReceptionService.getAllGatewayReceptions();
|
||||
res.status(200).json(gatewayReceptions);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Error retrieving gateway receptions" });
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/:id", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const gatewayReception =
|
||||
await ttnGatewayReceptionService.getGatewayReceptionById(id);
|
||||
if (!gatewayReception) {
|
||||
res.status(404).json({ error: "Gateway reception not found" });
|
||||
return;
|
||||
}
|
||||
res.status(200).json(gatewayReception);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Error retrieving gateway reception" });
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const newGatewayReception =
|
||||
await ttnGatewayReceptionService.createGatewayReception(req.body);
|
||||
res.status(201).json(newGatewayReception);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Error creating gateway reception" });
|
||||
}
|
||||
});
|
||||
|
||||
router.put("/:id", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const updatedGatewayReception =
|
||||
await ttnGatewayReceptionService.updateGatewayReception(id, req.body);
|
||||
if (!updatedGatewayReception) {
|
||||
res.status(404).json({ error: "Gateway reception not found" });
|
||||
return;
|
||||
}
|
||||
res.status(200).json(updatedGatewayReception);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Error updating gateway reception" });
|
||||
}
|
||||
});
|
||||
|
||||
router.delete("/:id", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const deleted = await ttnGatewayReceptionService.deleteGatewayReception(id);
|
||||
if (!deleted) {
|
||||
res.status(404).json({ error: "Gateway reception not found" });
|
||||
return;
|
||||
}
|
||||
res.status(204).send();
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Error deleting gateway reception" });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
Reference in New Issue
Block a user