create runs list page

This commit is contained in:
Takeshi Kimata
2024-04-07 19:03:43 +09:00
parent e54af6fd2f
commit b0c2168463
6 changed files with 533 additions and 2 deletions

View File

@@ -0,0 +1,105 @@
import Config from "@/config/config";
const apiServer = Config.apiServer;
async function fetchRuns(projectId: string) {
const url = `${apiServer}/runs?projectId=${projectId}`;
try {
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Error fetching data:", error.message);
}
}
async function createRun(name: string, detail: string) {
const newProjectData = {
name: name,
detail: detail,
};
const fetchOptions = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(newProjectData),
};
const url = `${apiServer}/runs`;
try {
const response = await fetch(url, fetchOptions);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Error creating new project:", error);
throw error;
}
}
async function updateRun(runId: number, name: string, detail: string) {
const updatedProjectData = {
name: name,
detail: detail,
};
const fetchOptions = {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(updatedProjectData),
};
const url = `${apiServer}/runs/${runId}`;
try {
const response = await fetch(url, fetchOptions);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Error updating project:", error);
throw error;
}
}
async function deleteRun(runId: number) {
const fetchOptions = {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
};
const url = `${apiServer}/runs/${runId}`;
try {
const response = await fetch(url, fetchOptions);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
} catch (error) {
console.error("Error deleting project:", error);
throw error;
}
}
export { fetchRuns, createRun, updateRun, deleteRun };