quivr/backend/modules/prompt/controller/prompt_routes.py
Zineb El Bachiri 1bf67e3640
refactor: Prompt module (#1688)
# Description

Prompt module with Service

## Checklist before requesting a review

Please delete options that are not relevant.

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

## Screenshots (if appropriate):
2023-11-23 14:13:21 +01:00

56 lines
1.4 KiB
Python

from uuid import UUID
from fastapi import APIRouter, Depends
from middlewares.auth import AuthBearer
from modules.prompt.entity.prompt import (
CreatePromptProperties,
Prompt,
PromptUpdatableProperties,
)
from modules.prompt.service import PromptService
prompt_router = APIRouter()
promptService = PromptService()
@prompt_router.get("/prompts", dependencies=[Depends(AuthBearer())], tags=["Prompt"])
async def get_prompts() -> list[Prompt]:
"""
Retrieve all public prompt
"""
return promptService.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 promptService.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 promptService.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 promptService.create_prompt(prompt)