Repository navigation
UZNadeem Assessment #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
uznadeem
wants to merge
8
commits into
Base360-AI:main
Choose a base branch
from
uznadeem:uznadeem-assessment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
UZNadeem Assessment #211
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2384d3b
Fix DB Conection, Remove Mock Data and Add Tenant Cache Key
uznadeem ba19a4a
Added tenant-scoped property ownership query
uznadeem 0d64ef1
fix: correct tenant-isolated monthly revenue calculation
uznadeem b18822a
Add monthly revenue filters to dashboard
uznadeem 305b98c
Preserve decimal precision in revenue totals
uznadeem b2d2060
Scope dashboard properties by tenant
uznadeem af4ff8e
Exclude non-USD reservations from revenue totals
uznadeem 8bf79e3
Revert DB Docker Port
uznadeem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,70 @@ | ||
| from fastapi import APIRouter, Depends, HTTPException | ||
| from typing import Dict, Any | ||
| from fastapi import APIRouter, Depends, HTTPException, Query | ||
| from typing import Any, Dict, List | ||
| from sqlalchemy import text | ||
| from app.services.cache import get_revenue_summary | ||
| from app.services.reservations import PropertyNotFoundError, RevenueServiceError | ||
| from app.core.auth import authenticate_request as get_current_user | ||
| from app.core.database_pool import db_pool | ||
|
|
||
| router = APIRouter() | ||
|
|
||
|
|
||
| @router.get("/dashboard/properties") | ||
| async def get_dashboard_properties( | ||
| current_user: dict = Depends(get_current_user) | ||
| ) -> List[Dict[str, str]]: | ||
| tenant_id = getattr(current_user, "tenant_id", "default_tenant") or "default_tenant" | ||
|
|
||
| try: | ||
| async with db_pool.get_session() as session: | ||
| result = await session.execute(text(""" | ||
| SELECT id, name | ||
| FROM properties | ||
| WHERE tenant_id = :tenant_id | ||
| ORDER BY name | ||
| """), {"tenant_id": tenant_id}) | ||
| return [ | ||
| {"id": row.id, "name": row.name} | ||
| for row in result.fetchall() | ||
| ] | ||
| except Exception as error: | ||
| raise HTTPException( | ||
| status_code=503, | ||
| detail="Properties are temporarily unavailable", | ||
| ) from error | ||
|
|
||
|
|
||
| @router.get("/dashboard/summary") | ||
| async def get_dashboard_summary( | ||
| property_id: str, | ||
| year: int = Query(ge=1, le=9998), | ||
| month: int = Query(ge=1, le=12), | ||
| current_user: dict = Depends(get_current_user) | ||
| ) -> Dict[str, Any]: | ||
|
|
||
| tenant_id = getattr(current_user, "tenant_id", "default_tenant") or "default_tenant" | ||
|
|
||
| revenue_data = await get_revenue_summary(property_id, tenant_id) | ||
|
|
||
| total_revenue_float = float(revenue_data['total']) | ||
| try: | ||
| revenue_data = await get_revenue_summary( | ||
| property_id, | ||
| tenant_id, | ||
| year, | ||
| month, | ||
| ) | ||
| except PropertyNotFoundError as error: | ||
| raise HTTPException( | ||
| status_code=404, | ||
| detail="Property not found", | ||
| ) from error | ||
| except RevenueServiceError as error: | ||
| raise HTTPException( | ||
| status_code=503, | ||
| detail="Revenue data is temporarily unavailable", | ||
| ) from error | ||
|
|
||
| return { | ||
| "property_id": revenue_data['property_id'], | ||
| "total_revenue": total_revenue_float, | ||
| "total_revenue": revenue_data['total'], | ||
| "currency": revenue_data['currency'], | ||
| "reservations_count": revenue_data['count'] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The database pool initialization
db_pool.initialize()lacks error handling. A misconfigured database URL will raise an unhandled exception and crash the application on startup.Severity: HIGH
Suggested Fix
Wrap the
await db_pool.initialize()call within atry/exceptblock to catch potential exceptions. Log any errors that occur, similar to the error handling implemented for the Supabase and Redis initializations, to prevent the entire application from crashing during startup.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.