LogicGoInfotechSpaces commited on
Commit
13edd0d
·
1 Parent(s): 9e1b2d4

Fix route order: Move POST /recommendations/check before GET /recommendations/{user_id} to prevent 405 error

Browse files
Smart_Budget_Recommendation_API.postman_collection.json CHANGED
@@ -1,398 +1,246 @@
1
  {
2
  "info": {
3
- "_postman_id": "smart-budget-recommendation-api",
4
- "name": "Smart Budget Recommendation API",
5
- "description": "API collection for Smart Budget Recommendation service deployed on Hugging Face",
6
- "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
7
- },
8
- "auth": {
9
- "type": "bearer",
10
- "bearer": [
11
- {
12
- "key": "token",
13
- "value": "{{hf_token}}",
14
- "type": "string"
15
- }
16
- ]
17
  },
18
  "item": [
19
- {
20
- "name": "Health Check",
21
- "request": {
22
- "method": "GET",
23
- "header": [],
24
- "url": {
25
- "raw": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space/health",
26
- "protocol": "https",
27
- "host": [
28
- "logicgoinfotechspaces-smart-budget-recommendation",
29
- "hf",
30
- "space"
31
- ],
32
- "path": [
33
- "health"
34
- ]
35
- },
36
- "description": "Check if the API and database are running"
37
- }
38
- },
39
- {
40
- "name": "Root Endpoint",
41
- "request": {
42
- "method": "GET",
43
- "header": [],
44
- "url": {
45
- "raw": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space/",
46
- "protocol": "https",
47
- "host": [
48
- "logicgoinfotechspaces-smart-budget-recommendation",
49
- "hf",
50
- "space"
51
- ],
52
- "path": [
53
- ""
54
- ]
55
- }
56
- }
57
- },
58
- {
59
- "name": "Create Expense",
60
- "request": {
61
- "method": "POST",
62
- "header": [
63
- {
64
- "key": "Content-Type",
65
- "value": "application/json"
66
- }
67
- ],
68
- "body": {
69
- "mode": "raw",
70
- "raw": "{\n \"user_id\": \"{{user_id}}\",\n \"amount\": 3800,\n \"category\": \"Groceries\",\n \"description\": \"Monthly groceries\",\n \"date\": \"2025-01-15T00:00:00\",\n \"type\": \"expense\"\n}"
71
- },
72
- "url": {
73
- "raw": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space/expenses",
74
- "protocol": "https",
75
- "host": [
76
- "logicgoinfotechspaces-smart-budget-recommendation",
77
- "hf",
78
- "space"
79
- ],
80
- "path": [
81
- "expenses"
82
- ]
83
- },
84
- "description": "Create a new expense record"
85
- }
86
- },
87
- {
88
- "name": "Get Expenses",
89
- "request": {
90
- "method": "GET",
91
- "header": [],
92
- "url": {
93
- "raw": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space/expenses?user_id={{user_id}}&limit=20",
94
- "protocol": "https",
95
- "host": [
96
- "logicgoinfotechspaces-smart-budget-recommendation",
97
- "hf",
98
- "space"
99
- ],
100
- "path": [
101
- "expenses"
102
- ],
103
- "query": [
104
- {
105
- "key": "user_id",
106
- "value": "{{user_id}}",
107
- "description": "User identifier"
108
- },
109
- {
110
- "key": "limit",
111
- "value": "20",
112
- "description": "Maximum number of expenses to return"
113
- }
114
- ]
115
- },
116
- "description": "Get expenses for a specific user"
117
- }
118
- },
119
- {
120
- "name": "Create Budget",
121
- "request": {
122
- "method": "POST",
123
- "header": [
124
- {
125
- "key": "Content-Type",
126
- "value": "application/json"
127
- }
128
- ],
129
- "body": {
130
- "mode": "raw",
131
- "raw": "{\n \"user_id\": \"{{user_id}}\",\n \"category\": \"Groceries\",\n \"amount\": 4000,\n \"period\": \"monthly\",\n \"start_date\": \"2025-02-01T00:00:00\",\n \"end_date\": \"2025-02-28T00:00:00\"\n}"
132
- },
133
- "url": {
134
- "raw": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space/budgets",
135
- "protocol": "https",
136
- "host": [
137
- "logicgoinfotechspaces-smart-budget-recommendation",
138
- "hf",
139
- "space"
140
- ],
141
- "path": [
142
- "budgets"
143
- ]
144
- },
145
- "description": "Create a new budget"
146
- }
147
- },
148
- {
149
- "name": "Get Budgets",
150
- "request": {
151
- "method": "GET",
152
- "header": [],
153
- "url": {
154
- "raw": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space/budgets?user_id={{user_id}}",
155
- "protocol": "https",
156
- "host": [
157
- "logicgoinfotechspaces-smart-budget-recommendation",
158
- "hf",
159
- "space"
160
- ],
161
- "path": [
162
- "budgets"
163
- ],
164
- "query": [
165
- {
166
- "key": "user_id",
167
- "value": "{{user_id}}"
168
- }
169
- ]
170
- },
171
- "description": "Get budgets for a specific user"
172
- }
173
- },
174
- {
175
- "name": "Get Smart Budget Recommendations",
176
- "request": {
177
- "method": "GET",
178
- "header": [],
179
- "url": {
180
- "raw": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space/recommendations/{{user_id}}?month=2&year=2025",
181
- "protocol": "https",
182
- "host": [
183
- "logicgoinfotechspaces-smart-budget-recommendation",
184
- "hf",
185
- "space"
186
- ],
187
- "path": [
188
- "recommendations",
189
- "{{user_id}}"
190
- ],
191
- "query": [
192
- {
193
- "key": "month",
194
- "value": "2",
195
- "description": "Target month (1-12), optional - defaults to next month"
196
- },
197
- {
198
- "key": "year",
199
- "value": "2025",
200
- "description": "Target year, optional - defaults to next year"
201
- }
202
- ]
203
- },
204
- "description": "Get smart budget recommendations based on past spending behavior. Uses expenses, then budgets as fallback."
205
- }
206
- },
207
- {
208
- "name": "Get Category Expenses",
209
- "request": {
210
- "method": "GET",
211
- "header": [],
212
- "url": {
213
- "raw": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space/category-expenses/{{user_id}}?months=3",
214
- "protocol": "https",
215
- "host": [
216
- "logicgoinfotechspaces-smart-budget-recommendation",
217
- "hf",
218
- "space"
219
- ],
220
- "path": [
221
- "category-expenses",
222
- "{{user_id}}"
223
- ],
224
- "query": [
225
- {
226
- "key": "months",
227
- "value": "3",
228
- "description": "Number of months to analyze (default: 3)"
229
- }
230
- ]
231
- },
232
- "description": "Get average expenses by category for the past N months"
233
- }
234
- },
235
- {
236
- "name": "Sample Expenses - Create Multiple",
237
- "item": [
238
- {
239
- "name": "Groceries - Month 1 (Sept 2024)",
240
- "request": {
241
- "method": "POST",
242
- "header": [
243
  {
244
- "key": "Content-Type",
245
- "value": "application/json"
 
 
 
 
 
 
 
 
 
246
  }
247
- ],
248
- "body": {
249
- "mode": "raw",
250
- "raw": "{\n \"user_id\": \"{{user_id}}\",\n \"amount\": 3500,\n \"category\": \"Groceries\",\n \"description\": \"Monthly groceries - September 2024\",\n \"date\": \"2024-09-15T00:00:00\",\n \"type\": \"expense\"\n}"
251
- },
252
- "url": {
253
- "raw": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space/expenses",
254
- "protocol": "https",
255
- "host": [
256
- "logicgoinfotechspaces-smart-budget-recommendation",
257
- "hf",
258
- "space"
259
- ],
260
- "path": [
261
- "expenses"
262
- ]
263
- }
264
- }
265
- },
266
- {
267
- "name": "Groceries - Month 2 (Oct 2024)",
268
- "request": {
269
- "method": "POST",
270
- "header": [
271
  {
272
- "key": "Content-Type",
273
- "value": "application/json"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  }
275
- ],
276
- "body": {
277
- "mode": "raw",
278
- "raw": "{\n \"user_id\": \"{{user_id}}\",\n \"amount\": 3800,\n \"category\": \"Groceries\",\n \"description\": \"Monthly groceries - October 2024\",\n \"date\": \"2024-10-15T00:00:00\",\n \"type\": \"expense\"\n}"
279
- },
280
- "url": {
281
- "raw": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space/expenses",
282
- "protocol": "https",
283
- "host": [
284
- "logicgoinfotechspaces-smart-budget-recommendation",
285
- "hf",
286
- "space"
287
- ],
288
- "path": [
289
- "expenses"
290
- ]
291
- }
292
- }
293
- },
294
- {
295
- "name": "Groceries - Month 3 (Nov 2024)",
296
- "request": {
297
- "method": "POST",
298
- "header": [
 
 
 
299
  {
300
- "key": "Content-Type",
301
- "value": "application/json"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  }
303
- ],
304
- "body": {
305
- "mode": "raw",
306
- "raw": "{\n \"user_id\": \"{{user_id}}\",\n \"amount\": 4000,\n \"category\": \"Groceries\",\n \"description\": \"Monthly groceries - November 2024\",\n \"date\": \"2024-11-15T00:00:00\",\n \"type\": \"expense\"\n}"
307
- },
308
- "url": {
309
- "raw": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space/expenses",
310
- "protocol": "https",
311
- "host": [
312
- "logicgoinfotechspaces-smart-budget-recommendation",
313
- "hf",
314
- "space"
315
- ],
316
- "path": [
317
- "expenses"
318
- ]
319
- }
320
- }
321
- },
322
- {
323
- "name": "Transport - Month 1 (Sept 2024)",
324
- "request": {
325
- "method": "POST",
326
- "header": [
327
  {
328
- "key": "Content-Type",
329
- "value": "application/json"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
  }
331
- ],
332
- "body": {
333
- "mode": "raw",
334
- "raw": "{\n \"user_id\": \"{{user_id}}\",\n \"amount\": 2000,\n \"category\": \"Transport\",\n \"description\": \"Monthly transport - September 2024\",\n \"date\": \"2024-09-20T00:00:00\",\n \"type\": \"expense\"\n}"
335
- },
336
- "url": {
337
- "raw": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space/expenses",
338
- "protocol": "https",
339
- "host": [
340
- "logicgoinfotechspaces-smart-budget-recommendation",
341
- "hf",
342
- "space"
343
- ],
344
- "path": [
345
- "expenses"
346
- ]
347
- }
348
- }
349
- },
350
- {
351
- "name": "Transport - Month 2 (Oct 2024)",
352
- "request": {
353
- "method": "POST",
354
- "header": [
355
  {
356
- "key": "Content-Type",
357
- "value": "application/json"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  }
359
- ],
360
- "body": {
361
- "mode": "raw",
362
- "raw": "{\n \"user_id\": \"{{user_id}}\",\n \"amount\": 2200,\n \"category\": \"Transport\",\n \"description\": \"Monthly transport - October 2024\",\n \"date\": \"2024-10-20T00:00:00\",\n \"type\": \"expense\"\n}"
363
- },
364
- "url": {
365
- "raw": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space/expenses",
366
- "protocol": "https",
367
- "host": [
368
- "logicgoinfotechspaces-smart-budget-recommendation",
369
- "hf",
370
- "space"
371
- ],
372
- "path": [
373
- "expenses"
374
- ]
375
- }
376
- }
377
- }
378
- ]
379
- }
380
  ],
381
  "variable": [
382
- {
383
- "key": "base_url",
384
- "value": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space",
385
- "type": "string"
386
- },
387
- {
388
- "key": "user_id",
389
- "value": "68a834c3f4694b11efedacd2",
390
- "type": "string"
391
- },
392
- {
393
- "key": "hf_token",
394
- "value": "",
395
- "type": "string"
396
- }
397
- ]
398
- }
 
 
 
 
 
 
 
 
1
  {
2
  "info": {
3
+ "_postman_id": "smart-budget-recommendation-api",
4
+ "name": "Smart Budget Recommendation API",
5
+ "description": "API collection for Smart Budget Recommendation service",
6
+ "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
 
 
 
 
 
 
 
 
 
 
7
  },
8
  "item": [
9
+ {
10
+ "name": "Health & Status",
11
+ "item": [
12
+ {
13
+ "name": "Root",
14
+ "request": {
15
+ "method": "GET",
16
+ "header": [],
17
+ "url": {
18
+ "raw": "{{base_url}}/",
19
+ "host": ["{{base_url}}"],
20
+ "path": [""]
21
+ },
22
+ "description": "Root endpoint"
23
+ }
24
+ },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  {
26
+ "name": "Health Check",
27
+ "request": {
28
+ "method": "GET",
29
+ "header": [],
30
+ "url": {
31
+ "raw": "{{base_url}}/health",
32
+ "host": ["{{base_url}}"],
33
+ "path": ["health"]
34
+ },
35
+ "description": "Health check endpoint"
36
+ }
37
  }
38
+ ]
39
+ },
40
+ {
41
+ "name": "Expenses",
42
+ "item": [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  {
44
+ "name": "Create Expense",
45
+ "request": {
46
+ "method": "POST",
47
+ "header": [
48
+ {
49
+ "key": "Content-Type",
50
+ "value": "application/json"
51
+ }
52
+ ],
53
+ "body": {
54
+ "mode": "raw",
55
+ "raw": "{\n \"user_id\": \"68a834c3f4694b11efedacd2\",\n \"amount\": 5000.0,\n \"category\": \"Groceries\",\n \"description\": \"Monthly groceries\",\n \"date\": \"2025-12-25T10:00:00Z\",\n \"type\": \"expense\"\n}"
56
+ },
57
+ "url": {
58
+ "raw": "{{base_url}}/expenses",
59
+ "host": ["{{base_url}}"],
60
+ "path": ["expenses"]
61
+ },
62
+ "description": "Create a new expense"
63
+ }
64
+ },
65
+ {
66
+ "name": "Get Expenses",
67
+ "request": {
68
+ "method": "GET",
69
+ "header": [],
70
+ "url": {
71
+ "raw": "{{base_url}}/expenses?user_id=68a834c3f4694b11efedacd2",
72
+ "host": ["{{base_url}}"],
73
+ "path": ["expenses"],
74
+ "query": [
75
+ {
76
+ "key": "user_id",
77
+ "value": "68a834c3f4694b11efedacd2"
78
+ }
79
+ ]
80
+ },
81
+ "description": "Get expenses for a user"
82
+ }
83
  }
84
+ ]
85
+ },
86
+ {
87
+ "name": "Budgets",
88
+ "item": [
89
+ {
90
+ "name": "Create Budget",
91
+ "request": {
92
+ "method": "POST",
93
+ "header": [
94
+ {
95
+ "key": "Content-Type",
96
+ "value": "application/json"
97
+ }
98
+ ],
99
+ "body": {
100
+ "mode": "raw",
101
+ "raw": "{\n \"user_id\": \"68a834c3f4694b11efedacd2\",\n \"category\": \"688c80ca990b63f0e945ecf1\",\n \"amount\": 10000.0,\n \"period\": \"monthly\",\n \"start_date\": \"2025-12-01T00:00:00Z\",\n \"end_date\": \"2025-12-31T23:59:59Z\"\n}"
102
+ },
103
+ "url": {
104
+ "raw": "{{base_url}}/budgets",
105
+ "host": ["{{base_url}}"],
106
+ "path": ["budgets"]
107
+ },
108
+ "description": "Create a new budget"
109
+ }
110
+ },
111
  {
112
+ "name": "Get Budgets",
113
+ "request": {
114
+ "method": "GET",
115
+ "header": [],
116
+ "url": {
117
+ "raw": "{{base_url}}/budgets?user_id=68a834c3f4694b11efedacd2",
118
+ "host": ["{{base_url}}"],
119
+ "path": ["budgets"],
120
+ "query": [
121
+ {
122
+ "key": "user_id",
123
+ "value": "68a834c3f4694b11efedacd2"
124
+ }
125
+ ]
126
+ },
127
+ "description": "Get budgets for a user"
128
+ }
129
  }
130
+ ]
131
+ },
132
+ {
133
+ "name": "Recommendations",
134
+ "item": [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  {
136
+ "name": "Get Budget Recommendations",
137
+ "request": {
138
+ "method": "GET",
139
+ "header": [],
140
+ "url": {
141
+ "raw": "{{base_url}}/recommendations/68a834c3f4694b11efedacd2?month=1&year=2026",
142
+ "host": ["{{base_url}}"],
143
+ "path": ["recommendations", "68a834c3f4694b11efedacd2"],
144
+ "query": [
145
+ {
146
+ "key": "month",
147
+ "value": "1",
148
+ "description": "Target month (1-12), optional"
149
+ },
150
+ {
151
+ "key": "year",
152
+ "value": "2026",
153
+ "description": "Target year, optional"
154
+ }
155
+ ]
156
+ },
157
+ "description": "Get smart budget recommendations for a user based on past spending behavior"
158
+ }
159
+ },
160
+ {
161
+ "name": "Check and Get Recommendations",
162
+ "request": {
163
+ "method": "POST",
164
+ "header": [
165
+ {
166
+ "key": "Content-Type",
167
+ "value": "application/json"
168
+ }
169
+ ],
170
+ "body": {
171
+ "mode": "raw",
172
+ "raw": "{\n \"user_id\": \"68a834c3f4694b11efedacd2\",\n \"category_id\": \"688c80ca990b63f0e945ecf1\"\n}"
173
+ },
174
+ "url": {
175
+ "raw": "{{base_url}}/recommendations/check?month=1&year=2026",
176
+ "host": ["{{base_url}}"],
177
+ "path": ["recommendations", "check"],
178
+ "query": [
179
+ {
180
+ "key": "month",
181
+ "value": "1",
182
+ "description": "Target month (1-12), optional"
183
+ },
184
+ {
185
+ "key": "year",
186
+ "value": "2026",
187
+ "description": "Target year, optional"
188
+ }
189
+ ]
190
+ },
191
+ "description": "Check if user has previous data for a category and return recommendations if available"
192
+ }
193
  }
194
+ ]
195
+ },
196
+ {
197
+ "name": "Category Expenses",
198
+ "item": [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  {
200
+ "name": "Get Category Expenses",
201
+ "request": {
202
+ "method": "GET",
203
+ "header": [],
204
+ "url": {
205
+ "raw": "{{base_url}}/category-expenses/68a834c3f4694b11efedacd2?months=3",
206
+ "host": ["{{base_url}}"],
207
+ "path": ["category-expenses", "68a834c3f4694b11efedacd2"],
208
+ "query": [
209
+ {
210
+ "key": "months",
211
+ "value": "3",
212
+ "description": "Number of months to analyze (default: 3)"
213
+ }
214
+ ]
215
+ },
216
+ "description": "Get average expenses by category for the past N months"
217
+ }
218
  }
219
+ ]
220
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  ],
222
  "variable": [
223
+ {
224
+ "key": "base_url",
225
+ "value": "https://logicgoinfotechspaces-smart-budget-recommendation.hf.space",
226
+ "type": "string",
227
+ "description": "Hugging Face Space URL (lowercase, hyphens). Check your Space page for the exact URL. For local development, use: http://localhost:7860"
228
+ },
229
+ {
230
+ "key": "hf_token",
231
+ "value": "",
232
+ "type": "string",
233
+ "description": "Hugging Face Access Token (optional, only if space is private). Get from: https://huggingface.co/settings/tokens"
234
+ }
235
+ ],
236
+ "auth": {
237
+ "type": "bearer",
238
+ "bearer": [
239
+ {
240
+ "key": "token",
241
+ "value": "{{hf_token}}",
242
+ "type": "string"
243
+ }
244
+ ]
245
+ }
246
+ }
app/main.py CHANGED
@@ -183,36 +183,6 @@ async def get_budgets(user_id: str):
183
  del budget["_id"]
184
  return budgets
185
 
186
- @app.get("/recommendations/{user_id}", response_model=List[BudgetRecommendation])
187
- async def get_budget_recommendations(user_id: str, month: Optional[int] = None, year: Optional[int] = None):
188
- """
189
- Get smart budget recommendations for a user based on past spending behavior.
190
-
191
- Example response:
192
- {
193
- "budget_name": "Groceries",
194
- "average_expense": 3800,
195
- "recommended_budget": 4000,
196
- "reason": "Your average monthly grocery expense is Rs.3,800. We suggest setting your budget to Rs.4,000 for next month.",
197
- "confidence": 0.85,
198
- "action": "increase"
199
- }
200
- """
201
- if not month or not year:
202
- # Default to next month
203
- next_month = datetime.now().replace(day=1) + timedelta(days=32)
204
- month = next_month.month
205
- year = next_month.year
206
-
207
- recommendations = recommender.get_recommendations(user_id, month, year)
208
- return recommendations
209
-
210
- @app.get("/category-expenses/{user_id}", response_model=List[CategoryExpense])
211
- async def get_category_expenses(user_id: str, months: int = 3):
212
- """Get average expenses by category for the past N months"""
213
- category_expenses = recommender.get_category_averages(user_id, months)
214
- return category_expenses
215
-
216
  @app.post("/recommendations/check", response_model=RecommendationResponse)
217
  async def check_and_get_recommendations(request: RecommendationRequest, month: Optional[int] = None, year: Optional[int] = None):
218
  """
@@ -267,6 +237,37 @@ async def check_and_get_recommendations(request: RecommendationRequest, month: O
267
  message=f"User does not have previous data for category_id: {request.category_id}. Please create a budget or add expenses for this category first."
268
  )
269
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  if __name__ == "__main__":
271
  import uvicorn
272
  uvicorn.run(app, host="0.0.0.0", port=8000)
 
183
  del budget["_id"]
184
  return budgets
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  @app.post("/recommendations/check", response_model=RecommendationResponse)
187
  async def check_and_get_recommendations(request: RecommendationRequest, month: Optional[int] = None, year: Optional[int] = None):
188
  """
 
237
  message=f"User does not have previous data for category_id: {request.category_id}. Please create a budget or add expenses for this category first."
238
  )
239
 
240
+ @app.get("/recommendations/{user_id}", response_model=List[BudgetRecommendation])
241
+ async def get_budget_recommendations(user_id: str, month: Optional[int] = None, year: Optional[int] = None):
242
+ """
243
+ Get smart budget recommendations for a user based on past spending behavior.
244
+
245
+ Example response:
246
+ {
247
+ "category": "Groceries",
248
+ "category_id": "688c80ca990b63f0e945ecf1",
249
+ "average_expense": 3800,
250
+ "recommended_budget": 4000,
251
+ "reason": "Your average monthly grocery expense is Rs.3,800. We suggest setting your budget to Rs.4,000 for next month.",
252
+ "confidence": 0.85,
253
+ "action": "increase"
254
+ }
255
+ """
256
+ if not month or not year:
257
+ # Default to next month
258
+ next_month = datetime.now().replace(day=1) + timedelta(days=32)
259
+ month = next_month.month
260
+ year = next_month.year
261
+
262
+ recommendations = recommender.get_recommendations(user_id, month, year)
263
+ return recommendations
264
+
265
+ @app.get("/category-expenses/{user_id}", response_model=List[CategoryExpense])
266
+ async def get_category_expenses(user_id: str, months: int = 3):
267
+ """Get average expenses by category for the past N months"""
268
+ category_expenses = recommender.get_category_averages(user_id, months)
269
+ return category_expenses
270
+
271
  if __name__ == "__main__":
272
  import uvicorn
273
  uvicorn.run(app, host="0.0.0.0", port=8000)