diff --git a/backend/controllers/students.go b/backend/controllers/students.go index e2930050..467419b8 100644 --- a/backend/controllers/students.go +++ b/backend/controllers/students.go @@ -11,7 +11,7 @@ import ( "time" ) -// stores the input from frontend (Estudiante, JSON) +// EstudianteInput stores the input from frontend (Estudiante, JSON) type EstudianteInput struct { Dpi string `json:"dpi"` Nombre string `json:"nombre"` @@ -25,7 +25,7 @@ type EstudianteInput struct { Universidad string `json:"universidad"` } -// Creates a new user (type Estudiante). +// NewStudent Creates a new user (type Estudiante). func NewStudent(c *gin.Context) { var input EstudianteInput @@ -41,6 +41,16 @@ func NewStudent(c *gin.Context) { // parsing of the date (SQL format) t, _ := time.Parse("2006-01-02", input.Nacimiento) + // revisar que el DPI tenga 13 caracteres + if len(input.Dpi) != 13 { + c.JSON(http.StatusBadRequest, responses.StandardResponse{ + Status: http.StatusBadRequest, + Message: "DPI must have 13 characters", + Data: nil, + }) + return + } + // Creates a new instance of Estudiante with the input data (local) e := models.Estudiante{ IdEstudiante: input.Correo, diff --git a/backend/tests/auth_student_test.go b/backend/tests/auth_student_test.go index 70b0a534..b1675014 100644 --- a/backend/tests/auth_student_test.go +++ b/backend/tests/auth_student_test.go @@ -84,7 +84,7 @@ func TestNewStudent(t *testing.T) { w := httptest.NewRecorder() - jsonData := `{"dpi": "101010101010", "nombre": "Estudiante", "apellido": "Prueba", "nacimiento": "01/01/2001", "correo": "estudiante@prueba.com", "telefono": "12345678", "carrera": 1, "semestre": 4, "contra": "estudianteprueba", "CV": "", "foto": "", "universidad": "Universidad del Valle de Guatemala"}` + jsonData := `{"dpi": "1010101010101", "nombre": "Estudiante", "apellido": "Prueba", "nacimiento": "01/01/2001", "correo": "estudiante@prueba.com", "telefono": "12345678", "carrera": 1, "semestre": 4, "contra": "estudianteprueba", "CV": "", "foto": "", "universidad": "Universidad del Valle de Guatemala"}` body := bytes.NewBufferString(jsonData)