From: Michael Tremer Date: Thu, 3 Jul 2025 08:36:11 +0000 (+0000) Subject: api: Create an endpoint to create new mirrors X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=972d40b6cf547777977ac7d1dd4281ccc9000110;p=pbs.git api: Create an endpoint to create new mirrors Signed-off-by: Michael Tremer --- diff --git a/src/api/mirrors.py b/src/api/mirrors.py index 978db93d..3864fce3 100644 --- a/src/api/mirrors.py +++ b/src/api/mirrors.py @@ -40,6 +40,40 @@ async def get_mirror_from_path(hostname: str = fastapi.Path(...)) -> Mirror | No """ return await backend.mirrors.get_by_hostname(hostname) +class CreateMirrorRequest(pydantic.BaseModel): + # Hostname + hostname: str + + # Path + path: str + + # Owner + owner: str + + # Contact + contact: str + + # Notes + notes: str + +@router.post("") +async def create_mirror( + request: CreateMirrorRequest, + current_user: User = fastapi.Depends(auth.get_current_admin), +) -> Mirror: + async with backend.db as session: + mirror = await backend.mirrors.create( + hostname = request.hostname, + path = request.path, + owner = request.owner, + contact = request.contact, + notes = request.notes, + user = current_user, + ) + + # Return the new mirror + return mirror + @router.get("") async def get_mirrors() -> list[Mirror]: return [mirror async for mirror in backend.mirrors]