feat(sqlalchemy): remove session reference from router

This commit is contained in:
Jonathan Rohde
2024-06-27 07:48:08 +02:00
parent df09d0830a
commit bee835cb65
34 changed files with 1227 additions and 1207 deletions
+10 -12
View File
@@ -6,7 +6,6 @@ from fastapi import APIRouter
from pydantic import BaseModel
import json
from apps.webui.internal.db import get_db
from apps.webui.models.prompts import Prompts, PromptForm, PromptModel
from utils.utils import get_current_user, get_admin_user
@@ -20,8 +19,8 @@ router = APIRouter()
@router.get("/", response_model=List[PromptModel])
async def get_prompts(user=Depends(get_current_user), db=Depends(get_db)):
return Prompts.get_prompts(db)
async def get_prompts(user=Depends(get_current_user)):
return Prompts.get_prompts()
############################
@@ -31,11 +30,11 @@ async def get_prompts(user=Depends(get_current_user), db=Depends(get_db)):
@router.post("/create", response_model=Optional[PromptModel])
async def create_new_prompt(
form_data: PromptForm, user=Depends(get_admin_user), db=Depends(get_db)
form_data: PromptForm, user=Depends(get_admin_user)
):
prompt = Prompts.get_prompt_by_command(db, form_data.command)
prompt = Prompts.get_prompt_by_command(form_data.command)
if prompt == None:
prompt = Prompts.insert_new_prompt(db, user.id, form_data)
prompt = Prompts.insert_new_prompt(user.id, form_data)
if prompt:
return prompt
@@ -56,9 +55,9 @@ async def create_new_prompt(
@router.get("/command/{command}", response_model=Optional[PromptModel])
async def get_prompt_by_command(
command: str, user=Depends(get_current_user), db=Depends(get_db)
command: str, user=Depends(get_current_user)
):
prompt = Prompts.get_prompt_by_command(db, f"/{command}")
prompt = Prompts.get_prompt_by_command(f"/{command}")
if prompt:
return prompt
@@ -79,9 +78,8 @@ async def update_prompt_by_command(
command: str,
form_data: PromptForm,
user=Depends(get_admin_user),
db=Depends(get_db),
):
prompt = Prompts.update_prompt_by_command(db, f"/{command}", form_data)
prompt = Prompts.update_prompt_by_command(f"/{command}", form_data)
if prompt:
return prompt
else:
@@ -98,7 +96,7 @@ async def update_prompt_by_command(
@router.delete("/command/{command}/delete", response_model=bool)
async def delete_prompt_by_command(
command: str, user=Depends(get_admin_user), db=Depends(get_db)
command: str, user=Depends(get_admin_user)
):
result = Prompts.delete_prompt_by_command(db, f"/{command}")
result = Prompts.delete_prompt_by_command(f"/{command}")
return result