feat: implement proxy management endpoints and MongoDB integration

This commit is contained in:
gabdevele
2026-04-12 00:55:29 +02:00 Unverified
parent 1b03ac7541
commit b4a84e70a2
6 changed files with 209 additions and 25 deletions
+47 -8
View File
@@ -1,4 +1,13 @@
from fastapi import APIRouter
from fastapi import APIRouter, HTTPException, status
from models.proxy import ProxyCreateInput, ProxyUpdateInput
from utils.proxy.manager import (
create_proxy,
delete_proxy,
get_proxy_by_port,
list_proxies as list_proxy_documents,
update_proxy,
)
router = APIRouter(
prefix="/proxy",
@@ -7,15 +16,45 @@ router = APIRouter(
@router.get("/")
async def list_proxies():
return
async def list_proxies_handler():
return await list_proxy_documents()
@router.post("/")
async def create_proxy():
return
@router.get("/{proxy_port}/")
async def get_proxy(proxy_port: int):
proxy = await get_proxy_by_port(proxy_port)
if proxy is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Proxy not found")
return proxy
@router.post("/", status_code=status.HTTP_201_CREATED)
async def create_proxy_handler(payload: ProxyCreateInput):
existing_proxy = await get_proxy_by_port(payload.proxy_port)
if existing_proxy is not None:
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail=f"Proxy already exists on port {payload.proxy_port}",
)
return await create_proxy(
proxy_port=payload.proxy_port,
name=payload.name,
service={"address": payload.service.address, "port": payload.service.port},
code=payload.code,
)
@router.put("/{proxy_port}/")
async def edit_proxy():
return
async def edit_proxy(proxy_port: int, payload: ProxyUpdateInput):
updated_proxy = await update_proxy(proxy_port, payload)
if updated_proxy is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Proxy not found")
return updated_proxy
@router.delete("/{proxy_port}/", status_code=status.HTTP_204_NO_CONTENT)
async def remove_proxy(proxy_port: int):
deleted = await delete_proxy(proxy_port)
if not deleted:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Proxy not found")