Skip to content

Commit

Permalink
/status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mcaine committed Oct 25, 2020
1 parent 764b782 commit 40bb5c6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/main/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"axios": "^0.21.0",
"bootstrap-4-react": "0.0.59",
"jquery": "^3.5.1",
"react": "^17.0.1",
Expand Down
22 changes: 21 additions & 1 deletion src/main/frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './App.css';

import React, { Component } from 'react';
import { w3cwebsocket as W3CWebSocket } from "websocket";

import axios from 'axios';
import { Table, Container } from "react-bootstrap"

import ChanceMeter from "./ChanceMeter";
Expand Down Expand Up @@ -39,6 +39,26 @@ class App extends Component {
console.log('New isForecast = ' + newData.isForecast);
this.setState({ chance: newData.chance, margin:newData.margin, votes: newData.votes, isForecast: newData.isForecast});
};

axios
.get(`/status`)
.then(res => {
if (res.status === 200) {
console.log('Received status response!! ' + res);
let newData = res.data;
console.log('New Chance = ' + newData.chance);
console.log('New Margin = ' + newData.margin);
console.log('New votes = ' + newData.votes);
console.log('New isForecast = ' + newData.isForecast);
this.setState({ chance: newData.chance, margin:newData.margin, votes: newData.votes, isForecast: newData.isForecast});
} else {
console.log("status request got response status " + res.status);
}
})
.catch(function(error) {
console.log(error)
});

}

render() {
Expand Down
12 changes: 12 additions & 0 deletions src/main/frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2684,6 +2684,13 @@ axe-core@^3.5.4:
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-3.5.5.tgz#84315073b53fa3c0c51676c588d59da09a192227"
integrity sha512-5P0QZ6J5xGikH780pghEdbEKijCTrruK9KxtPZCFWUpef0f6GipO+xEZ5GKCb020mmqgbiNO6TcA55CriL784Q==

axios@^0.21.0:
version "0.21.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.0.tgz#26df088803a2350dff2c27f96fef99fe49442aca"
integrity sha512-fmkJBknJKoZwem3/IKSSLpkdNXZeBu5Q7GA/aRsr2btgrptmSCxi2oFjZHqGdK9DoTil9PIHlPIZw2EcRJXRvw==
dependencies:
follow-redirects "^1.10.0"

axobject-query@^2.1.2:
version "2.2.0"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be"
Expand Down Expand Up @@ -5324,6 +5331,11 @@ follow-redirects@^1.0.0:
dependencies:
debug "^3.0.0"

follow-redirects@^1.10.0:
version "1.13.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db"
integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==

for-in@^0.1.3:
version "0.1.8"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.8.tgz#d8773908e31256109952b1fdb9b3fa867d2775e1"
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/cspam/pointer/PointerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PointerController {
private MeterData meterData = new MeterData(50, 0, 270, true);

@GetMapping("/status")
public String status() {
public synchronized String status() {
return meterData.toString();
}

Expand All @@ -36,13 +36,8 @@ public synchronized void update(
if ((votes < 0 && votes > -270) || (votes >=0 && votes < 270)) {
throw new RuntimeException("Votes should be in the range -540 to -270 (for Biden), 270 to 540 (for Trump)");
}
/*
if (votes < 0) {
votes = 540 + votes;
}
*/

meterData = new MeterData(chance, margin, votes, isForecast);
this.meterData = meterData;
webSocketHandler.sendUpdate(meterData);
}
}

0 comments on commit 40bb5c6

Please sign in to comment.