quivr/backend/routes/prompt_routes.py
Zineb El Bachiri 1f21c6d7f3
refactor: packages folder be 2 (#1628)
# Description

Move some folders to packages
Remove unused code
2023-11-14 14:31:02 +01:00

60 lines
1.4 KiB
Python

from uuid import UUID
from fastapi import APIRouter, Depends
from middlewares.auth import AuthBearer
from models import Prompt
from models.databases.supabase.prompts import (
CreatePromptProperties,
PromptUpdatableProperties,
)
from repository.prompt import (
create_prompt,
get_prompt_by_id,
get_public_prompts,
update_prompt_by_id,
)
prompt_router = APIRouter()
@prompt_router.get("/prompts", dependencies=[Depends(AuthBearer())], tags=["Prompt"])
async def get_prompts() -> list[Prompt]:
"""
Retrieve all public prompt
"""
return get_public_prompts()
@prompt_router.get(
"/prompts/{prompt_id}", dependencies=[Depends(AuthBearer())], tags=["Prompt"]
)
async def get_prompt(prompt_id: UUID) -> Prompt | None:
"""
Retrieve a prompt by its id
"""
return get_prompt_by_id(prompt_id)
@prompt_router.put(
"/prompts/{prompt_id}", dependencies=[Depends(AuthBearer())], tags=["Prompt"]
)
async def update_prompt(
prompt_id: UUID, prompt: PromptUpdatableProperties
) -> Prompt | None:
"""
Update a prompt by its id
"""
return update_prompt_by_id(prompt_id, prompt)
@prompt_router.post("/prompts", dependencies=[Depends(AuthBearer())], tags=["Prompt"])
async def create_prompt_route(prompt: CreatePromptProperties) -> Prompt | None:
"""
Create a prompt by its id
"""
return create_prompt(prompt)