Skip to content

Commit

Permalink
Switch visualization api calls to interface
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Nov 2, 2024
1 parent 65bdf6b commit 8be27e9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
24 changes: 20 additions & 4 deletions src/api/client.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { rethrowSimple } from "@/utilities/simpleError";
import { useConfigStore } from "@/store/configStore";

export async function fetchApi(path, options) {
async function fetchApi(path, options) {
const configStore = useConfigStore();
const routedPath = `${configStore.getRoot()}${path.substring(1)}`;
try {
const response = await fetch(routedPath, {
credentials: process.env.GALAXY_KEY ? "omit" : "include",
method: "GET",
headers: { "Content-Type": "application/json" },
...options,
});
const data = await response.json();
Expand All @@ -18,10 +18,26 @@ export async function fetchApi(path, options) {
}

export function GalaxyApi() {
async function GET(path, options) {
return fetchApi(path, options);
async function GET(path) {
return fetchApi(path, {
method: "GET",
});
}
async function POST(path, options) {
return fetchApi(path, {
body: JSON.stringify(options),
method: "POST",
});
}
async function PUT(path, options) {
return fetchApi(path, {
body: JSON.stringify(options),
method: "PUT",
});
}
return {
GET,
POST,
PUT,
};
}
9 changes: 3 additions & 6 deletions src/api/datasets.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { fetchApi } from "@/api/client";
import { useConfigStore } from "@/store/configStore";
import { GalaxyApi } from "@/api/client";

export async function datasetsGetColumns(datasetId, columnList) {
try {
const url = `/api/datasets/${datasetId}`;
const params = new URLSearchParams({
data_type: "raw_data",
provider: "dataset-column",
indeces: columnList.toString(),
}).toString();
const data = await fetchApi(`${url}?${params}`);
const data = await GalaxyApi().GET(`/api/datasets/${datasetId}?${params}`);
const columnLength = columnList.length;
const results = new Array(columnLength);
for (let i = 0; i < results.length; i++) {
Expand All @@ -30,6 +28,5 @@ export async function datasetsGetColumns(datasetId, columnList) {
}

export function datasetsGetUrl(datasetId) {
const configStore = useConfigStore();
return `${configStore.getRoot()}api/datasets/${datasetId}/display`;
return `/api/datasets/${datasetId}/display`;
}
9 changes: 3 additions & 6 deletions src/api/visualizations.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import axios from "axios";
import { rethrowSimple } from "@/utilities/simpleError";
import { useConfigStore } from "@/store/configStore";
import { GalaxyApi } from "@/api/client";

export async function visualizationsCreate(type, title, config) {
const configStore = useConfigStore();
try {
const { data } = await axios.post(`${configStore.getRoot()}api/visualizations`, {
const { data } = await GalaxyApi().POST("/api/visualizations", {
type,
title,
config,
Expand All @@ -17,9 +15,8 @@ export async function visualizationsCreate(type, title, config) {
}

export async function visualizationsSave(id, title, config) {
const configStore = useConfigStore();
try {
const response = await axios.put(`${configStore.getRoot()}api/visualizations/${id}`, {
const response = await GalaxyApi().PUT(`/api/visualizations/${id}`, {
title,
config,
});
Expand Down

0 comments on commit 8be27e9

Please sign in to comment.