Spaces:
Sleeping
Sleeping
Doanh Van Vu commited on
Commit ·
520d0d8
1
Parent(s): 53c7523
Add delete mentor endpoint and implement deletion logic in RecommendationService
Browse files- Introduced a new DELETE endpoint at /mentors/{mentor_id} for removing mentors from the system.
- Implemented the delete_mentor method in RecommendationService to handle the deletion process, including error logging and exception handling for improved reliability.
- routers/mentors.py +31 -1
- services/recommendation_service.py +7 -2
routers/mentors.py
CHANGED
|
@@ -85,5 +85,35 @@ async def batch_upsert_mentors(
|
|
| 85 |
detail=f"Failed to batch upsert mentors: {str(e)}"
|
| 86 |
)
|
| 87 |
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
|
|
|
| 85 |
detail=f"Failed to batch upsert mentors: {str(e)}"
|
| 86 |
)
|
| 87 |
|
| 88 |
+
@router.delete("/mentors/{mentor_id}")
|
| 89 |
+
async def delete_mentor(
|
| 90 |
+
request: Request,
|
| 91 |
+
mentor_id: int
|
| 92 |
+
):
|
| 93 |
+
try:
|
| 94 |
+
logger.info(f"Received delete request for mentor ID: {mentor_id}")
|
| 95 |
+
|
| 96 |
+
recommendation_service = RecommendationService()
|
| 97 |
+
success = recommendation_service.delete_mentor(str(mentor_id))
|
| 98 |
+
|
| 99 |
+
if success:
|
| 100 |
+
logger.info(f"Successfully deleted mentor ID: {mentor_id}")
|
| 101 |
+
return {
|
| 102 |
+
"success": True,
|
| 103 |
+
"message": "Mentor deleted successfully",
|
| 104 |
+
"mentor_id": mentor_id
|
| 105 |
+
}
|
| 106 |
+
else:
|
| 107 |
+
raise HTTPException(
|
| 108 |
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
| 109 |
+
detail="Failed to delete mentor"
|
| 110 |
+
)
|
| 111 |
+
except HTTPException:
|
| 112 |
+
raise
|
| 113 |
+
except Exception as e:
|
| 114 |
+
logger.error(f"Error deleting mentor: {str(e)}", exc_info=True)
|
| 115 |
+
raise HTTPException(
|
| 116 |
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
| 117 |
+
detail=f"Failed to delete mentor: {str(e)}"
|
| 118 |
+
)
|
| 119 |
|
services/recommendation_service.py
CHANGED
|
@@ -123,6 +123,11 @@ class RecommendationService:
|
|
| 123 |
filter_dict["status"] = "ACTIVATED"
|
| 124 |
|
| 125 |
return filter_dict if filter_dict else None
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
|
|
|
| 123 |
filter_dict["status"] = "ACTIVATED"
|
| 124 |
|
| 125 |
return filter_dict if filter_dict else None
|
| 126 |
+
|
| 127 |
+
def delete_mentor(self, mentor_id: str) -> bool:
|
| 128 |
+
try:
|
| 129 |
+
return self.pinecone_service.delete_mentor(mentor_id)
|
| 130 |
+
except Exception as e:
|
| 131 |
+
logger.error(f"Failed to delete mentor: {str(e)}")
|
| 132 |
+
raise
|
| 133 |
|