Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 4 additions & 50 deletions backend/controllers/admin/StudentController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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<void(const HttpResponsePtr &)> &&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<std::string>();
student["name"] = row["name"].as<std::string>();
student["dateofbirth"] = row["dateofbirth"].as<std::string>();
student["sex"] = row["sex"].as<std::string>();
student["phone"] = row["phone"].as<std::string>();
student["email"] = row["email"].as<std::string>();
student["address"] = row["address"].as<std::string>();
//student["enrollmentStatus"] = row["enrollmentStatus"].as<std::string>(); // 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()
);
}
5 changes: 0 additions & 5 deletions backend/controllers/admin/StudentController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ class StudentController : public drogon::HttpController<StudentController> {
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<void(const drogon::HttpResponsePtr &)> &&callback);
// Handles GET request to return all students as JSON
void getAllStudents(const drogon::HttpRequestPtr &req,
std::function<void(const drogon::HttpResponsePtr &)> &&callback);
};
53 changes: 0 additions & 53 deletions docs/admin/assets/sidebar.css

This file was deleted.

25 changes: 0 additions & 25 deletions docs/admin/assets/sidebar.js

This file was deleted.

55 changes: 0 additions & 55 deletions docs/admin/assets/student_table.css

This file was deleted.

29 changes: 0 additions & 29 deletions docs/admin/assets/student_table.js

This file was deleted.

50 changes: 43 additions & 7 deletions docs/admin/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,55 @@
<meta charset="UTF-8">
<title>Admin Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

<style>
body {
margin: 0;
display: flex;
height: 100vh;
font-family: "Segoe UI", sans-serif;
}
.sidebar {
width: 220px;
background-color: #1e1e2f;
color: #fff;
display: flex;
flex-direction: column;
padding: 20px;
}
.sidebar h2 {
font-size: 1.5rem;
margin-bottom: 30px;
text-align: center;
}
.sidebar a {
color: #cfd1d7;
text-decoration: none;
padding: 10px 15px;
border-radius: 6px;
margin-bottom: 10px;
transition: background 0.2s ease;
}
.sidebar a:hover, .sidebar a.active {
background-color: #34344a;
color: #fff;
}
.main {
flex-grow: 1;
background-color: #f8f9fa;
padding: 40px;
}
</style>
</head>
<link rel="stylesheet" href="assets/sidebar.css">

<body>
<div id="sidebar-container"></div>
<div class="sidebar">
<h2>Admin</h2>
<a href="/admin/dashboard.html" class="active">Dashboard</a>
<a href="/admin/new_student.html">Add Student</a>
</div>

<div class="main">
<h1>Welcome, Admin!</h1>
<p>This is your admin dashboard.</p>
</div>

<script src="assets/sidebar.js"></script>

</body>
</html>
59 changes: 0 additions & 59 deletions docs/admin/list_of_students.html

This file was deleted.

Loading