feat: refactor proxy management logic and add database integration
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
|
||||
from models.proxy import ProxyCreateInput, ProxyUpdateInput
|
||||
from utils.proxy.manager import (
|
||||
from db.proxy import (
|
||||
create_proxy,
|
||||
delete_proxy,
|
||||
get_proxy_by_port,
|
||||
list_proxies as list_proxy_documents,
|
||||
update_proxy,
|
||||
)
|
||||
from models.proxy import ProxyCreateInput, ProxyUpdateInput
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/proxy",
|
||||
@@ -15,12 +15,12 @@ router = APIRouter(
|
||||
)
|
||||
|
||||
|
||||
@router.get("/")
|
||||
@router.get("")
|
||||
async def list_proxies_handler():
|
||||
return await list_proxy_documents()
|
||||
|
||||
|
||||
@router.get("/{proxy_port}/")
|
||||
@router.get("/{proxy_port}")
|
||||
async def get_proxy(proxy_port: int):
|
||||
proxy = await get_proxy_by_port(proxy_port)
|
||||
if proxy is None:
|
||||
@@ -28,7 +28,7 @@ async def get_proxy(proxy_port: int):
|
||||
return proxy
|
||||
|
||||
|
||||
@router.post("/", status_code=status.HTTP_201_CREATED)
|
||||
@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:
|
||||
@@ -45,7 +45,7 @@ async def create_proxy_handler(payload: ProxyCreateInput):
|
||||
)
|
||||
|
||||
|
||||
@router.put("/{proxy_port}/")
|
||||
@router.put("/{proxy_port}")
|
||||
async def edit_proxy(proxy_port: int, payload: ProxyUpdateInput):
|
||||
updated_proxy = await update_proxy(proxy_port, payload)
|
||||
if updated_proxy is None:
|
||||
@@ -53,7 +53,7 @@ async def edit_proxy(proxy_port: int, payload: ProxyUpdateInput):
|
||||
return updated_proxy
|
||||
|
||||
|
||||
@router.delete("/{proxy_port}/", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@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:
|
||||
|
||||
Reference in New Issue
Block a user