Эх сурвалжийг харах

Updating the API to supply just the target on a current round endpoint

Kirk Trombley 5 жил өмнө
parent
commit
4b1697f8d4

+ 7 - 8
README.md

@@ -28,6 +28,7 @@ GET /game/{ID}
         "gameId": string,
         "creator": string,
         "timer": number,
+        "numRounds": number,
         "coords": {
             "1": {
                 "lat": number,
@@ -52,17 +53,15 @@ GET /game/{ID}
 POST /game/{ID}/join
     Header Authorization: Name string
     Returns 201 vs 401
-GET /game/{ID}/guesses
+GET /game/{ID}/current
     Header Authorization: Name string
     Returns {
         "currentRound": string || null,
-        "guesses": {
-            "1": {
-                "lat": number,
-                "lng": number,
-                "score": number
-            }, ...
-        }
+        "coord": {
+            "lat": number,
+            "lng": number,
+        } || null,
+        "timer": number
     }
 POST /game/{ID}/guesses/{round}
     Header Authorization: Name string

+ 3 - 5
client/src/components/screens/GamePanel/useRoundInfo.jsx

@@ -1,5 +1,5 @@
 import { useState, useEffect } from 'react';
-import { gameInfo, getGuesses } from "../../../domain/GGSHService";
+import { getCurrentRound } from "../../../domain/GGSHService";
 
 export default (gameId, playerName) => {
   const [finished, setFinished] = useState(false);
@@ -7,11 +7,9 @@ export default (gameId, playerName) => {
 
   useEffect(() => {
     const setup = async () => {
-      const { currentRound } = await getGuesses(gameId, playerName);
+      const { currentRound, coord, timer } = await getCurrentRound(gameId, playerName);
       if (currentRound) {
-        const { coords, timer } = await gameInfo(gameId);
-        const targetPoint = coords[currentRound];
-        setRoundInfo({ currentRound, targetPoint, roundSeconds: timer });
+        setRoundInfo({ currentRound, targetPoint: coord, roundSeconds: timer });
       } else {
         setFinished(true);
       }

+ 3 - 3
client/src/domain/GGSHService.js

@@ -1,4 +1,4 @@
-const API_BASE = "https://kirkleon.ddns.net/terrassumptions/api";
+const API_BASE = "http://localhost:5000";
 
 export const getStatus = async () => {
     try {
@@ -48,8 +48,8 @@ export const joinGame = async (gameId, name) => {
     }
 }
 
-export const getGuesses = async (gameId, name) => {
-    const res = await fetch(`${API_BASE}/game/${gameId}/guesses`, {
+export const getCurrentRound = async (gameId, name) => {
+    const res = await fetch(`${API_BASE}/game/${gameId}/current`, {
         headers: {
             "Authorization": `Name ${name}`
         },

+ 1 - 1
server/app.py

@@ -30,7 +30,7 @@ def version():
     """
     Return the version of the API and a status message, "healthy"
     """
-    return jsonify({"version": "1", "status": "healthy"})
+    return jsonify({"version": "2", "status": "healthy"})
 
 
 if __name__ == "__main__":

+ 15 - 4
server/game_api.py

@@ -64,12 +64,23 @@ def join(game_id):
     return "", 201
 
 
-@game.route("/<game_id>/guesses")
-def guesses(game_id):
+@game.route("/<game_id>/current")
+def current_round(game_id):
+    g = require_game(game_id)
     gs = require_guess_set(game_id)
+    cur_rnd = gs.get_current_round()
+    if cur_rnd is None:
+        coord = None
+    else:
+        (lat, lng) = g.coord_set.get_coord(cur_rnd)
+        coord = {
+            "lat": float(lat),
+            "lng": float(lng),
+        }
     return jsonify({
-        "currentRound": gs.get_current_round(),
-        "guesses": gs.to_dict(),
+        "currentRound": cur_rnd,
+        "coord": coord,
+        "timer": g.timer,
     })