diff --git a/backend/controllers/admin/StudentController.cpp b/backend/controllers/admin/StudentController.cpp index 55a6828..ab5281a 100644 --- a/backend/controllers/admin/StudentController.cpp +++ b/backend/controllers/admin/StudentController.cpp @@ -18,7 +18,7 @@ void StudentController::createStudent(const HttpRequestPtr &req, } // Validate required fields - if (!json->isMember("name") || !json->isMember("email") || + if (!json->isMember("name") || !json->isMember("email") || !json->isMember("studentId") || !json->isMember("phone") || !json->isMember("dateofbirth") || !json->isMember("address") || !json->isMember("sex")) @@ -55,52 +55,6 @@ void StudentController::createStudent(const HttpRequestPtr &req, (*json)["dateofbirth"].asString(), (*json)["address"].asString(), (*json)["sex"].asString(), - (*json)["studentId"].asString()); -} - -// Handles GET request to retrieve all student records from the database -void StudentController::getAllStudents(const HttpRequestPtr &req, - std::function &&callback) -{ - // Get the default database client instance - auto client = app().getDbClient("default"); - - // Execute SQL query asynchronously to fetch student data - client->execSqlAsync( - "SELECT id, name, phone, email, dateofbirth, address, sex, studentId FROM Students", - - // Success callback: transform DB result into JSON array - [callback](const drogon::orm::Result &result) - { - Json::Value jsonResponse(Json::arrayValue); - - // Iterate through each row and build a JSON object for each student - for (const auto &row : result) - { - Json::Value student; - student["studentId"] = row["studentId"].as(); - student["name"] = row["name"].as(); - student["dateofbirth"] = row["dateofbirth"].as(); - student["sex"] = row["sex"].as(); - student["phone"] = row["phone"].as(); - student["email"] = row["email"].as(); - student["address"] = row["address"].as(); - //student["enrollmentStatus"] = row["enrollmentStatus"].as(); // May be null - jsonResponse.append(student); - } - - // Return JSON response with HTTP 200 OK - auto resp = HttpResponse::newHttpJsonResponse(jsonResponse); - resp->setStatusCode(k200OK); - callback(resp); - }, - - // Error callback: return HTTP 500 with error message - [callback](const drogon::orm::DrogonDbException &e) - { - auto resp = HttpResponse::newHttpResponse(); - resp->setStatusCode(k500InternalServerError); - resp->setBody("Database error: " + std::string(e.base().what())); - callback(resp); - }); -} + (*json)["studentId"].asString() + ); +} \ No newline at end of file diff --git a/backend/controllers/admin/StudentController.h b/backend/controllers/admin/StudentController.h index 219baeb..f2f211a 100644 --- a/backend/controllers/admin/StudentController.h +++ b/backend/controllers/admin/StudentController.h @@ -6,14 +6,9 @@ class StudentController : public drogon::HttpController { METHOD_LIST_BEGIN // Admin-only endpoint to create a new student ADD_METHOD_TO(StudentController::createStudent, "/api/admin/students", drogon::Post); - // Route: GET /api/admin/students → calls getAllStudents - ADD_METHOD_TO(StudentController::getAllStudents, "/api/admin/students", drogon::Get); METHOD_LIST_END // Handler void createStudent(const drogon::HttpRequestPtr &req, std::function &&callback); - // Handles GET request to return all students as JSON - void getAllStudents(const drogon::HttpRequestPtr &req, - std::function &&callback); }; diff --git a/docs/admin/assets/sidebar.css b/docs/admin/assets/sidebar.css deleted file mode 100644 index 09dc01a..0000000 --- a/docs/admin/assets/sidebar.css +++ /dev/null @@ -1,53 +0,0 @@ -/* Base layout setup */ -body { - margin: 0; - display: flex; /* Enables sidebar + main layout */ - height: 100vh; - font-family: "Segoe UI", sans-serif; -} - -/* Sidebar styling */ -.sidebar { - width: 220px; - background-color: #1e1e2f; - color: #fff; - display: flex; - flex-direction: column; - padding: 20px; - height: 100vh; /* Fill full vertical space */ - position: fixed; /* Stay fixed on the left */ - top: 0; - left: 0; -} - -/* Sidebar title */ -.sidebar h2 { - font-size: 1.5rem; - margin-bottom: 30px; - text-align: center; -} - -/* Sidebar links */ -.sidebar a { - color: #cfd1d7; - text-decoration: none; - padding: 10px 15px; - border-radius: 6px; - margin-bottom: 10px; - transition: background 0.2s ease; -} - -/* Hover and active link styles */ -.sidebar a:hover, -.sidebar a.active { - background-color: #34344a; - color: #fff; -} - -/* Main content area */ -.main { - flex-grow: 1; /* Take remaining space */ - background-color: #f8f9fa; - padding: 40px; - margin-left: 220px; /* Offset for fixed sidebar */ -} diff --git a/docs/admin/assets/sidebar.js b/docs/admin/assets/sidebar.js deleted file mode 100644 index f1ea5d6..0000000 --- a/docs/admin/assets/sidebar.js +++ /dev/null @@ -1,25 +0,0 @@ -// Load sidebar HTML and highlight the active link -document.addEventListener("DOMContentLoaded", () => { - const sidebarContainer = document.getElementById("sidebar-container"); - - if (sidebarContainer) { - // Inject sidebar.html into the container - fetch("sidebar.html") - .then(res => res.text()) - .then(html => { - sidebarContainer.innerHTML = html; - - // Add 'active' class to the link matching current page - const links = sidebarContainer.querySelectorAll("a"); - const currentPage = window.location.pathname; - links.forEach(link => { - if (link.getAttribute("href") === currentPage) { - link.classList.add("active"); - } - }); - }) - .catch(err => { - console.error("Error loading sidebar:", err); - }); - } -}); diff --git a/docs/admin/assets/student_table.css b/docs/admin/assets/student_table.css deleted file mode 100644 index f521ac8..0000000 --- a/docs/admin/assets/student_table.css +++ /dev/null @@ -1,55 +0,0 @@ -/* =============================== - Table layout and formatting - =============================== */ -table { - width: 100%; - border-collapse: collapse; - margin-top: 20px; -} - -thead th { - text-align: center; - background-color: #f0f0f0; - color: #333; -} - -th, -td { - padding: 10px; - border: 1px solid #ddd; - text-align: left; - white-space: nowrap; -} - -/* First column: center-align and fixed width */ -td:first-child, -th:first-child { - text-align: center; - width: 60px; -} - -/* =============================== - Confirm button styling - =============================== */ - -/* Container aligns button to bottom-right of table */ -.confirm-container { - display: flex; - justify-content: flex-end; - margin-top: 20px; -} - -/* Button appearance and hover effect */ -.confirm-button { - padding: 10px 20px; - background-color: #28a745; /* success green */ - color: white; - border: none; - border-radius: 5px; - font-size: 16px; - cursor: pointer; -} - -.confirm-button:hover { - background-color: #218838; -} diff --git a/docs/admin/assets/student_table.js b/docs/admin/assets/student_table.js deleted file mode 100644 index e1102cb..0000000 --- a/docs/admin/assets/student_table.js +++ /dev/null @@ -1,29 +0,0 @@ -// =============================== -// Fetch and render student data -// =============================== - -// Send GET request to backend API -fetch("/api/admin/students") - .then(res => res.json()) - .then(students => { - const tableBody = document.querySelector("#studentTableBody"); - tableBody.innerHTML = ""; // Clear any existing rows - - // Loop through each student and build a table row - students.forEach((student, index) => { - const row = ` - - - ${student.studentId} - ${student.name} - ${student.dateofbirth} - ${student.sex} - ${student.phone} - ${student.email} - ${student.address} - ${student.enrollmentStatus || "Active"} - - `; - tableBody.innerHTML += row; - }); - }); diff --git a/docs/admin/dashboard.html b/docs/admin/dashboard.html index 83a80f2..813bb05 100644 --- a/docs/admin/dashboard.html +++ b/docs/admin/dashboard.html @@ -4,19 +4,55 @@ Admin Dashboard - + - - - +

Welcome, Admin!

This is your admin dashboard.

- - - diff --git a/docs/admin/list_of_students.html b/docs/admin/list_of_students.html deleted file mode 100644 index 14b569e..0000000 --- a/docs/admin/list_of_students.html +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - List of Students - - - - - - - - - - - - - - - - -
-

Registered Students

- - - - - - - - - - - - - - - - - - - -
Student IDFull NameDOBSexPhoneEmailAddressEnrollment Status
- - -
- -
-
- - - - - - - - - diff --git a/docs/admin/new_student.html b/docs/admin/new_student.html index f26fdb2..1f57828 100644 --- a/docs/admin/new_student.html +++ b/docs/admin/new_student.html @@ -5,16 +5,53 @@ New Student Registration - - - - +

Register New Student

@@ -123,8 +160,5 @@

Register New Student

}); }); - - - diff --git a/docs/admin/sidebar.html b/docs/admin/sidebar.html deleted file mode 100644 index 2a9a050..0000000 --- a/docs/admin/sidebar.html +++ /dev/null @@ -1,13 +0,0 @@ - -