Skip to content

Commit b4b7a7d

Browse files
author
teds-lin
committed
[新增] 實作 end_game endpoint 將會呼叫大平台的"結束遊戲"API
1 parent f865ec5 commit b4b7a7d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

backend/app/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,40 @@ def player_status():
150150
return jsonify({"message": "gameRoomID does not exist"}), 400
151151

152152

153+
@app.route("/endgame", methods=["DELETE"])
154+
@jwt_required
155+
def end_game(current_user, nickname):
156+
data = request.json
157+
gameRoomID = data.get("gameRoomID")
158+
if not gameRoomID:
159+
return jsonify({"message": "gameRoomID is required"}), 400
160+
161+
token = None
162+
if "Authorization" in request.headers:
163+
auth_header = request.headers["Authorization"]
164+
try:
165+
token = auth_header.split(" ")[1]
166+
except IndexError:
167+
return jsonify({"message": "Invalid token format"}), 401
168+
169+
headers = {"Authorization": f"Bearer {token}"}
170+
response = requests.post(
171+
f"https://api.gaas.waterballsa.tw/rooms/{gameRoomID}:endGame",
172+
headers=headers,
173+
)
174+
if response.status_code != 204:
175+
return (
176+
jsonify(
177+
{
178+
"message": f"Failed to end game on GaaS platform: {response.status_code}",
179+
}
180+
),
181+
400,
182+
)
183+
else:
184+
return jsonify({"message": "Game ended successfully"}), 204
185+
186+
153187
@app.route("/health", methods=["GET"])
154188
def health_check():
155189
return jsonify({"status": "healthy"}), 200

0 commit comments

Comments
 (0)