Minor updates and comments
This commit is contained in:
1 parent
ff65d9eadc
commit
0a95f847d4
5 files changed
+14
-3
No files matched your search
@@ -170,6 +170,7 @@ func RegisterTeacher(c *fiber.Ctx) error {
|
|||||||
// Send teacher personal email temp password
|
// Send teacher personal email temp password
|
||||||
|
|
||||||
var tid string
|
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 {
|
for {
|
||||||
tid = GenerateID()
|
tid = GenerateID()
|
||||||
isValid := ValidateID(tid)
|
isValid := ValidateID(tid)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func ValidateID(id string) bool { // true: valid id, false: id already in use
|
|||||||
var foundID models.Id
|
var foundID models.Id
|
||||||
err := idCollection.FindOne(ctx, bson.M{"cid": id}).Decode(&foundID)
|
err := idCollection.FindOne(ctx, bson.M{"cid": id}).Decode(&foundID)
|
||||||
cancel()
|
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
|
var newID models.Id
|
||||||
newID.CID = id
|
newID.CID = id
|
||||||
newID.ID = primitive.NewObjectID()
|
newID.ID = primitive.NewObjectID()
|
||||||
|
|||||||
@@ -4,6 +4,16 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"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 {
|
type Id struct {
|
||||||
ID primitive.ObjectID `bson:"_id"`
|
ID primitive.ObjectID `bson:"_id"`
|
||||||
CID string `bson:"cid"` // custom id for admin, teahcer or student
|
CID string `bson:"cid"` // custom id for admin, teahcer or student
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ type Student struct {
|
|||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
City string `json:"city"`
|
City string `json:"city"`
|
||||||
Province string `json:"province"`
|
Province string `json:"province"`
|
||||||
Postal string `json:"pc"` // Postal Code
|
Postal string `json:"postal"`
|
||||||
DOB string `json:"dob" validate:"required"`
|
DOB string `json:"dob" validate:"required"`
|
||||||
Photo string `json:"photo"`
|
Photo string `json:"photo"`
|
||||||
Contacts []string `json:"contacts"` // List of contact ID's rather than contact object
|
Contacts []string `json:"contacts"` // List of contact ID's rather than contact object
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ type Teacher struct {
|
|||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
City string `json:"city"`
|
City string `json:"city"`
|
||||||
Province string `json:"province"`
|
Province string `json:"province"`
|
||||||
Postal string `json:"pc"` // Postal Code
|
Postal string `json:"postal"`
|
||||||
DOB string `json:"dob" validate:"required"`
|
DOB string `json:"dob" validate:"required"`
|
||||||
Photo string `json:"string"`
|
Photo string `json:"string"`
|
||||||
Created_at time.Time `json:"created_at"`
|
Created_at time.Time `json:"created_at"`
|
||||||
|
|||||||
Reference in new issue
Block a user