]> git.giorgioravera.it Git - network-manager.git/commitdiff
Removed JSONResponse
authorGiorgio Ravera <giorgio.ravera@gmail.com>
Mon, 16 Mar 2026 20:38:37 +0000 (21:38 +0100)
committerGiorgio Ravera <giorgio.ravera@gmail.com>
Mon, 16 Mar 2026 20:38:37 +0000 (21:38 +0100)
backend/routes/aliases.py
backend/routes/backup.py
backend/routes/dhcp.py
backend/routes/dns.py
backend/routes/hosts.py
backend/routes/login.py

index b97da40ce326a2eb5418518c06d9d9f5c63ef7fa..66673facfd0a3a0e0941df31daccb348b55d3d8b 100644 (file)
@@ -2,7 +2,7 @@
 
 # import standard modules
 from fastapi import APIRouter, Request, Response, HTTPException, status
-from fastapi.responses import FileResponse, JSONResponse, RedirectResponse
+from fastapi.responses import FileResponse
 import ipaddress
 import time
 import os
@@ -122,16 +122,13 @@ def api_add_alias(request: Request, data: dict):
         alias_id = add_alias(data)
         if(alias_id > 0):
             took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
-            return JSONResponse(
-                status_code=status.HTTP_200_OK,
-                content={
+            return {
                     "code": "ALIAS_ADDED",
                     "status": "success",
                     "message": "Alias added successfully",
                     "alias_id": alias_id,
                     "took_ms": took_ms,
-                },
-            )
+                }
 
         # Already present
         took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
@@ -178,16 +175,13 @@ def api_update_alias(request: Request, data: dict, alias_id: int):
         updated = update_alias(alias_id, data)
         if updated:
             took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
-            return JSONResponse(
-                status_code=status.HTTP_200_OK,
-                content={
+            return {
                     "code": "ALIAS_UPDATED",
                     "status": "success",
                     "message": "Alias updated successfully",
                     "alias_id": alias_id,
                     "took_ms": took_ms,
-                },
-            )
+                }
 
         # Not Found
         took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
@@ -236,15 +230,12 @@ def api_delete_alias(request: Request, alias_id: int):
         deleted = delete_alias(alias_id)
         if deleted:
             took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
-            return JSONResponse(
-                status_code=status.HTTP_200_OK,
-                content={
+            return {
                     "code": "ALIAS_DELETED",
                     "status": "success",
                     "message": "Alias deleted successfully",
                     "details": {"took_ms": took_ms, "alias_id": alias_id,},
-                },
-            )
+                }
 
         # Not Found
         took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
index 794f852425020117d4bf35800b8f568f3ef3017e..e84b3379e6530350cd4b8be011b8cc6679ad3466 100644 (file)
@@ -2,7 +2,7 @@
 
 # import standard modules
 from fastapi import APIRouter, Request, Response, HTTPException, status
-from fastapi.responses import FileResponse, JSONResponse, RedirectResponse
+from fastapi.responses import FileResponse
 import asyncio
 import json
 import os
@@ -69,15 +69,12 @@ async def api_backup(request: Request):
         save_aliases()
 
         took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
-        return JSONResponse(
-            status_code=status.HTTP_200_OK,
-            content={
+        return {
                 "code": "BACKUP_OK",
                 "status": "success",
                 "message": "BACKUP executed successfully",
                 "took_ms": took_ms,
-            },
-        )
+            }
 
     except HTTPException:
         raise
index df1c4178ff66d65c057849a6c1fffe2369c95619..a69fd2271c72969106827e53a805c10e39dbe0c5 100644 (file)
@@ -2,7 +2,7 @@
 
 # import standard modules
 from fastapi import APIRouter, Request, Response, HTTPException, status
-from fastapi.responses import FileResponse, JSONResponse, RedirectResponse
+from fastapi.responses import FileResponse
 import asyncio
 import csv
 import json
@@ -76,15 +76,12 @@ async def api_dhcp_reload(request: Request):
         # RELOAD DHCP
 
         took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
-        return JSONResponse(
-            status_code=status.HTTP_200_OK,
-                content={
+        return {
                 "code": "DHCP_RELOAD_OK",
                 "status": "success",
                 "message": "DHCP configuration reload successfully",
                 "took_ms": took_ms,
-            },
-        )
+            }
 
     except HTTPException:
         raise
@@ -161,12 +158,9 @@ def api_dhcp_leases(request: Request):
         with path.open("r", encoding="utf-8", newline="") as f:
             reader = csv.DictReader(f)
             if not reader.fieldnames:
-                return JSONResponse(
-                    status_code=status.HTTP_200_OK,
-                    content={
+                return {
                         "total": 0, "items": []
-                    },
-                )
+                    }
 
             for raw in reader:
                 rec = { _norm(k): (v if v is not None else "") for k, v in raw.items() }
@@ -187,13 +181,10 @@ def api_dhcp_leases(request: Request):
                 }
                 items.append(item)
 
-        return JSONResponse(
-            status_code=status.HTTP_200_OK,
-            content={
+        return {
                 "total": len(items),
                 "items": items
-            },
-        )
+            }
 
     except Exception as err:
         logger.exception("Error reading DHCP leases: %s", str(err).strip())
index 894e9c85412c122ca8cd2c372ca65041376f5e97..10aefe9002cbc33ccc126dc086f421c081d409ff 100644 (file)
@@ -2,7 +2,7 @@
 
 # import standard modules
 from fastapi import APIRouter, Request, Response, HTTPException, status
-from fastapi.responses import FileResponse, JSONResponse, RedirectResponse
+from fastapi.responses import FileResponse
 import asyncio
 import json
 import os
@@ -114,15 +114,12 @@ async def api_dns_reload(request: Request):
         # RELOAD DNS
 
         took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
-        return JSONResponse(
-            status_code=status.HTTP_200_OK,
-                content={
+        return {
                 "code": "DNS_RELOAD_OK",
                 "status": "success",
                 "message": "DNS configuration reload successfully",
                 "took_ms": took_ms,
-            },
-        )
+            }
 
     except HTTPException:
         raise
index 06dd294641b9e07cdc2c0469024bf5cadd03f0b0..07362af8aafed6a4650046a6ef42849daf73221b 100644 (file)
@@ -2,7 +2,7 @@
 
 # import standard modules
 from fastapi import APIRouter, Request, Response, HTTPException, status
-from fastapi.responses import FileResponse, JSONResponse, RedirectResponse
+from fastapi.responses import FileResponse
 import ipaddress
 import time
 import os
@@ -122,16 +122,13 @@ def api_add_host(request: Request, data: dict):
         host_id = add_host(data)
         if(host_id > 0):
             took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
-            return JSONResponse(
-                status_code=status.HTTP_200_OK,
-                content={
+            return {
                     "code": "HOST_ADDED",
                     "status": "success",
                     "message": "Host added successfully",
                     "host_id": host_id,
                     "took_ms": took_ms,
-                },
-            )
+                }
 
         # Already present
         took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
@@ -178,16 +175,13 @@ def api_update_host(request: Request, data: dict, host_id: int):
         updated = update_host(host_id, data)
         if updated:
             took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
-            return JSONResponse(
-                status_code=status.HTTP_200_OK,
-                content={
+            return {
                     "code": "HOST_UPDATED",
                     "status": "success",
                     "message": "Host updated successfully",
                     "host_id": host_id,
                     "took_ms": took_ms,
-                },
-            )
+                }
 
         # Not Found
         took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
@@ -236,15 +230,12 @@ def api_delete_host(request: Request, host_id: int):
         deleted = delete_host(host_id)
         if deleted:
             took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
-            return JSONResponse(
-                status_code=status.HTTP_200_OK,
-                content={
+            return {
                     "code": "HOST_DELETED",
                     "status": "success",
                     "message": "Host deleted successfully",
                     "details": {"took_ms": took_ms, "host_id": host_id,},
-                },
-            )
+                }
 
         # Not Found
         took_ms = (time.monotonic_ns() - start_ns) / 1_000_000
index feda767b7790f82f056db8a2eb1b65cfc7414e6c..8978aa957c0942fabdc3ff7446aea960edc81eac 100644 (file)
@@ -2,7 +2,7 @@
 
 # import standard modules
 from fastapi import APIRouter, Request, Response, HTTPException, status
-from fastapi.responses import FileResponse, RedirectResponse
+from fastapi.responses import FileResponse
 import os
 import time