Skip to content

Commit

Permalink
Merge pull request #260 from markalbrand56/backend
Browse files Browse the repository at this point in the history
Backend
  • Loading branch information
markalbrand56 authored Nov 19, 2023
2 parents 91cf89c + a6ebf30 commit 282dd84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions backend/controllers/students.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/auth_student_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 282dd84

Please sign in to comment.