Mishut-17 commited on
Commit
c79ef22
·
verified ·
1 Parent(s): fe14457

Upload 2 files

Browse files
Files changed (2) hide show
  1. database.py +11 -0
  2. main.py +8 -0
database.py CHANGED
@@ -150,6 +150,17 @@ class DatabaseManager:
150
  conn.commit()
151
  return cursor.rowcount > 0
152
 
 
 
 
 
 
 
 
 
 
 
 
153
  def delete_item(self, filename):
154
  with self.get_connection() as conn:
155
  cursor = conn.cursor()
 
150
  conn.commit()
151
  return cursor.rowcount > 0
152
 
153
+ def resolve_lost_requests(self, student_email):
154
+ with self.get_connection() as conn:
155
+ cursor = conn.cursor()
156
+ cursor.execute("""
157
+ UPDATE items
158
+ SET status = 'resolved'
159
+ WHERE reported_by = ? AND status = 'lost'
160
+ """, (student_email,))
161
+ conn.commit()
162
+ return cursor.rowcount
163
+
164
  def delete_item(self, filename):
165
  with self.get_connection() as conn:
166
  cursor = conn.cursor()
main.py CHANGED
@@ -294,6 +294,14 @@ def update_item_status(filename: str, req: StatusRequest, user: dict = Depends(g
294
  item["handed_over_by"] = user["email"]
295
  break
296
 
 
 
 
 
 
 
 
 
297
  # We do not need to save matcher since we don't save metadata.json anymore
298
  # but let's just trigger sync
299
  storage.upload_data(BASE_DIR)
 
294
  item["handed_over_by"] = user["email"]
295
  break
296
 
297
+ # Automatically waive off any 'lost' requests filed by this student
298
+ if req.status == "claimed" and req.claimed_by:
299
+ resolved_count = db.resolve_lost_requests(req.claimed_by)
300
+ if resolved_count > 0:
301
+ for item in matcher.metadata:
302
+ if item.get("status") == "lost" and item.get("reported_by") == req.claimed_by:
303
+ item["status"] = "resolved"
304
+
305
  # We do not need to save matcher since we don't save metadata.json anymore
306
  # but let's just trigger sync
307
  storage.upload_data(BASE_DIR)