banao-tech commited on
Commit
716ecfd
Β·
verified Β·
1 Parent(s): 8b32013

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -0
app.py CHANGED
@@ -175,6 +175,95 @@ async def log_commitment(data: CommitmentIn):
175
  # HEALTH
176
  # ─────────────────────────────────────────────
177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  @app.get("/health", summary="Health check")
179
  async def health():
180
  return JSONResponse({"status": "ok"})
 
175
  # HEALTH
176
  # ─────────────────────────────────────────────
177
 
178
+
179
+ # ─────────────────────────────────────────────
180
+ # INTERN MANAGEMENT β€” GET / UPDATE / DELETE
181
+ # ─────────────────────────────────────────────
182
+
183
+ class InternUpdate(BaseModel):
184
+ name: str | None = None
185
+ stage: str | None = None
186
+ department: str | None = None
187
+ channel_id: str | None = None
188
+ ft_slack_id: str | None = None
189
+ hr_slack_id: str | None = None
190
+ week0_start_date: str | None = None
191
+ status: str | None = None
192
+ cohort_id: str | None = None
193
+
194
+
195
+ @app.get("/interns", summary="List all interns β€” filter by department")
196
+ async def get_interns(department: str = None):
197
+ """
198
+ Returns all active interns.
199
+ Optional query param: ?department=ai
200
+ Example: /interns?department=ai
201
+ """
202
+ try:
203
+ candidates = sheets.get_active_candidates()
204
+ if department:
205
+ candidates = [
206
+ c for c in candidates
207
+ if c.get("department", "").lower() == department.lower()
208
+ ]
209
+ return JSONResponse({"ok": True, "count": len(candidates), "interns": candidates})
210
+ except Exception as e:
211
+ return JSONResponse({"error": str(e)}, status_code=500)
212
+
213
+
214
+ @app.get("/interns/{candidate_id}", summary="Get a single intern by candidate ID")
215
+ async def get_intern(candidate_id: str):
216
+ try:
217
+ candidate = sheets.get_candidate_by_id(candidate_id)
218
+ if not candidate:
219
+ return JSONResponse({"error": "Intern not found"}, status_code=404)
220
+ return JSONResponse({"ok": True, "intern": candidate})
221
+ except Exception as e:
222
+ return JSONResponse({"error": str(e)}, status_code=500)
223
+
224
+
225
+ @app.patch("/interns/{candidate_id}", summary="Update intern fields")
226
+ async def update_intern(candidate_id: str, data: InternUpdate):
227
+ """
228
+ Update one or more fields of an intern.
229
+ Only pass the fields you want to change.
230
+ """
231
+ try:
232
+ candidate = sheets.get_candidate_by_id(candidate_id)
233
+ if not candidate:
234
+ return JSONResponse({"error": "Intern not found"}, status_code=404)
235
+
236
+ updates = data.dict(exclude_none=True)
237
+ if not updates:
238
+ return JSONResponse({"error": "No fields to update"}, status_code=400)
239
+
240
+ for field, value in updates.items():
241
+ sheets.update_candidate_field(candidate_id, field, value)
242
+
243
+ return JSONResponse({"ok": True, "updated": updates})
244
+ except Exception as e:
245
+ return JSONResponse({"error": str(e)}, status_code=500)
246
+
247
+
248
+ @app.delete("/interns/{candidate_id}", summary="Remove an intern from the pipeline")
249
+ async def delete_intern(candidate_id: str):
250
+ """
251
+ Marks the intern as eliminated and inactive.
252
+ Does not delete the row β€” preserves audit trail.
253
+ """
254
+ try:
255
+ candidate = sheets.get_candidate_by_id(candidate_id)
256
+ if not candidate:
257
+ return JSONResponse({"error": "Intern not found"}, status_code=404)
258
+
259
+ sheets.update_candidate_field(candidate_id, "status", "eliminated")
260
+ return JSONResponse({
261
+ "ok": True,
262
+ "message": f"{candidate.get('name')} removed from pipeline. Row preserved for audit."
263
+ })
264
+ except Exception as e:
265
+ return JSONResponse({"error": str(e)}, status_code=500)
266
+
267
  @app.get("/health", summary="Health check")
268
  async def health():
269
  return JSONResponse({"status": "ok"})