@@ -43,20 +43,25 @@ def main_menu():
4343
4444@app .route ('/get_participants' , methods = ['GET' ])
4545def get_parts ():
46- participants = get_participants () # Replace with your function to fetch participants
46+ online_participants_ids = get_participants () # Replace with your function to fetch participants
47+ all_participants = get_participants_for_view ()
4748 # participants = None
4849 # if not participants:
4950 # participants = PARTICIPANTS
50- if len (participants ) > 0 and not isinstance (participants [0 ], dict ):
51- # Add some dummy data
52- participants = [{"id" : i , # Convert i to int
53- "firstName" : f"Participant { i } " ,
54- "lastName" : f"Lastname { i } " ,
55- "age" : 20 , # Convert i to int before adding
56- "gender" : "Male" ,
57- "email" : f"{ i } @gmail.com" ,
58- "phone" : f"1234567{ i } " } for i in participants ]
59- return jsonify (participants )
51+
52+ if len (online_participants_ids ) > 0 and not isinstance (online_participants_ids [0 ], dict ):
53+ # make every id in the list, from a '003' to '3'
54+ online_participants_ids = [int (x ) for x in online_participants_ids ]
55+
56+ online_participants = []
57+ for part in all_participants :
58+ # convert from string to dict
59+ part = json .loads (part )
60+ if part ['pid' ] in online_participants_ids :
61+ online_participants .append (part )
62+
63+ return jsonify (online_participants )
64+ return jsonify (all_participants )
6065
6166
6267@app .route ('/lobbies' , methods = ['GET' ])
@@ -78,19 +83,18 @@ def create_lobby_action():
7883 selected_participants = request .form .getlist ('selected_participants' ) # Get all selected participants
7984 if len (selected_participants ) != 2 : # Ensure exactly two participants are selected
8085 return "Exactly two participants must be selected to create a lobby." , 400
81-
86+
8287 lobby_id = create_lobby (selected_participants )
8388 if not lobby_id :
8489 return "Failed to create lobby." , 500
85-
90+
8691 return redirect (url_for ('lobby' , lobby_id = lobby_id , selected_participants = "," .join (selected_participants )))
8792
8893 except Exception as e :
8994 Logger .log_error (f"Error creating lobby: { e } " )
9095 return f"Error: { e } " , 500
9196
9297
93-
9498@app .route ('/delete_lobby' , methods = ['GET' ])
9599def delete_lobby_action ():
96100 lobby_id = request .args .get ('lobby_id' )
@@ -195,6 +199,8 @@ def stop_game_route():
195199 except Exception as e :
196200 Logger .log_error (f"Unexpected error in /stop_game: { e } " )
197201 return jsonify ({"status" : "error" , "message" : "Internal server error" }), 500
202+
203+
198204@app .route ('/get_lobby' , methods = ['POST' ])
199205def get_lobby_route ():
200206 lobby_id = request .json .get ('lobby_id' )
@@ -212,7 +218,6 @@ def get_lobby_route():
212218
213219@app .route ('/update_session_order' , methods = ['POST' ])
214220def update_session_order ():
215-
216221 data = request .json
217222 lobby_id = data .get ('lobby_id' )
218223 session_order = data .get ('session_order' )
@@ -243,8 +248,6 @@ def get_sessions_route():
243248 return jsonify ({"status" : "error" , "message" : "Internal server error" }), 500
244249
245250
246-
247-
248251@app .route ('/add_session' , methods = ['POST' ])
249252def add_session ():
250253 data = request .json
@@ -296,6 +299,7 @@ def game_type_from_name():
296299 game_type = game_type_name
297300 return jsonify ({'status' : 'success' , 'gameType' : game_type })
298301
302+
299303@app .route ('/delete_session' , methods = ['POST' ])
300304def delete_session_route ():
301305 # return jsonify({"status": "success"})
@@ -326,6 +330,7 @@ def participants_menu():
326330
327331 return render_template ('participants.html' , participants = participants )
328332
333+
329334@app .route ('/add_participant' , methods = ['POST' ])
330335def add_part ():
331336 try :
@@ -347,21 +352,21 @@ def add_part():
347352def remove_part ():
348353 try :
349354 if remove_participant (request .json .get ('id' )):
350- return jsonify ({"success" :True })
355+ return jsonify ({"success" : True })
351356 return jsonify ({"status" : "error" , "message" : "Failed to remove participant" }), 500
352357 except Exception as e :
353358 Logger .log_error (f"Error removing participant: { e } " )
354359 return jsonify ({"status" : "error" , "message" : "Internal server error" }), 500
355360
356361
357-
358362###################### OPERATORS ######################
359363@app .route ('/operators' , methods = ['GET' ])
360364def operators_menu ():
361365 if 'username' not in session :
362366 return redirect (url_for ('login' ))
363367 return render_template ('operators.html' )
364368
369+
365370@app .route ('/add_operator' , methods = ['POST' ])
366371def add_oper ():
367372 # fetch(url, {
@@ -375,13 +380,17 @@ def add_oper():
375380 return add_operator (username , password )
376381 # return jsonify({"success":True})
377382
383+
378384@app .route ('/get_operators' , methods = ['GET' ])
379385def get_opers ():
380386 return get_operators ()
387+
388+
381389@app .route ('/remove_operator' , methods = ['DELETE' ])
382390def remove_oper ():
383391 return remove_operator (request .json .get ('username' ))
384392
393+
385394# @app.route('/edit_operator', methods=['PUT'])
386395# def edit_operator():
387396# return jsonify({"success":True})
0 commit comments