diagnose-backend/ec_user/templates/api_social_practice_test.html
pzc-x99 f56b66d8f1 /health/
/error_code_map/
/ec_user/*
/diagnose/*
/admin/*
2025-02-28 23:05:31 +08:00

134 lines
5.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Social Practice API</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.message {
margin-top: 10px;
padding: 10px;
background-color: #f4f4f4;
border: 1px solid #ddd;
}
</style>
</head>
<body>
<h2>Test Social Practice API</h2>
<h3>Get Social Practice Records</h3>
<label for="user_id_get">User ID:</label>
<input type="number" id="user_id_get" min="1" placeholder="Enter user ID">
<button onclick="getSocialPractice()">Get Social Practice Records</button>
<div id="get-result" class="message"></div>
<h3>Add Social Practice Record</h3>
<label for="user_id_post">User ID:</label>
<input type="number" id="user_id_post" min="1" placeholder="Enter user ID">
<br><br>
<label for="activity_name">Activity Name:</label>
<input type="text" id="activity_name" placeholder="Enter activity name">
<br><br>
<label for="activity_date">Activity Date:</label>
<input type="date" id="activity_date">
<br><br>
<label for="activity_location">Activity Location:</label>
<input type="text" id="activity_location" placeholder="Enter activity location">
<br><br>
<label for="activity_description">Activity Description:</label>
<textarea id="activity_description" placeholder="Enter activity description"></textarea>
<br><br>
<label for="activity_outcome">Activity Outcome:</label>
<textarea id="activity_outcome" placeholder="Enter activity outcome"></textarea>
<br><br>
<button onclick="addSocialPractice()">Add Social Practice Record</button>
<div id="post-result" class="message"></div>
<script>
// Function to get social practice records via GET request
function getSocialPractice() {
const userId = document.getElementById('user_id_get').value;
const resultDiv = document.getElementById('get-result');
if (!userId) {
resultDiv.textContent = "Please enter a valid user ID.";
return;
}
fetch(`/ec_user/social_practice/api/`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'token': '486ef8198bb10ba6878eba95771c064ff64db81a'
},
})
.then(response => response.json())
.then(data => {
if (data.error) {
resultDiv.textContent = `Error: ${data.error}`;
} else {
let resultText = '';
data.forEach(entry => {
resultText += `Activity Name: ${entry.activity_name}, Activity Date: ${entry.activity_date}, Location: ${entry.activity_location}, Description: ${entry.activity_description}, Outcome: ${entry.activity_outcome}<br><br>`;
});
resultDiv.innerHTML = resultText;
}
})
.catch(error => {
resultDiv.textContent = `Error: ${error.message}`;
});
}
// Function to add a social practice record via POST request
function addSocialPractice() {
const userId = document.getElementById('user_id_post').value;
const activityName = document.getElementById('activity_name').value;
const activityDate = document.getElementById('activity_date').value;
const activityLocation = document.getElementById('activity_location').value;
const activityDescription = document.getElementById('activity_description').value;
const activityOutcome = document.getElementById('activity_outcome').value;
const resultDiv = document.getElementById('post-result');
if (!userId || !activityName || !activityDate || !activityLocation || !activityDescription || !activityOutcome) {
resultDiv.textContent = "Please fill out all fields.";
return;
}
const postData = {
activity_name: activityName,
activity_date: activityDate,
activity_location: activityLocation,
activity_description: activityDescription,
activity_outcome: activityOutcome
};
fetch(`/ec_user/social_practice/api/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'token': '486ef8198bb10ba6878eba95771c064ff64db81a'
},
body: JSON.stringify(postData)
})
.then(response => response.json())
.then(data => {
if (data.error) {
resultDiv.textContent = `Error: ${data.error}`;
} else {
resultDiv.textContent = data.message;
}
})
.catch(error => {
resultDiv.textContent = `Error: ${error.message}`;
});
}
</script>
</body>
</html>