tags=["Distributions"],
)
-async def get_from_path(distro: str = fastapi.Path(...)) -> Distro:
+async def get_distro_from_path(distro: str = fastapi.Path(...)) -> Distro:
"""
Fetches the distribution from the name in the path
"""
return await backend.distros.get_by_slug(distro)
+async def get_repo_from_path(
+ distro: typing.Optional[Distro] = fastapi.Depends(get_distro_from_path),
+ repo: str = fastapi.Path(...)) -> typing.Optional[Repo]:
+ """
+ Fetches the repository from the name in the path
+ """
+ # Return None if we could not find the distro
+ if distro is None:
+ return None
+
+ # Return the repo
+ return await distro.get_repo(repo)
+
@router.get("")
async def get_distros() -> typing.List[Distro]:
"""
return [distro async for distro in backend.distros]
@router.get("/{distro}")
-async def get_distro(distro = fastapi.Depends(get_from_path)) -> Distro:
+async def get_distro(distro = fastapi.Depends(get_distro_from_path)) -> Distro:
"""
An endpoint to fetch information about a specific distribution
"""
return distro
@router.get("/{distro}/repos")
-async def get_repos(distro = fastapi.Depends(get_from_path)) -> typing.List[Repo]:
+async def get_repos(distro = fastapi.Depends(get_distro_from_path)) -> typing.List[Repo]:
"""
An endpoint to fetch all repositories that belong to a distro
"""
# Return a list with all repos
return await distro.get_repos()
+@router.get("/{distro}/repos/{repo}")
+async def get_repo(repo = fastapi.Depends(get_repo_from_path)) -> Repo:
+ """
+ An endpoint to fetch all repositories that belong to a distro
+ """
+ # Send 404 if we could not find the repo
+ if not repo:
+ raise fastapi.HTTPException(404, "Could not find the repository")
+
+ # Return the repository
+ return repo
+
# Add everything to the APIv1
apiv1.include_router(router)