File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77from .routes .get import router as get_router
88
99from .routes .create import router as create_router
10+ from .routes .delete import router as delete_router
1011
1112from .routes .import_linkedin import router as import_linkedin_router
1213
1819router .include_router (empty_router )
1920router .include_router (get_router )
2021router .include_router (create_router )
22+ router .include_router (delete_router )
2123router .include_router (import_linkedin_router )
2224router .include_router (alter_router )
2325router .include_router (rename_router )
Original file line number Diff line number Diff line change 1+ import os
2+ from fastapi import APIRouter , HTTPException
3+ from app .utils .make_meta import make_meta
4+ from app .utils .db import get_db_connection_direct
5+
6+ router = APIRouter ()
7+
8+ @router .delete ("/queue/delete" )
9+ def delete_queue_record (id : int ) -> dict :
10+ """DELETE /queue/delete: Delete a record from the queue table by id."""
11+ try :
12+ conn = get_db_connection_direct ()
13+ cursor = conn .cursor ()
14+ cursor .execute ("DELETE FROM queue WHERE id = %s RETURNING id;" , (id ,))
15+ deleted = cursor .fetchone ()
16+ conn .commit ()
17+ conn .close ()
18+ if deleted :
19+ return {"meta" : make_meta ("success" , f"Record with id { id } deleted." )}
20+ else :
21+ return {"meta" : make_meta ("error" , f"No record found with id { id } ." )}
22+ except Exception as e :
23+ msg = str (e )
24+ return {"meta" : make_meta ("error" , msg )}
Original file line number Diff line number Diff line change @@ -27,11 +27,11 @@ def read_queue() -> dict:
2727 for row in cursor .fetchall ()
2828 ]
2929
30- # 3. Get the 10 most recently updated records
31- cursor .execute ("SELECT * FROM queue ORDER BY updated DESC LIMIT 10 ;" )
30+ # 3. Get a random record
31+ cursor .execute ("SELECT * FROM queue ORDER BY RANDOM() LIMIT 1 ;" )
3232 columns = [desc [0 ] for desc in cursor .description ] if cursor .description else []
3333 rows = cursor .fetchall ()
34- most_recent = [dict (zip (columns , row )) for row in rows ] if rows and columns else []
34+ random_record = [dict (zip (columns , row )) for row in rows ] if rows and columns else []
3535
3636 # 4. Get unique values from collection and group columns
3737 cursor .execute ("SELECT DISTINCT collection FROM queue WHERE collection IS NOT NULL;" )
@@ -47,7 +47,7 @@ def read_queue() -> dict:
4747 "in_queue" : record_count ,
4848 "collections" : collections ,
4949 "groups" : groups ,
50- "example" : most_recent [: 1 ] ,
50+ "example" : random_record ,
5151 # "queue_schema": schema
5252 }
5353 }
Original file line number Diff line number Diff line change 1010@router .post ("/queue/import/linkedin" )
1111def import_linkedin_csv () -> dict :
1212 """POST /queue/import/linkedin: Import data from linkedin.csv into the queue table, robust for large files."""
13- csv_path = os .path .join (os .path .dirname (__file__ ), "../csv/linkedin/linkedin_sample .csv" )
13+ csv_path = os .path .join (os .path .dirname (__file__ ), "../csv/linkedin/linkedin .csv" )
1414 if not os .path .exists (csv_path ):
1515 raise HTTPException (status_code = 404 , detail = "linkedin.csv not found" )
1616 try :
Original file line number Diff line number Diff line change 11from app import __version__
2- from fastapi import FastAPI
2+ from fastapi import FastAPI , Request
3+ from fastapi .responses import JSONResponse
4+ from fastapi .exceptions import RequestValidationError
5+ from app .utils .make_meta import make_meta
36from fastapi .middleware .cors import CORSMiddleware
47from fastapi .staticfiles import StaticFiles
58from fastapi .responses import FileResponse
2629 allow_headers = ["*" ]
2730)
2831
32+
33+ # Global validation error handler for make_meta pattern
34+ @app .exception_handler (RequestValidationError )
35+ async def validation_exception_handler (request : Request , exc : RequestValidationError ):
36+ msg = exc .errors ()[0 ]['msg' ] if exc .errors () else str (exc )
37+ return JSONResponse (status_code = 422 , content = {"meta" : make_meta ("error" , msg )})
38+
2939app .include_router (router )
3040
3141# Mount static directory
You can’t perform that action at this time.
0 commit comments