update/teacher-homeroom
This commit is contained in:
1 parent
dd94f362a6
commit
592cedc276
1 file changed
+79
-3
@@ -141,6 +141,17 @@ func UpdateStudentGradeLevel(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
Far later on this function is going to be completely automated.
|
||||
Instead of an admin sending a request to update the homeroom of
|
||||
a student or teacher, the system will take the room number of
|
||||
the teacher's or student's Block 2 class from their schedule.
|
||||
|
||||
Though this function would remain for students only, for example
|
||||
a student requests a course change, if its their block 2 the
|
||||
admin would have to alter their homeroom to be the new class
|
||||
number.
|
||||
*/
|
||||
func UpdateStudentHomeroom(c *fiber.Ctx) error {
|
||||
var data map[string]string
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
@@ -733,10 +744,75 @@ func RemoveStudentsDisabled(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
Far later on this function is going to be completely automated.
|
||||
Instead of an admin sending a request to update the homeroom of
|
||||
a student or teacher, the system will take the room number of
|
||||
the teacher's or student's Block 2 class from their schedule.
|
||||
|
||||
Though this function would remain for students only, for example
|
||||
a student requests a course change, if its their block 2 the
|
||||
admin would have to alter their homeroom to be the new class
|
||||
number.
|
||||
*/
|
||||
func UpdateTeacherHomeroom(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||
"success": nil,
|
||||
"message": "not implimented",
|
||||
var data map[string]string
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
|
||||
if err := c.BodyParser(&data); err != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "Failed to parse body",
|
||||
"error": err,
|
||||
})
|
||||
}
|
||||
|
||||
// Ensure Authenticated admin sent request
|
||||
if !AuthAdmin(c) {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "Unauthorized: only an admin can perform this action",
|
||||
})
|
||||
}
|
||||
|
||||
// Check required fields are included
|
||||
if data["tid"] == "" || data["homeroom"] == "" {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "missing required fields",
|
||||
})
|
||||
}
|
||||
|
||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||
update := bson.M{
|
||||
"$set": bson.M{
|
||||
"schooldata.homeroom": data["homeroom"],
|
||||
"updated_at": update_time,
|
||||
},
|
||||
}
|
||||
|
||||
result, updateErr := teacherCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"tid": data["tid"]},
|
||||
update,
|
||||
)
|
||||
if updateErr != nil {
|
||||
cancel()
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"success": false,
|
||||
"message": "the teacher could not be updated",
|
||||
"error": updateErr,
|
||||
})
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"success": true,
|
||||
"message": "successfully updated teacher",
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user