Commit
·
26c0248
1
Parent(s):
4b9447f
Fix endpoint to use user-provided budget_amount even when has_previous_data is true
Browse files- app/main.py +19 -9
app/main.py
CHANGED
|
@@ -208,15 +208,25 @@ async def check_and_get_recommendations(request: RecommendationRequest, month: O
|
|
| 208 |
has_data = recommender.check_user_has_category_data(request.user_id, request.category_id)
|
| 209 |
|
| 210 |
if has_data:
|
| 211 |
-
# User has previous data - use it
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
|
| 221 |
if recommendations:
|
| 222 |
return RecommendationResponse(
|
|
|
|
| 208 |
has_data = recommender.check_user_has_category_data(request.user_id, request.category_id)
|
| 209 |
|
| 210 |
if has_data:
|
| 211 |
+
# User has previous data - but if they provided budget_amount, use it (they want to set a new budget)
|
| 212 |
+
if request.budget_amount and request.budget_amount > 0:
|
| 213 |
+
print(f"✅ User {request.user_id} has previous data for category {request.category_id}, but provided budget_amount {request.budget_amount} - using provided amount")
|
| 214 |
+
recommendations = recommender.get_recommendation_for_category(
|
| 215 |
+
request.user_id,
|
| 216 |
+
request.category_id,
|
| 217 |
+
month,
|
| 218 |
+
year,
|
| 219 |
+
budget_amount=request.budget_amount # Use user's provided budget_amount
|
| 220 |
+
)
|
| 221 |
+
else:
|
| 222 |
+
print(f"✅ User {request.user_id} has previous data for category {request.category_id} - using historical data")
|
| 223 |
+
recommendations = recommender.get_recommendation_for_category(
|
| 224 |
+
request.user_id,
|
| 225 |
+
request.category_id,
|
| 226 |
+
month,
|
| 227 |
+
year,
|
| 228 |
+
budget_amount=None # Use historical data if no budget_amount provided
|
| 229 |
+
)
|
| 230 |
|
| 231 |
if recommendations:
|
| 232 |
return RecommendationResponse(
|