Skip to content

Commit 7952e8c

Browse files
committed
add previous keyword delete endpoint
1 parent b8a47c3 commit 7952e8c

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from fastapi import FastAPI , HTTPException, status
33
from fastapi.middleware.cors import CORSMiddleware
44
from crawlProcess import exec # Assuming these are in other files
5-
from service.privousChats import getAllDetailsById , getAllPreviousKeywords
5+
from service.privousChats import getAllDetailsById , getAllPreviousKeywords , deletePreviousCrawl
66
# from testdb import getKeywordAll , getKeywordById # Assuming these are in other files
77
from schema.keywordSchema import Keyword , KeywordOut # Assuming these are in other files
88
from schema.fullDetailsSchema import FullSchema , FullSchemaOut
@@ -175,4 +175,8 @@ def crawl():
175175
"message": f"Failed to run crawler: {str(e)}",
176176
"urls_sent": urls,
177177
"keyword_id": keywordId
178-
}
178+
}
179+
180+
@app.delete("/api/v1/keyword/{id}")
181+
async def deletePrevious(id:str):
182+
return await deletePreviousCrawl(id)

service/privousChats.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from model.keyword import keyword_collection
2+
from model.siteData import siteDataCollection
3+
from model.summary import summaryCollection
24
from bson import ObjectId
5+
from fastapi.responses import JSONResponse
36

47

58

@@ -75,3 +78,22 @@ async def getAllPreviousKeywords():
7578
print(result)
7679
return result
7780

81+
82+
83+
async def deletePreviousCrawl(id):
84+
try :
85+
await keyword_collection.delete_many({"_id" : ObjectId(id)})
86+
await siteDataCollection.delete_many({"keywordId" : ObjectId(id)})
87+
await summaryCollection.delete_many({"keywordId" : ObjectId(id)})
88+
89+
return JSONResponse(
90+
status_code=200,
91+
content={"status" : "success"}
92+
)
93+
except Exception as e :
94+
print(e)
95+
return JSONResponse(
96+
status_code=400,
97+
content={"status" : "fail"}
98+
)
99+

0 commit comments

Comments
 (0)