Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend #260

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading