Skip to content

Commit 7502958

Browse files
Merge branch 'feat/new-api'
2 parents d101e2a + e503c94 commit 7502958

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "data-web-app",
33
"version": "1.0.0",
44
"description": "Web app for interacting with Jay's data",
5-
"main": "index.js",
5+
"main": "server.js",
66
"proxy": "https://data.jayherron.org",
77
"homepage": ".",
88
"scripts": {

src/App/API.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import base64 from "base-64";
22
import formatISO from "date-fns/formatISO";
33

44
export async function getAuthToken(username, password) {
5-
let response = await fetch("/auth/token", {
5+
let url = "/auth/token"
6+
let response = await fetch(url, {
67
method: 'GET',
78
headers: {
89
'Authorization': 'Basic ' + base64.encode(username + ":" + password)
9-
}
10+
},
11+
1012
})
1113
if (response.ok) {
1214
return await response.json();
@@ -15,9 +17,13 @@ export async function getAuthToken(username, password) {
1517
}
1618
}
1719

18-
export async function getRecsTag(tag, token) {
20+
export async function getRecs(tag, token) {
1921
try {
20-
let response = await fetch("/recs/tag/"+ tag, {
22+
var url = "/recs"
23+
if (tag != "") {
24+
url = url + "?" + new URLSearchParams({tag: tag})
25+
}
26+
let response = await fetch(url, {
2127
method: 'GET',
2228
headers: {
2329
'Authorization': 'Bearer ' + token
@@ -31,7 +37,11 @@ export async function getRecsTag(tag, token) {
3137

3238
export async function getHis(id, start, end, token) {
3339
try {
34-
let response = await fetch("/his/" + id + "?start=" + start + "&end=" + end, {
40+
let url = `/recs/${id}/history?` + new URLSearchParams({
41+
start: start,
42+
end: end,
43+
})
44+
let response = await fetch(url, {
3545
method: 'GET',
3646
headers: {
3747
'Authorization': 'Bearer ' + token
@@ -50,7 +60,8 @@ export async function postHis(id, ts, value, token) {
5060
ts: formatISO(ts), // We use date-fns implementation here to avoid milliseconds (Swift hates them and me)
5161
value: value
5262
};
53-
await fetch("/his/" + id, {
63+
let url = `/rec/${id}/history`
64+
await fetch(url, {
5465
method: 'POST',
5566
headers: {
5667
'Authorization': 'Bearer ' + token,

src/App/utility-input/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { DatePicker } from '@mui/x-date-pickers/DatePicker';
2020

2121
import Chart from './chart';
2222
import Input from './input';
23-
import { getHis, getRecsTag } from "../API";
23+
import { getHis, getRecs } from "../API";
2424

2525
export default class UtilityInput extends React.Component {
2626

@@ -47,7 +47,7 @@ export default class UtilityInput extends React.Component {
4747
}
4848

4949
async fetchPoints() {
50-
let points = await getRecsTag("siteMeter", this.props.token);
50+
let points = await getRecs("siteMeter", this.props.token);
5151
this.setState({...this.state, points: points});
5252
}
5353

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createRoot } from 'react-dom/client';
22
import "./index.css";
3-
import App from "./App";
3+
import App from "./app";
44

55
const root = createRoot(document.getElementById('root'));
66
root.render(<App />);

0 commit comments

Comments
 (0)