Skip to content

Commit a7cdc7d

Browse files
Merge pull request #87 from goldlabelapps/staging
Add PATCH /prompt/drop endpoint
2 parents ef9c98a + 7193af0 commit a7cdc7d

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

app/api/prompt/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Prompt Routes"""
22

3+
34
from .prompt import router as prompt_router
45
from .linkedin import router as linkedin_router
6+
from .drop import router as drop_router

app/api/prompt/drop.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
3+
from fastapi import APIRouter, Depends, HTTPException
4+
5+
from app.utils.api_key_auth import get_api_key
6+
from app.utils.db import get_db_connection_direct
7+
from app.utils.make_meta import make_meta
8+
9+
router = APIRouter()
10+
11+
# PATCH /prompt/drop: empties the prompt table
12+
@router.patch("/prompt/drop")
13+
def drop_prompt_table(api_key: str = Depends(get_api_key)) -> dict:
14+
"""PATCH /prompt/drop: empties the prompt table."""
15+
try:
16+
conn = get_db_connection_direct()
17+
cur = conn.cursor()
18+
cur.execute("TRUNCATE TABLE prompt RESTART IDENTITY CASCADE;")
19+
conn.commit()
20+
cur.close()
21+
conn.close()
22+
return {"meta": make_meta("success", "Prompt table emptied"), "data": {}}
23+
except Exception as e:
24+
return {"meta": make_meta("error", f"Failed to empty prompt table: {str(e)}"), "data": {}}

app/api/routes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from app.utils.notify.resend import router as resend_router
1111
from app.api.prompt.prompt import router as prompt_router
1212
from app.api.prompt.linkedin import router as linkedin_router
13+
from app.api.prompt.drop import router as drop_router
1314
from app.api.prospects.prospects import router as prospects_router
1415
from app.api.orders.orders import router as orders_router
1516

@@ -18,5 +19,6 @@
1819
router.include_router(health_router)
1920
router.include_router(prompt_router)
2021
router.include_router(linkedin_router)
22+
router.include_router(drop_router)
2123
router.include_router(prospects_router)
2224
router.include_router(orders_router)

0 commit comments

Comments
 (0)