From: Giorgio Ravera Date: Mon, 16 Mar 2026 20:38:37 +0000 (+0100) Subject: Removed JSONResponse X-Git-Url: http://git.giorgioravera.it/?a=commitdiff_plain;h=25746cd0a656450c878e4ab870f84ff4a142576e;p=network-manager.git Removed JSONResponse --- diff --git a/backend/routes/aliases.py b/backend/routes/aliases.py index b97da40..66673fa 100644 --- a/backend/routes/aliases.py +++ b/backend/routes/aliases.py @@ -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 diff --git a/backend/routes/backup.py b/backend/routes/backup.py index 794f852..e84b337 100644 --- a/backend/routes/backup.py +++ b/backend/routes/backup.py @@ -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 diff --git a/backend/routes/dhcp.py b/backend/routes/dhcp.py index df1c417..a69fd22 100644 --- a/backend/routes/dhcp.py +++ b/backend/routes/dhcp.py @@ -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()) diff --git a/backend/routes/dns.py b/backend/routes/dns.py index 894e9c8..10aefe9 100644 --- a/backend/routes/dns.py +++ b/backend/routes/dns.py @@ -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 diff --git a/backend/routes/hosts.py b/backend/routes/hosts.py index 06dd294..07362af 100644 --- a/backend/routes/hosts.py +++ b/backend/routes/hosts.py @@ -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 diff --git a/backend/routes/login.py b/backend/routes/login.py index feda767..8978aa9 100644 --- a/backend/routes/login.py +++ b/backend/routes/login.py @@ -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