File size: 1,460 Bytes
67e167f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from typing import Annotated, List
from sqlalchemy.orm import Session
from fastapi import APIRouter, Depends, HTTPException

from app.db import get_db
from app.core import schemas, crud
from app.security import get_current_user


router = APIRouter()


@router.get("/get-all-prompts/", response_model=List[schemas.Prompt])
def get_all_prompts(

    db: Annotated[Session, Depends(get_db)],

    current_user: Annotated[schemas.User, Depends(get_current_user)],

):
    if not current_user.is_superuser:
        raise HTTPException(status_code=403, detail="Forbidden")

    return crud.get_all_prompts(db=db)


@router.get("/get-prompt_by_user_id/{user_id}/", response_model=List[schemas.Prompt])
def get_prompt_by_user_id(

    user_id: int,

    db: Annotated[Session, Depends(get_db)],

    current_user: Annotated[schemas.User, Depends(get_current_user)],

):
    if not current_user.is_superuser:
        raise HTTPException(status_code=403, detail="Forbidden")

    return crud.get_prompt_by_user_id(user_id=user_id, db=db)


# @router.post("/create-prompt/", response_model=schemas.Prompt)
# def create_prompt(
#     prompt: str,
#     db: Annotated[Session, Depends(get_db)],
#     current_user: Annotated[schemas.User, Depends(get_current_user)],
# ):
#     if not current_user.is_superuser:
#         raise HTTPException(status_code=403, detail="Forbidden")

#     return crud.create_prompt(prompt=prompt, db=db)