-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlobby_api.py
More file actions
37 lines (31 loc) · 1.26 KB
/
lobby_api.py
File metadata and controls
37 lines (31 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from flask import Flask, request, jsonify
import json
import redis
app = Flask(__name__)
r = redis.Redis(host='localhost', port=6379, db=0)
@app.route('/lobbies/<lobby_id>', methods=['POST'])
def add_lobby(lobby_id):
data = request.get_json()
r.set(f"lobby:{lobby_id}", json.dumps(data))
return jsonify({"message": "Lobby data added successfully!"}), 200
@app.route('/lobbies/<lobby_id>', methods=['GET'])
def get_lobby(lobby_id):
lobby_data = r.get(f"lobby:{lobby_id}")
if lobby_data:
lobby = json.loads(lobby_data)
return jsonify(lobby), 200
else:
return jsonify({"status": "error"}), 400
@app.route('/lobby_seekers/<lobby_id>', methods=['POST'])
def post_seekers(lobby_id):
data = request.get_json()
r.set(f"lobby_seekers:{lobby_id}", json.dumps(data))
return jsonify({"message": "Lobby seeker data added successfully!"}), 200
@app.route('/lobby_seekers/<lobby_id>', methods=['GET'])
def get_seekers(lobby_id):
seeker_data = r.get(f"lobby_seekers:{lobby_id}")
if seeker_data:
seekers = json.loads(seeker_data)
return jsonify(seekers), 200
else:
return jsonify({"status": "error"}), 400