diff --git a/controllers/authController.go b/controllers/authController.go index 51914e3..8387c95 100644 --- a/controllers/authController.go +++ b/controllers/authController.go @@ -170,6 +170,7 @@ func RegisterTeacher(c *fiber.Ctx) error { // Send teacher personal email temp password var tid string + // For the unlikely event that an ID is already in use this will simply try again till it gets a id not in use for { tid = GenerateID() isValid := ValidateID(tid) diff --git a/controllers/idManager.go b/controllers/idManager.go index cae08fb..38c64d7 100644 --- a/controllers/idManager.go +++ b/controllers/idManager.go @@ -22,7 +22,7 @@ func ValidateID(id string) bool { // true: valid id, false: id already in use var foundID models.Id err := idCollection.FindOne(ctx, bson.M{"cid": id}).Decode(&foundID) cancel() - if err != nil { + if err != nil { // If there is no id found create new ID object to be stored and return true (unless insert error then try again) var newID models.Id newID.CID = id newID.ID = primitive.NewObjectID() diff --git a/models/idModel.go b/models/idModel.go index 976d882..fd45ad7 100644 --- a/models/idModel.go +++ b/models/idModel.go @@ -4,6 +4,16 @@ import ( "go.mongodb.org/mongo-driver/bson/primitive" ) +/* + This is a stupid Idea but in the cids collection + is a list of all id's (student id's [sid], teacher + id's [tid], or admin id's [aid]) this way when + generating a new id for a new user, only the cids + collection has to be searched to see the id is + already in use. Rather than looking in the admin, + teacher, and student collections to check an id. +*/ + type Id struct { ID primitive.ObjectID `bson:"_id"` CID string `bson:"cid"` // custom id for admin, teahcer or student diff --git a/models/studentModel.go b/models/studentModel.go index 7086a26..4bed5cf 100644 --- a/models/studentModel.go +++ b/models/studentModel.go @@ -30,7 +30,7 @@ type Student struct { Address string `json:"address"` City string `json:"city"` Province string `json:"province"` - Postal string `json:"pc"` // Postal Code + Postal string `json:"postal"` DOB string `json:"dob" validate:"required"` Photo string `json:"photo"` Contacts []string `json:"contacts"` // List of contact ID's rather than contact object diff --git a/models/teacherModel.go b/models/teacherModel.go index 525a62a..0110685 100644 --- a/models/teacherModel.go +++ b/models/teacherModel.go @@ -32,7 +32,7 @@ type Teacher struct { Address string `json:"address"` City string `json:"city"` Province string `json:"province"` - Postal string `json:"pc"` // Postal Code + Postal string `json:"postal"` DOB string `json:"dob" validate:"required"` Photo string `json:"string"` Created_at time.Time `json:"created_at"`