Add password field for students and teachers

This commit is contained in:
raul 2024-12-09 17:58:00 +01:00
parent 2ab9b83b43
commit 8a7202ffd7
Signed by: raul
GPG Key ID: C1AA797073F17129
2 changed files with 15 additions and 13 deletions

View File

@ -106,19 +106,19 @@ func server() {
func getUser(c *gin.Context) {
id := c.Param("userid")
user := user{}
err := db.QueryRow("SELECT * FROM alumnos WHERE id_alumno = "+id).Scan(&user.Id, &user.Name, &user.Surname1, &user.Surname2, &user.Email)
err := db.QueryRow("SELECT id_alumno,nombre,apellido1,apellido2,email FROM alumnos WHERE id_alumno = "+id).Scan(&user.Id, &user.Name, &user.Surname1, &user.Surname2, &user.Email)
if err != nil {
e := fmt.Sprintf("SOMETHING BAD HAPPENED QUERYING THE DATABASE: %v\n", err)
log.Print(e)
c.String(http.StatusInternalServerError, e)
return
}
c.JSON(http.StatusOK, user)
c.IndentedJSON(http.StatusOK, user)
}
func getUsers(c *gin.Context) {
users := []user{}
rows, err := db.Query("SELECT * FROM alumnos")
rows, err := db.Query("SELECT id_alumno,nombre,apellido1,apellido2,email FROM alumnos")
if err != nil {
e := fmt.Sprintf("SOMETHING BAD HAPPENED QUERYING THE DATABASE: %v\n", err)
log.Print(e)
@ -137,7 +137,7 @@ func getUsers(c *gin.Context) {
}
users = append(users, user)
}
c.JSON(http.StatusOK, users)
c.IndentedJSON(http.StatusOK, users)
}
// func createUser(c *gin.Context) {

View File

@ -4,7 +4,8 @@ CREATE TABLE ALUMNOS (
nombre VARCHAR(255) NOT NULL,
apellido1 VARCHAR(255),
apellido2 VARCHAR(255),
email VARCHAR(255) NOT NULL
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL
);
CREATE TABLE PROFESORES (
@ -12,7 +13,8 @@ CREATE TABLE PROFESORES (
nombre VARCHAR(255) NOT NULL,
apellido1 VARCHAR(255),
apellido2 VARCHAR(255),
email VARCHAR(255) NOT NULL
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL
);
CREATE TABLE CUESTIONARIOS (
@ -48,15 +50,15 @@ CREATE TABLE JUEGA (
);
-- add test data
INSERT INTO ALUMNOS (nombre, apellido1, apellido2, email)
VALUES ('Raúl', 'Bulgariu', 'Suciu', 'raul@bulgariu.xyz'),
('Pepito', 'Prueba', 'de Ejemplo', 'pepito@gmail.com');
INSERT INTO ALUMNOS (nombre, apellido1, apellido2, email, password)
VALUES ('Raúl', 'Bulgariu', 'Suciu', 'raul@bulgariu.xyz', 'ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f'),
('Pepito', 'Prueba', 'de Ejemplo', 'pepito@gmail.com', 'ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f');
INSERT INTO PROFESORES (nombre, apellido1, apellido2, email)
VALUES ('Jacinto', 'Sánchez', 'Villa', 'j.sanchezvilla@gmail.com');
INSERT INTO PROFESORES (nombre, apellido1, apellido2, email, password)
VALUES ('Jacinto', 'Sánchez', 'Villa', 'j.sanchezvilla@gmail.com', 'ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f');
INSERT INTO PROFESORES (nombre, apellido1, email)
VALUES ('David', 'Balaguer', 'david@gmail.com');
INSERT INTO PROFESORES (nombre, apellido1, email, password)
VALUES ('David', 'Balaguer', 'david@gmail.com', 'ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f');
INSERT INTO CUESTIONARIOS (id_profesor, titulo, descripcion)
VALUES (1, 'Examen SOM', 'Cuestionario con preguntas sobre SOM'),