diff --git a/EduSync.exe b/EduSync.exe index 992caf0..98397e2 100644 Binary files a/EduSync.exe and b/EduSync.exe differ diff --git a/adminHandler.go b/adminHandler.go index 0c6bba2..1f18bb7 100644 --- a/adminHandler.go +++ b/adminHandler.go @@ -31,6 +31,7 @@ func AdminHandler(router *mux.Router) { t.Execute(res, nil) }).Methods("GET") + //searve the search student page router.HandleFunc("/admin/search_student", func(res http.ResponseWriter, req *http.Request) { t, err := template.ParseFiles("templates/admin/search_student.html") if err != nil { @@ -40,6 +41,16 @@ func AdminHandler(router *mux.Router) { t.Execute(res, nil) }).Methods("GET") + // Serve the create student page + router.HandleFunc("/admin/create_student", func(res http.ResponseWriter, req *http.Request) { + t, err := template.ParseFiles("templates/admin/create_student.html") + if err != nil { + http.Error(res, err.Error(), http.StatusInternalServerError) + return + } + t.Execute(res, nil) + }).Methods("GET") + // Search for students by name and class router.HandleFunc("/admin/api/search_student", func(res http.ResponseWriter, req *http.Request) { name := req.URL.Query().Get("name") @@ -113,6 +124,31 @@ func AdminHandler(router *mux.Router) { // Request Body: JSON object with updated student information // Response: HTTP Status No Content (204) + // Create a new student + router.HandleFunc("/admin/student/", func(res http.ResponseWriter, req *http.Request) { + switch req.Method { + case http.MethodPost: + var student Student // Replace 'Student' with your actual student struct type + if err := json.NewDecoder(req.Body).Decode(&student); err != nil { + http.Error(res, fmt.Sprintf(`{"error": "Invalid request payload: %v"}`, err), http.StatusBadRequest) + return + } + student.GoogleID = uuid.New().String() + student.Role = "Student" + student.CreatedAt = time.Now() + student.UpdatedAt = time.Now() + if err := createStudent(student, req); err != nil { // Implement createStudent to handle the logic + http.Error(res, fmt.Sprintf(`{"error": "Failed to create student: %v"}`, err), http.StatusInternalServerError) + return + } + res.WriteHeader(http.StatusCreated) + json.NewEncoder(res).Encode(student) + default: + http.Error(res, `{"error": "Invalid request method"}`, http.StatusMethodNotAllowed) + } + }).Methods("POST") + + // Serve the search parent page router.HandleFunc("/admin/search_parent", func(res http.ResponseWriter, req *http.Request) { t, err := template.ParseFiles("templates/admin/search_parent.html") if err != nil { @@ -122,6 +158,16 @@ func AdminHandler(router *mux.Router) { t.Execute(res, nil) }).Methods("GET") + // Serve the create parent page + router.HandleFunc("/admin/create_parent", func(res http.ResponseWriter, req *http.Request) { + t, err := template.ParseFiles("templates/admin/create_parent.html") + if err != nil { + http.Error(res, err.Error(), http.StatusInternalServerError) + return + } + t.Execute(res, nil) + }).Methods("GET") + router.HandleFunc("/admin/api/search_parent", func(res http.ResponseWriter, req *http.Request) { name := req.URL.Query().Get("name") parents, err := searchParents(name) @@ -178,6 +224,31 @@ func AdminHandler(router *mux.Router) { } }).Methods("GET", "PUT") + // Create a new parent + router.HandleFunc("/admin/parent/", func(res http.ResponseWriter, req *http.Request) { + switch req.Method { + case http.MethodPost: + var parent Parent + if err := json.NewDecoder(req.Body).Decode(&parent); err != nil { + http.Error(res, fmt.Sprintf(`{"error": "Invalid request payload: %v"}`, err), http.StatusBadRequest) + return + } + parent.GoogleID = uuid.New().String() + parent.Role = "Parent" + parent.CreatedAt = time.Now() + parent.UpdatedAt = time.Now() + if err := createParent(parent, req); err != nil { + http.Error(res, fmt.Sprintf(`{"error": "Failed to create parent: %v"}`, err), http.StatusInternalServerError) + return + } + res.WriteHeader(http.StatusCreated) + json.NewEncoder(res).Encode(parent) + default: + http.Error(res, `{"error": "Invalid request method"}`, http.StatusMethodNotAllowed) + } + }).Methods("POST") + + // Serve the search instructor page router.HandleFunc("/admin/search_instructor", func(res http.ResponseWriter, req *http.Request) { t, err := template.ParseFiles("templates/admin/search_instructor.html") if err != nil { @@ -187,6 +258,17 @@ func AdminHandler(router *mux.Router) { t.Execute(res, nil) }).Methods("GET") + // Serve the create instructor page + router.HandleFunc("/admin/create_instructor", func(res http.ResponseWriter, req *http.Request) { + t, err := template.ParseFiles("templates/admin/create_instructor.html") + if err != nil { + http.Error(res, err.Error(), http.StatusInternalServerError) + return + } + t.Execute(res, nil) + }).Methods("GET") + + // Serve the search instructor API endpoint router.HandleFunc("/admin/api/search_instructor", func(res http.ResponseWriter, req *http.Request) { name := req.URL.Query().Get("name") instructors, err := searchInstructors(name) @@ -243,6 +325,30 @@ func AdminHandler(router *mux.Router) { } }).Methods("GET", "PUT") + // Create a new instructor + router.HandleFunc("/admin/instructor/", func(res http.ResponseWriter, req *http.Request) { + switch req.Method { + case http.MethodPost: + var instructor Instructor + if err := json.NewDecoder(req.Body).Decode(&instructor); err != nil { + http.Error(res, fmt.Sprintf(`{"error": "Invalid request payload: %v"}`, err), http.StatusBadRequest) + return + } + instructor.GoogleID = uuid.New().String() + instructor.Role = "Instructor" + instructor.CreatedAt = time.Now() + instructor.UpdatedAt = time.Now() + if err := createInstructor(instructor, req); err != nil { + http.Error(res, fmt.Sprintf(`{"error": "Failed to create instructor: %v"}`, err), http.StatusInternalServerError) + return + } + res.WriteHeader(http.StatusCreated) + json.NewEncoder(res).Encode(instructor) + default: + http.Error(res, `{"error": "Invalid request method"}`, http.StatusMethodNotAllowed) + } + }).Methods("POST") + //Serve the search announcement page router.HandleFunc("/admin/search_announcement", func(res http.ResponseWriter, req *http.Request) { t, err := template.ParseFiles("templates/admin/search_announcement.html") diff --git a/templates/admin/create_instructor.html b/templates/admin/create_instructor.html new file mode 100644 index 0000000..b2afebb --- /dev/null +++ b/templates/admin/create_instructor.html @@ -0,0 +1,97 @@ + + + + EduSync + + + + + + + + + +
+ + +
+

Create New Instructor

+
+
+
+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+ + + + + + + + + diff --git a/templates/admin/create_parent.html b/templates/admin/create_parent.html new file mode 100644 index 0000000..3f9480b --- /dev/null +++ b/templates/admin/create_parent.html @@ -0,0 +1,84 @@ + + + + EduSync + + + + + + + + + +
+ + +
+

Create New Parent

+
+
+
+
+
+
+
+
+ + +
+
+
+
+ + + + + + + + + diff --git a/templates/admin/create_student.html b/templates/admin/create_student.html new file mode 100644 index 0000000..435f3a0 --- /dev/null +++ b/templates/admin/create_student.html @@ -0,0 +1,110 @@ + + + + EduSync + + + + + + + + + +
+ + + +
+

Create New Student

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+ + + + + + + + + diff --git a/templates/admin/search_instructor.html b/templates/admin/search_instructor.html index 62bae1c..e6cd837 100644 --- a/templates/admin/search_instructor.html +++ b/templates/admin/search_instructor.html @@ -100,6 +100,7 @@

Search Instructors

+
diff --git a/templates/admin/search_parent.html b/templates/admin/search_parent.html index fadacf0..73e5adf 100644 --- a/templates/admin/search_parent.html +++ b/templates/admin/search_parent.html @@ -100,6 +100,7 @@

Search Parents

+
diff --git a/templates/admin/search_student.html b/templates/admin/search_student.html index 1791642..e0d4c06 100644 --- a/templates/admin/search_student.html +++ b/templates/admin/search_student.html @@ -118,6 +118,7 @@

Update Student Details

+