84 lines
No EOL
2.4 KiB
JavaScript
84 lines
No EOL
2.4 KiB
JavaScript
const url = 'http://127.0.0.1:5180/api/';
|
|
async function ping(){
|
|
fetch ('http://127.0.0.1:5180/api/ping')
|
|
.then(data => {
|
|
console.log(data);
|
|
});
|
|
}
|
|
async function setBaseDataHorseAPI(id, basedata) {
|
|
try {
|
|
console.log("Setting horse data");
|
|
console.log("ID:", id); // Log ID to ensure it's received correctly
|
|
console.log("Basedata:", basedata); // Log the entire horse data to check
|
|
|
|
const apiUrl = url+`setHorseBasicData/id=${id}`;
|
|
|
|
// Wait for the API call to complete
|
|
const response = await fetch(apiUrl, {
|
|
method: 'POST',
|
|
body: JSON.stringify(basedata),
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
console.log("API Response:", response); // Log the response from the API
|
|
|
|
} catch (error) {
|
|
console.error("Error setting horse data: " + error.message);
|
|
}
|
|
}
|
|
async function getHorseAPI(id) {
|
|
let horseData;
|
|
const apiUrl = url+`getHorseInfo/id=${id}`;
|
|
await fetch(apiUrl)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
horseData = data;
|
|
});
|
|
return horseData;
|
|
}
|
|
async function setHorsePedigreeAPIAsync(id, pedigreeData)
|
|
{
|
|
const apiUrl = url+`setHorsePedigree/id=${id}`;
|
|
const response = await fetch(apiUrl, {
|
|
method: 'POST',
|
|
body: JSON.stringify(pedigreeData),
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
return response;
|
|
}
|
|
async function setHorseTrainingAPIAsync(id, training)
|
|
{
|
|
const apiUrl = url+`setHorseTraining/id=${id}`;
|
|
const response = await fetch(apiUrl, {
|
|
method: 'POST',
|
|
body: JSON.stringify(training),
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
}
|
|
async function setHorseGeneticsAPIAsync(id, genetics)
|
|
{
|
|
const apiUrl = url+`setHorseGenetics/id=${id}`;
|
|
const response = await fetch(apiUrl, {
|
|
method: 'POST',
|
|
body: JSON.stringify(genetics),
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
}
|
|
async function setHorseHealthAPIAsync(id, health)
|
|
{
|
|
const apiUrl = url+`setHorseHealth/id=${id}`;
|
|
const response = await fetch(apiUrl, {
|
|
method: 'POST',
|
|
body: JSON.stringify(health),
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
} |