OxbridgeEconomics commited on
Commit
1753da3
·
unverified ·
1 Parent(s): 89f268f

Update summary.py

Browse files
Files changed (1) hide show
  1. app/routes/summary.py +47 -47
app/routes/summary.py CHANGED
@@ -10,57 +10,57 @@ from models.database import knowledge_base # pylint: disable=import-error
10
 
11
  router = APIRouter(prefix="/summary", tags=["summary"])
12
 
13
- @router.get("/{email}")
14
- async def get_user_document_stats(
15
- email: str = Path(..., description="User's email address")
16
- ) -> JSONResponse:
17
- """
18
- Get document statistics for a specific user.
19
 
20
- This endpoint counts the number of unique emails and files uploaded by the user.
21
- It groups documents by metadata.id to ensure unique document counting (not chunks).
22
 
23
- Args:
24
- email (str): The user's email address
25
 
26
- Returns:
27
- JSONResponse: A JSON response containing document counts:
28
- {
29
- "email": "[email protected]",
30
- "emails": 5,
31
- "files": 12,
32
- "total_documents": 17
33
- }
34
 
35
- Raises:
36
- HTTPException: 400 for invalid email, 500 for database errors
37
- """
38
- try:
39
- email_pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
40
- if not email or not re.match(email_pattern, email):
41
- raise HTTPException(
42
- status_code=400,
43
- detail="Invalid email format. Must be a valid email address."
44
- )
45
-
46
- # Get document counts from database
47
- result = knowledge_base.get_doc_count(email)
48
-
49
- # Add email to response
50
- result["email"] = email
51
-
52
- return JSONResponse(content=result, status_code=200)
53
-
54
- except ValueError as e:
55
- logger.error("Validation error for user %s: %s", email, str(e))
56
- raise HTTPException(status_code=400, detail=str(e)) # pylint: disable=raise-missing-from
57
-
58
- except Exception as e: # pylint: disable=broad-exception-caught
59
- logger.error("Database error for user %s: %s", email, str(e))
60
- raise HTTPException( # pylint: disable=raise-missing-from
61
- status_code=500,
62
- detail="Internal server error while retrieving document statistics."
63
- )
64
 
65
  @router.get('')
66
  async def get_summary() -> JSONResponse:
 
10
 
11
  router = APIRouter(prefix="/summary", tags=["summary"])
12
 
13
+ # @router.get("/{email}")
14
+ # async def get_user_document_stats(
15
+ # email: str = Path(..., description="User's email address")
16
+ # ) -> JSONResponse:
17
+ # """
18
+ # Get document statistics for a specific user.
19
 
20
+ # This endpoint counts the number of unique emails and files uploaded by the user.
21
+ # It groups documents by metadata.id to ensure unique document counting (not chunks).
22
 
23
+ # Args:
24
+ # email (str): The user's email address
25
 
26
+ # Returns:
27
+ # JSONResponse: A JSON response containing document counts:
28
+ # {
29
+ # "email": "[email protected]",
30
+ # "emails": 5,
31
+ # "files": 12,
32
+ # "total_documents": 17
33
+ # }
34
 
35
+ # Raises:
36
+ # HTTPException: 400 for invalid email, 500 for database errors
37
+ # """
38
+ # try:
39
+ # email_pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
40
+ # if not email or not re.match(email_pattern, email):
41
+ # raise HTTPException(
42
+ # status_code=400,
43
+ # detail="Invalid email format. Must be a valid email address."
44
+ # )
45
+
46
+ # # Get document counts from database
47
+ # result = knowledge_base.get_doc_count(email)
48
+
49
+ # # Add email to response
50
+ # result["email"] = email
51
+
52
+ # return JSONResponse(content=result, status_code=200)
53
+
54
+ # except ValueError as e:
55
+ # logger.error("Validation error for user %s: %s", email, str(e))
56
+ # raise HTTPException(status_code=400, detail=str(e)) # pylint: disable=raise-missing-from
57
+
58
+ # except Exception as e: # pylint: disable=broad-exception-caught
59
+ # logger.error("Database error for user %s: %s", email, str(e))
60
+ # raise HTTPException( # pylint: disable=raise-missing-from
61
+ # status_code=500,
62
+ # detail="Internal server error while retrieving document statistics."
63
+ # )
64
 
65
  @router.get('')
66
  async def get_summary() -> JSONResponse: