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

Implementing new methods and change to submit

Kirk Trombley 5 жил өмнө
parent
commit
6ad118087d

+ 51 - 17
client/src/domain/apiMethods.js

@@ -1,4 +1,4 @@
-const API_BASE = "https://hiram.services/terrassumptions/api";
+const API_BASE = "http://localhost:5000";
 
 export const getStatus = async () => {
     try {
@@ -12,6 +12,20 @@ export const getStatus = async () => {
     }
 }
 
+export const checkScore = async (point1, point2) => {
+    const res = await fetch(`${API_BASE}/score`, {
+        method: "POST",
+        headers: {
+            "Content-Type": "application/json",
+        },
+        body: JSON.stringify({ point1, point2 }),
+    });
+    if (!res.ok) {
+        throw Error(res.statusText);
+    }
+    return await res.json();
+}
+
 export const createGame = async (timer, rounds, onlyAmerica) => {
     const res = await fetch(`${API_BASE}/game`, {
         method: "PUT",
@@ -35,6 +49,40 @@ export const gameInfo = async (gameId) => {
     return await res.json();
 }
 
+export const gameConfig = async (gameId) => {
+    const res = await fetch(`${API_BASE}/game/${gameId}/config`);
+    if (!res.ok) {
+        throw Error(res.statusText);
+    }
+    return await res.json();
+}
+
+export const gameCoords = async (gameId) => {
+    const res = await fetch(`${API_BASE}/game/${gameId}/coords`);
+    if (!res.ok) {
+        throw Error(res.statusText);
+    }
+    return await res.json();
+}
+
+export const getPlayers = async (gameId) => {
+    const res = await fetch(`${API_BASE}/game/${gameId}/players`);
+    if (!res.ok) {
+        throw Error(res.statusText);
+    }
+    const { players } = await res.json();
+    return players;
+}
+
+export const getLinkedGame = async (gameId) => {
+    const res = await fetch(`${API_BASE}/game/${gameId}/linked`);
+    if (!res.ok) {
+        throw Error(res.statusText);
+    }
+    const { linkedGame } = await res.json();
+    return linkedGame;
+}
+
 export const linkGame = async (gameId, linkedGame) => {
     const res = await fetch(`${API_BASE}/game/${gameId}/linked`, {
         method: "POST",
@@ -74,28 +122,14 @@ export const getCurrentRound = async (gameId, playerId) => {
     return await res.json();
 }
 
-export const sendGuess = async (gameId, playerId, round, point) => {
+export const sendGuess = async (gameId, playerId, round, point, timeRemaining) => {
     const res = await fetch(`${API_BASE}/game/${gameId}/guesses/${round}`, {
         method: "POST",
         headers: {
             "Authorization": `Player ${playerId}`,
             "Content-Type": "application/json",
         },
-        body: JSON.stringify(point),
-    });
-    if (!res.ok) {
-        throw Error(res.statusText);
-    }
-    return await res.json();
-}
-
-export const checkScore = async (point1, point2) => {
-    const res = await fetch(`${API_BASE}/score`, {
-        method: "POST",
-        headers: {
-            "Content-Type": "application/json",
-        },
-        body: JSON.stringify({ point1, point2 }),
+        body: JSON.stringify({ timeRemaining, ...point }),
     });
     if (!res.ok) {
         throw Error(res.statusText);

+ 3 - 1
client/src/domain/gameStore.js

@@ -88,11 +88,13 @@ export const [
     const playerId = get.playerId();
     const roundNum = get.currentRound();
     const targetPoint = get.targetPoint();
+    const roundSeconds = get.roundSeconds();
     const { score, totalScore } = await sendGuess(
       gameId,
       playerId,
       roundNum,
-      selectedPoint || { timeout: true }
+      selectedPoint || { timeout: true },
+      roundSeconds
     );
     set({
       lastRound: {