Seperate update functions
This commit is contained in:
1 parent
7768c5c9ee
commit
c01900968c
2 files changed
+419
-408
No files matched your search
@@ -657,379 +657,6 @@ func Logout(c *fiber.Ctx) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateStudentName(c *fiber.Ctx) error {
|
|
||||||
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,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if admin sent request
|
|
||||||
if data["aid"] == "" {
|
|
||||||
cancel()
|
|
||||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
|
||||||
"success": false,
|
|
||||||
"message": "admin id required",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
var admin models.Admin
|
|
||||||
err := adminCollection.FindOne(ctx, bson.M{"aid": data["aid"]}).Decode(&admin)
|
|
||||||
if err != nil {
|
|
||||||
cancel()
|
|
||||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
|
||||||
"success": false,
|
|
||||||
"message": "invalid admin id",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check id and names are included
|
|
||||||
// Middle name is optional
|
|
||||||
if data["sid"] == "" || data["firstname"] == "" || data["lastname"] == "" {
|
|
||||||
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{
|
|
||||||
"firstname": data["firstname"],
|
|
||||||
"middlename": data["middlename"],
|
|
||||||
"lastname": data["lastname"],
|
|
||||||
"updated_at": update_time,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
result, updateErr := studentCollection.UpdateOne(
|
|
||||||
ctx,
|
|
||||||
bson.M{"sid": data["sid"]},
|
|
||||||
update,
|
|
||||||
)
|
|
||||||
if updateErr != nil {
|
|
||||||
cancel()
|
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
||||||
"success": false,
|
|
||||||
"message": "the student could not be updated",
|
|
||||||
"error": updateErr,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
|
||||||
"success": true,
|
|
||||||
"message": "successfully updated student",
|
|
||||||
"result": result,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateStudentGradeLevel(c *fiber.Ctx) error {
|
|
||||||
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,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if admin sent request
|
|
||||||
if data["aid"] == "" {
|
|
||||||
cancel()
|
|
||||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
|
||||||
"success": false,
|
|
||||||
"message": "admin id required",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
var admin models.Admin
|
|
||||||
err := adminCollection.FindOne(ctx, bson.M{"aid": data["aid"]}).Decode(&admin)
|
|
||||||
if err != nil {
|
|
||||||
cancel()
|
|
||||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
|
||||||
"success": false,
|
|
||||||
"message": "invalid admin id",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check required fields are included
|
|
||||||
if data["sid"] == "" || data["gradelevel"] == "" {
|
|
||||||
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{
|
|
||||||
"gradelevel": data["gradelevel"],
|
|
||||||
"updated_at": update_time,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
result, updateErr := studentCollection.UpdateOne(
|
|
||||||
ctx,
|
|
||||||
bson.M{"sid": data["sid"]},
|
|
||||||
update,
|
|
||||||
)
|
|
||||||
if updateErr != nil {
|
|
||||||
cancel()
|
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
||||||
"success": false,
|
|
||||||
"message": "the student could not be updated",
|
|
||||||
"error": updateErr,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
|
||||||
"success": true,
|
|
||||||
"message": "successfully updated student",
|
|
||||||
"result": result,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateStudentHomeroom(c *fiber.Ctx) error {
|
|
||||||
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,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
var admin models.Admin
|
|
||||||
err := adminCollection.FindOne(ctx, bson.M{"aid": data["aid"]}).Decode(&admin)
|
|
||||||
if err != nil {
|
|
||||||
cancel()
|
|
||||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
|
||||||
"success": false,
|
|
||||||
"message": "invalid admin id",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check required fields are included
|
|
||||||
if data["sid"] == "" || 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{
|
|
||||||
"homeroom": data["homeroom"],
|
|
||||||
"updated_at": update_time,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
result, updateErr := studentCollection.UpdateOne(
|
|
||||||
ctx,
|
|
||||||
bson.M{"sid": data["sid"]},
|
|
||||||
update,
|
|
||||||
)
|
|
||||||
if updateErr != nil {
|
|
||||||
cancel()
|
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
||||||
"success": false,
|
|
||||||
"message": "the student could not be updated",
|
|
||||||
"error": updateErr,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
|
||||||
"success": true,
|
|
||||||
"message": "successfully updated student",
|
|
||||||
"result": result,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateStudentPassword(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateStudentLocker(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateStudentAddress(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateStudentYOG(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateStudentContacts(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateStudentPhoto(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateStudentEmail(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateTeacherHomeroom(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateTeacherPassword(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateTeacherAddress(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateTeacherPhoto(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateTeacherEmail(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateTeacherName(c *fiber.Ctx) error {
|
|
||||||
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,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if admin sent request
|
|
||||||
if data["aid"] == "" {
|
|
||||||
cancel()
|
|
||||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
|
||||||
"success": false,
|
|
||||||
"message": "admin id required",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
var admin models.Admin
|
|
||||||
err := adminCollection.FindOne(ctx, bson.M{"aid": data["aid"]}).Decode(&admin)
|
|
||||||
if err != nil {
|
|
||||||
cancel()
|
|
||||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
|
||||||
"success": false,
|
|
||||||
"message": "invalid admin id",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check id and names are included
|
|
||||||
if data["_id"] == "" || data["firstname"] == "" || data["middlename"] == "" || data["lastname"] == "" {
|
|
||||||
cancel()
|
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
|
||||||
"success": false,
|
|
||||||
"message": "missing required fields",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
teacherObjectId, idErr := primitive.ObjectIDFromHex(data["_id"])
|
|
||||||
if idErr != nil {
|
|
||||||
cancel()
|
|
||||||
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
|
|
||||||
"success": false,
|
|
||||||
"message": "teacher not found",
|
|
||||||
"error": idErr,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
|
||||||
update := bson.M{
|
|
||||||
"$set": bson.M{
|
|
||||||
"firstname": data["firstname"],
|
|
||||||
"middlename": data["middlename"],
|
|
||||||
"lastname": data["lastname"],
|
|
||||||
"updated_at": update_time,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
result, updateErr := teacherCollection.UpdateOne(
|
|
||||||
ctx,
|
|
||||||
bson.M{"_id": teacherObjectId},
|
|
||||||
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,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreateContact(c *fiber.Ctx) error {
|
func CreateContact(c *fiber.Ctx) error {
|
||||||
var data map[string]string
|
var data map[string]string
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
@@ -1131,38 +758,3 @@ func RemoveContact(c *fiber.Ctx) error {
|
|||||||
"message": "not implimented",
|
"message": "not implimented",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateContactName(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateContactAddress(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateContactPhone(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateContactEmail(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateContactPriority(c *fiber.Ctx) error {
|
|
||||||
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
|
||||||
"success": nil,
|
|
||||||
"message": "not implimented",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,419 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"school-management/models"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UpdateStudentName(c *fiber.Ctx) error {
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if admin sent request
|
||||||
|
if data["aid"] == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "admin id required",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var admin models.Admin
|
||||||
|
err := adminCollection.FindOne(ctx, bson.M{"aid": data["aid"]}).Decode(&admin)
|
||||||
|
if err != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "invalid admin id",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check id and names are included
|
||||||
|
// Middle name is optional
|
||||||
|
if data["sid"] == "" || data["firstname"] == "" || data["lastname"] == "" {
|
||||||
|
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{
|
||||||
|
"firstname": data["firstname"],
|
||||||
|
"middlename": data["middlename"],
|
||||||
|
"lastname": data["lastname"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, updateErr := studentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"sid": data["sid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated student",
|
||||||
|
"result": result,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentGradeLevel(c *fiber.Ctx) error {
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if admin sent request
|
||||||
|
if data["aid"] == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "admin id required",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var admin models.Admin
|
||||||
|
err := adminCollection.FindOne(ctx, bson.M{"aid": data["aid"]}).Decode(&admin)
|
||||||
|
if err != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "invalid admin id",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check required fields are included
|
||||||
|
if data["sid"] == "" || data["gradelevel"] == "" {
|
||||||
|
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{
|
||||||
|
"gradelevel": data["gradelevel"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, updateErr := studentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"sid": data["sid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated student",
|
||||||
|
"result": result,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentHomeroom(c *fiber.Ctx) error {
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var admin models.Admin
|
||||||
|
err := adminCollection.FindOne(ctx, bson.M{"aid": data["aid"]}).Decode(&admin)
|
||||||
|
if err != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "invalid admin id",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check required fields are included
|
||||||
|
if data["sid"] == "" || 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{
|
||||||
|
"homeroom": data["homeroom"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, updateErr := studentCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"sid": data["sid"]},
|
||||||
|
update,
|
||||||
|
)
|
||||||
|
if updateErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "the student could not be updated",
|
||||||
|
"error": updateErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||||
|
"success": true,
|
||||||
|
"message": "successfully updated student",
|
||||||
|
"result": result,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentPassword(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentLocker(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentAddress(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentYOG(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentContacts(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentPhoto(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStudentEmail(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateTeacherHomeroom(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateTeacherPassword(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateTeacherAddress(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateTeacherPhoto(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateTeacherEmail(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateTeacherName(c *fiber.Ctx) error {
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if admin sent request
|
||||||
|
if data["aid"] == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "admin id required",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var admin models.Admin
|
||||||
|
err := adminCollection.FindOne(ctx, bson.M{"aid": data["aid"]}).Decode(&admin)
|
||||||
|
if err != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "invalid admin id",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check id and names are included
|
||||||
|
if data["_id"] == "" || data["firstname"] == "" || data["middlename"] == "" || data["lastname"] == "" {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "missing required fields",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
teacherObjectId, idErr := primitive.ObjectIDFromHex(data["_id"])
|
||||||
|
if idErr != nil {
|
||||||
|
cancel()
|
||||||
|
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
|
||||||
|
"success": false,
|
||||||
|
"message": "teacher not found",
|
||||||
|
"error": idErr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
update_time, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339))
|
||||||
|
update := bson.M{
|
||||||
|
"$set": bson.M{
|
||||||
|
"firstname": data["firstname"],
|
||||||
|
"middlename": data["middlename"],
|
||||||
|
"lastname": data["lastname"],
|
||||||
|
"updated_at": update_time,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, updateErr := teacherCollection.UpdateOne(
|
||||||
|
ctx,
|
||||||
|
bson.M{"_id": teacherObjectId},
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateContactName(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateContactAddress(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateContactPhone(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateContactEmail(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateContactPriority(c *fiber.Ctx) error {
|
||||||
|
return c.Status(fiber.StatusNotImplemented).JSON(fiber.Map{
|
||||||
|
"success": nil,
|
||||||
|
"message": "not implimented",
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in new issue
Block a user