Merge teachers and students into one table
Using the AccountType attribute to store the user type
This commit is contained in:
parent
1205572f1e
commit
e13e9e2019
|
@ -124,19 +124,23 @@ func createUser(c *gin.Context) {
|
||||||
}
|
}
|
||||||
secret := hashPW(newuser.Password)
|
secret := hashPW(newuser.Password)
|
||||||
var dynStmt string
|
var dynStmt string
|
||||||
if newuser.IsTeacher == true {
|
if newuser.AccountType != "estudiante" && newuser.AccountType != "profesor" {
|
||||||
dynStmt = `INSERT INTO profesores(nombre, apellido1, apellido2, email, password) values($1, $2, $3, $4, $5)`
|
if newuser.AccountType == "admin" {
|
||||||
} else {
|
c.String(http.StatusTeapot, "https://xkcd.com/327/\n")
|
||||||
dynStmt = `INSERT INTO alumnos(nombre, apellido1, apellido2, email, password) values($1, $2, $3, $4, $5)`
|
return
|
||||||
|
}
|
||||||
|
c.String(http.StatusNotFound, "Invalid account type\n")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
_, err := db.Exec(dynStmt, newuser.Name, newuser.Surname1, newuser.Surname2, newuser.Email, secret)
|
dynStmt = `INSERT INTO usuarios(nombre, apellido1, apellido2, email, password, rol) values($1, $2, $3, $4, $5, $6)`
|
||||||
|
_, err := db.Exec(dynStmt, newuser.Name, newuser.Surname1, newuser.Surname2, newuser.Email, secret, newuser.AccountType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := fmt.Sprintf("Something went wrong trying to create the user: %v\n", err)
|
e := fmt.Sprintf("Something went wrong trying to create the user: %v\n", err)
|
||||||
log.Print(e)
|
log.Print(e)
|
||||||
c.String(http.StatusInternalServerError, e)
|
c.String(http.StatusInternalServerError, e)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.String(http.StatusOK, "Success!")
|
c.String(http.StatusOK, "Success!\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUser(c *gin.Context) {
|
func getUser(c *gin.Context) {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
type user struct {
|
type user struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
Name string `json:"nombre"`
|
Name string `json:"nombre"`
|
||||||
Surname1 string `json:"apellido1"`
|
Surname1 string `json:"apellido1"`
|
||||||
Surname2 string `json:"apellido2"`
|
Surname2 string `json:"apellido2"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
IsTeacher bool `json:"esprofesor"`
|
AccountType string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue