Skip to content

Commit

Permalink
feat: Added missing API integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
bahattincinic committed May 27, 2024
1 parent 1cea61e commit 5cb96a4
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 13 deletions.
22 changes: 11 additions & 11 deletions api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ func (a *API) setupHandlers() {

{
dash := api.Group("/dashboards")
// Dashboard
dash.GET("", a.listDashboards)
dash.POST("", a.createDashboard)
dash.GET("/:id", a.getDashboard, a.setDashboardMiddleware())
dash.PUT("/:id", a.updateDashboard, a.setDashboardMiddleware())
dash.DELETE("/:id", a.deleteDashboard, a.setDashboardMiddleware())
dash.POST("/:id/run", a.runQuery, a.setDashboardMiddleware())
// Component
dash.GET("/:id/components", a.getDashboardComponents, a.setDashboardMiddleware())
dash.POST("/:id/components", a.createComponent, a.setDashboardMiddleware())
dash.PUT("/:id/components/:cpid", a.updateComponent,
a.setDashboardMiddleware(), a.setComponentMiddleware())
dash.DELETE("/:id/components/:cpid", a.deleteComponent,
a.setDashboardMiddleware(), a.setComponentMiddleware())
dash.POST("/:id/components/:cpid/run", a.runComponent,
a.setDashboardMiddleware(), a.setComponentMiddleware())
dash.POST("/:id/run", a.runDashboard, a.setDashboardMiddleware())

}

{
comp := api.Group("/dashboards/:id/components", a.setDashboardMiddleware())
comp.GET("", a.getDashboardComponents)
comp.POST("", a.createComponent)
comp.PUT("/:cpid", a.updateComponent, a.setComponentMiddleware())
comp.DELETE("/:cpid", a.deleteComponent, a.setComponentMiddleware())
comp.POST("/:cpid/run", a.runComponent, a.setComponentMiddleware())
}

a.ec.GET("/*", a.serveStatic)
Expand Down
53 changes: 53 additions & 0 deletions ui/src/services/activities.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,56 @@ export async function fetchActivities(page) {

return await response.json();
}

export async function getActivity(id) {
const endpoint = `${API_BASE_URL}/activities/${id}`;

const response = await fetch(endpoint, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error('Could not get activity');
}

return await response.json();
}

export async function getActivityGPX(id, accessToken) {
const endpoint = `${API_BASE_URL}/activities/${id}/gpx`;

const response = await fetch(endpoint, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
},
});

if (!response.ok) {
throw new Error('Could not get activity');
}

return await response.json();
}

export async function getActivityLaps(id, accessToken) {
const endpoint = `${API_BASE_URL}/activities/${id}/laps`;

const response = await fetch(endpoint, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
},
});

if (!response.ok) {
throw new Error('Could not get activity');
}

return await response.json();
}
17 changes: 17 additions & 0 deletions ui/src/services/athletes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,20 @@ export async function fetchAthletes(page) {

return await response.json();
}

export async function getAthlete(id) {
const endpoint = `${API_BASE_URL}/athletes/${id}`;

const response = await fetch(endpoint, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error('Could not get athlete');
}

return await response.json();
}
86 changes: 86 additions & 0 deletions ui/src/services/components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { API_BASE_URL } from './api';

export async function fetchComponents(dashId) {
const endpoint = `${API_BASE_URL}/dashboards/${dashId}/components`;

const response = await fetch(endpoint, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error('Could not fetch dashboard components');
}

return await response.json();
}

export async function createComponent(dashId, data) {
const endpoint = `${API_BASE_URL}/dashboards/${dashId}/components`;

const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});

if (!response.ok) {
throw new Error('Could not create a component');
}

return await response.json();
}

export async function updateComponent(dashId, compId, data) {
const endpoint = `${API_BASE_URL}/dashboards/${dashId}/components/${compId}`;

const response = await fetch(endpoint, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});

if (!response.ok) {
throw new Error('Could not create a component');
}

return await response.json();
}

export async function deleteComponent(dashId, compId) {
const endpoint = `${API_BASE_URL}/dashboards/${dashId}/components/${compId}`;

const response = await fetch(endpoint, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error('Could not delete a component');
}
}

export async function runComponent(dashId, compId) {
const endpoint = `${API_BASE_URL}/dashboards/${dashId}/components/${compId}`;

const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error('Could not run component');
}

return await response.json();
}
85 changes: 84 additions & 1 deletion ui/src/services/dashboars.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,90 @@ export async function fetchDashboards() {
});

if (!response.ok) {
throw new Error('Network response was not ok');
throw new Error('Could not fetch dashboards');
}

return await response.json();
}

export async function getDashboard(id) {
const endpoint = `${API_BASE_URL}/dashboards/${id}`;

const response = await fetch(endpoint, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error('Could not get dashboard');
}

return await response.json();
}

export async function createDashboard(data) {
const response = await fetch(`${API_BASE_URL}/dashboards`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});

if (!response.ok) {
throw new Error('Could not create a dashboard');
}

return await response.json();
}

export async function updateDashboard(id, data) {
const endpoint = `${API_BASE_URL}/dashboards/${id}`;

const response = await fetch(endpoint, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});

if (!response.ok) {
throw new Error('Could not update a dashboard');
}

return await response.json();
}

export async function deleteDashboard(id) {
const endpoint = `${API_BASE_URL}/dashboards/${id}`;

const response = await fetch(endpoint, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error('Could not delete a dashboard');
}
}

export async function runDashboard(id) {
const endpoint = `${API_BASE_URL}/dashboards/${id}/run`;

const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error('Could not run dashboard');
}

return await response.json();
Expand Down
17 changes: 17 additions & 0 deletions ui/src/services/gears.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,20 @@ export async function fetchGears(page) {

return await response.json();
}

export async function getGear(id) {
const endpoint = `${API_BASE_URL}/gears/${id}`;

const response = await fetch(endpoint, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error('Could not get gear');
}

return await response.json();
}
20 changes: 19 additions & 1 deletion ui/src/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export async function getUserMe(accessToken) {
}

export async function getTaskDetail(id) {
const response = await fetch(`${API_BASE_URL}/user/task/${id}`, {
const endpoint = `${API_BASE_URL}/user/task/${id}`;

const response = await fetch(endpoint, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -77,3 +79,19 @@ export async function saveUserConfig(config) {

return await response.json();
}

export async function runQuery(query) {
const response = await fetch(`${API_BASE_URL}/user/query`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(query),
});

if (!response.ok) {
throw new Error('Could not run query');
}

return await response.json();
}

0 comments on commit 5cb96a4

Please sign in to comment.