130 lines
4.7 KiB
HTML
130 lines
4.7 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 School Info 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 School Info API</h2>
|
|
|
|
<h3>Get School Info</h3>
|
|
<label for="user_id_get">User ID:</label>
|
|
<input type="number" id="user_id_get" min="1" placeholder="Enter user ID">
|
|
<button onclick="getSchoolInfo()">Get School Info</button>
|
|
|
|
<div id="get-result" class="message"></div>
|
|
|
|
<h3>Update School Info</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="school_name">School Name:</label>
|
|
<input type="text" id="school_name" placeholder="Enter school name">
|
|
<br><br>
|
|
<label for="grade">Grade:</label>
|
|
<input type="text" id="grade" placeholder="Enter grade">
|
|
<br><br>
|
|
<label for="class_name">Class Name:</label>
|
|
<input type="text" id="class_name" placeholder="Enter class name">
|
|
<br><br>
|
|
<label for="admission_date">Admission Date:</label>
|
|
<input type="date" id="admission_date">
|
|
<br><br>
|
|
<label for="expected_graduation_date">Expected Graduation Date:</label>
|
|
<input type="date" id="expected_graduation_date">
|
|
<br><br>
|
|
<button onclick="updateSchoolInfo()">Update School Info</button>
|
|
|
|
<div id="post-result" class="message"></div>
|
|
|
|
<script>
|
|
// Function to get school info via GET request
|
|
function getSchoolInfo() {
|
|
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/school_info/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 {
|
|
resultDiv.textContent = `School Name: ${data.school_name}, Grade: ${data.grade}, Class Name: ${data.class_name}, Admission Date: ${data.admission_date}, Expected Graduation Date: ${data.expected_graduation_date}`;
|
|
}
|
|
})
|
|
.catch(error => {
|
|
resultDiv.textContent = `Error: ${error.message}`;
|
|
});
|
|
}
|
|
|
|
// Function to update school info via POST request
|
|
function updateSchoolInfo() {
|
|
const userId = document.getElementById('user_id_post').value;
|
|
const schoolName = document.getElementById('school_name').value;
|
|
const grade = document.getElementById('grade').value;
|
|
const className = document.getElementById('class_name').value;
|
|
const admissionDate = document.getElementById('admission_date').value;
|
|
const expectedGraduationDate = document.getElementById('expected_graduation_date').value;
|
|
const resultDiv = document.getElementById('post-result');
|
|
|
|
if (!userId || !schoolName || !grade || !className || !admissionDate || !expectedGraduationDate) {
|
|
resultDiv.textContent = "Please fill out all fields.";
|
|
return;
|
|
}
|
|
|
|
const postData = {
|
|
school_name: schoolName,
|
|
grade: grade,
|
|
class_name: className,
|
|
admission_date: admissionDate,
|
|
expected_graduation_date: expectedGraduationDate
|
|
};
|
|
|
|
fetch(`/ec_user/school_info/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>
|