From 554cda7e17732fda463332f3dbf8cc2bf17eaafd Mon Sep 17 00:00:00 2001 From: Javier Alejandro Azurdia Arrecis Date: Thu, 16 Nov 2023 20:46:56 -0600 Subject: [PATCH 1/8] Update files.go Comments and Final check --- backend/controllers/files.go | 56 +++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/backend/controllers/files.go b/backend/controllers/files.go index ae383502..d15da215 100644 --- a/backend/controllers/files.go +++ b/backend/controllers/files.go @@ -15,12 +15,13 @@ import ( "strings" ) +// Updates the profile picture of the user func UpdateProfilePicture() gin.HandlerFunc { return func(c *gin.Context) { - user, err := utils.TokenExtractUsername(c) + user, err := utils.TokenExtractUsername(c) // get the username from the token acceptedFileTypes := []string{"png", "jpg", "jpeg"} - if err != nil { + if err != nil { // if the token is invalid c.JSON(http.StatusUnauthorized, responses.StandardResponse{ Status: http.StatusUnauthorized, Message: "Unauthorized. Cannot get information from token. " + err.Error(), @@ -34,12 +35,12 @@ func UpdateProfilePicture() gin.HandlerFunc { fmt.Println("Username upload: " + user_stripped) // single file - fileHeader, _ := c.FormFile("file") + fileHeader, _ := c.FormFile("file") // get the file from the request // get the file type from filename fileType := fileHeader.Filename[strings.LastIndex(fileHeader.Filename, ".")+1:] - if !utils.Contains(acceptedFileTypes, fileType) { + if !utils.Contains(acceptedFileTypes, fileType) { // if the file type is not accepted c.JSON(http.StatusBadRequest, responses.StandardResponse{ Status: http.StatusBadRequest, Message: "Invalid file type. Accepted file types are " + strings.Join(acceptedFileTypes, ", "), @@ -48,12 +49,12 @@ func UpdateProfilePicture() gin.HandlerFunc { return } + // generate a random image. randomNumber := rand.Intn(9999999999-1111111111) + 1111111111 newFileName := user_stripped + "_" + fmt.Sprint(randomNumber) + "." + fileType fileHeader.Filename = newFileName - - dst := "./uploads/" + newFileName + dst := "./uploads/" + newFileName // destination // Eliminar archivos antiguos con el mismo prefijo de usuario if err := deleteFilesWithPrefix("./uploads/", user_stripped); err != nil { @@ -77,6 +78,7 @@ func UpdateProfilePicture() gin.HandlerFunc { return } + // Update the profile picture in the database if userType == "student" { err = configs.DB.Model(&models.Estudiante{}).Where("correo = ?", user).Updates(models.Estudiante{Foto: newFileName}).Error } else if userType == "enterprise" { @@ -118,6 +120,7 @@ func UpdateProfilePicture() gin.HandlerFunc { return } + // return the filename to the client c.JSON(http.StatusOK, responses.StandardResponse{ Status: http.StatusOK, Message: "File uploaded successfully", @@ -128,12 +131,13 @@ func UpdateProfilePicture() gin.HandlerFunc { } } +// Updates the CV of the user func UpdateCV() gin.HandlerFunc { return func(c *gin.Context) { user, err := utils.TokenExtractUsername(c) acceptedFileTypes := []string{"pdf"} - if err != nil { + if err != nil { // if the token is invalid c.JSON(http.StatusUnauthorized, responses.StandardResponse{ Status: http.StatusUnauthorized, Message: "Unauthorized. Cannot get information from token. " + err.Error(), @@ -144,7 +148,7 @@ func UpdateCV() gin.HandlerFunc { // strip username from email. ignoring everything after @ user_stripped := user[:strings.Index(user, "@")] - fmt.Println("Username upload: " + user_stripped) + fmt.Println("Username upload: " + user_stripped) // single file (print-debbuging) // single file file, _ := c.FormFile("file") @@ -161,6 +165,7 @@ func UpdateCV() gin.HandlerFunc { return } + // generate a random image. randomNumber := rand.Intn(9999999999-1111111111) + 1111111111 newFileName := user_stripped + "_" + fmt.Sprint(randomNumber) + "." + fileType @@ -191,6 +196,7 @@ func UpdateCV() gin.HandlerFunc { return } + // Update the profile picture in the database if userType != "student" { c.JSON(http.StatusUnauthorized, responses.StandardResponse{ Status: http.StatusUnauthorized, @@ -200,6 +206,7 @@ func UpdateCV() gin.HandlerFunc { return } + // Update the profile picture in the database err = configs.DB.Model(&models.Estudiante{}).Where("correo = ?", user).Updates(models.Estudiante{CV: newFileName}).Error // Save locally @@ -236,6 +243,7 @@ func UpdateCV() gin.HandlerFunc { return } + // return the filename to the client c.JSON(http.StatusOK, responses.StandardResponse{ Status: http.StatusOK, Message: "File uploaded successfully", @@ -246,26 +254,26 @@ func UpdateCV() gin.HandlerFunc { } } +// Deletes the profile picture of the user func deleteFilesWithPrefix(directory, prefix string) error { - files, err := os.ReadDir(directory) + files, err := os.ReadDir(directory) // read the directory if err != nil { return err - } + } // iterate over the files for _, file := range files { - //fmt.Println(file.Name()) - if strings.HasPrefix(file.Name(), prefix) { + if strings.HasPrefix(file.Name(), prefix) { // if the file starts with the prefix filePath := filepath.Join(directory, file.Name()) - fmt.Println("Deleting file: " + filePath) + fmt.Println("Deleting file: " + filePath) // delete the file if err := os.Remove(filePath); err != nil { return err } } } - return nil } +// Returns the profile picture of the user func GetProfilePicture() gin.HandlerFunc { return func(c *gin.Context) { filename := c.Param("filename") @@ -282,9 +290,9 @@ func GetProfilePicture() gin.HandlerFunc { return } - defer func(Body io.ReadCloser) { + defer func(Body io.ReadCloser) { // Cerrar el cuerpo de la respuesta del servidor de archivos externo err := Body.Close() - if err != nil { + if err != nil { // Si hay un error al cerrar el cuerpo de la respuesta del servidor de archivos externo c.JSON(http.StatusInternalServerError, responses.StandardResponse{ Status: http.StatusInternalServerError, Message: "Error al cerrar el cuerpo de la respuesta del servidor de archivos externo: " + err.Error(), @@ -294,7 +302,7 @@ func GetProfilePicture() gin.HandlerFunc { } }(resp.Body) - if resp.StatusCode != http.StatusOK { + if resp.StatusCode != http.StatusOK { // Si el código de estado de la respuesta del servidor de archivos externo no es 200 c.JSON(http.StatusNotFound, responses.StandardResponse{ Status: http.StatusNotFound, Message: "Archivo no encontrado en el servidor de archivos externo", @@ -321,14 +329,15 @@ func GetProfilePicture() gin.HandlerFunc { } } +// Returns the CV of the user func GetCV() gin.HandlerFunc { return func(c *gin.Context) { - filename := c.Param("filename") - fileURL := configs.FileServer + "pdf/" + filename + filename := c.Param("filename") // Obtener el nombre del archivo de la URL + fileURL := configs.FileServer + "pdf/" + filename // Construir la URL del servidor de archivos externo // Realizar una solicitud GET al servidor de archivos externo resp, err := http.Get(fileURL) - if err != nil { + if err != nil { // Si hay un error al realizar la solicitud GET, devolver un error al cliente c.JSON(http.StatusNotFound, responses.StandardResponse{ Status: http.StatusNotFound, Message: "Error al obtener el archivo: " + err.Error(), @@ -337,9 +346,10 @@ func GetCV() gin.HandlerFunc { return } + // Cerrar el cuerpo de la respuesta del servidor de archivos externo defer func(Body io.ReadCloser) { err := Body.Close() - if err != nil { + if err != nil { // Si hay un error al cerrar el cuerpo de la respuesta del servidor de archivos externo c.JSON(http.StatusInternalServerError, responses.StandardResponse{ Status: http.StatusInternalServerError, Message: "Error al cerrar el cuerpo de la respuesta del servidor de archivos externo: " + err.Error(), @@ -347,9 +357,9 @@ func GetCV() gin.HandlerFunc { }) return } - }(resp.Body) + }(resp.Body) // Cerrar el cuerpo de la respuesta del servidor de archivos externo - if resp.StatusCode != http.StatusOK { + if resp.StatusCode != http.StatusOK { // Si el código de estado de la respuesta del servidor de archivos externo no es 200 c.JSON(http.StatusNotFound, responses.StandardResponse{ Status: http.StatusNotFound, Message: "Archivo no encontrado en el servidor de archivos externo", From 83d7c0eed884621ecbb42aea96ba1fdb7c4baa12 Mon Sep 17 00:00:00 2001 From: Javier Alejandro Azurdia Arrecis Date: Thu, 16 Nov 2023 20:54:45 -0600 Subject: [PATCH 2/8] Update offer.go Comments and final check --- backend/controllers/offer.go | 59 ++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/backend/controllers/offer.go b/backend/controllers/offer.go index 0c0c2405..9ef211f1 100644 --- a/backend/controllers/offer.go +++ b/backend/controllers/offer.go @@ -12,6 +12,7 @@ import ( "time" ) +// Offer as they arrive from frontend type OfferInput struct { IDEmpresa string `json:"id_empresa"` Puesto string `json:"puesto"` @@ -24,6 +25,7 @@ type OfferInput struct { HoraFin time.Time `json:"hora_fin"` } +// Processing offer (backend) type AfterInsert struct { IdOferta int `json:"id_oferta"` IDEmpresa string `json:"id_empresa"` @@ -36,15 +38,17 @@ type AfterInsert struct { HoraFin time.Time `json:"hora_fin"` } +// Processing offer_carrera (backend) type AfterInsert2 struct { IdOferta int `json:"id_oferta"` IdCarrera int `json:"id_carrera"` } +// Creates a new offer in the database func NewOffer(c *gin.Context) { var input OfferInput - if err := c.BindJSON(&input); err != nil { + if err := c.BindJSON(&input); err != nil { // If the input is not valid, return an error c.JSON(http.StatusBadRequest, responses.StandardResponse{ Status: http.StatusBadRequest, Message: "Invalid input: " + err.Error(), @@ -53,9 +57,10 @@ func NewOffer(c *gin.Context) { return } + // extract the username from the token user, err := utils.TokenExtractUsername(c) - if err != nil { + if err != nil { // If the token is not valid, return an error c.JSON(http.StatusBadRequest, responses.StandardResponse{ Status: http.StatusBadRequest, Message: "Error extracting information from token: " + err.Error(), @@ -64,7 +69,7 @@ func NewOffer(c *gin.Context) { return } - if user != input.IDEmpresa { + if user != input.IDEmpresa { // If the user in the token does not match the one in the request body, return an error c.JSON(http.StatusForbidden, responses.StandardResponse{ Status: http.StatusForbidden, Message: "The user in the token does not match the one in the request body", @@ -73,6 +78,7 @@ func NewOffer(c *gin.Context) { return } + // Create the offer object offer := models.Oferta{ IDEmpresa: input.IDEmpresa, Puesto: input.Puesto, @@ -84,10 +90,11 @@ func NewOffer(c *gin.Context) { HoraFin: input.HoraFin, } + // Insert into oferta table var inserted AfterInsert err = configs.DB.Raw("INSERT INTO oferta (id_empresa, puesto, descripcion, requisitos, salario, jornada, hora_inicio, hora_fin) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id_oferta, id_empresa, puesto, descripcion, requisitos, salario, jornada, hora_inicio, hora_fin", offer.IDEmpresa, offer.Puesto, offer.Descripcion, offer.Requisitos, offer.Salario, offer.Jornada, offer.HoraInicio, offer.HoraFin).Scan(&inserted).Error - if err != nil { + if err != nil { // If the insertion fails, return an error c.JSON(http.StatusBadRequest, responses.StandardResponse{ Status: http.StatusBadRequest, Message: "Error creating offer: " + err.Error(), @@ -110,6 +117,7 @@ func NewOffer(c *gin.Context) { } } + // Return a success response c.JSON(http.StatusOK, responses.StandardResponse{ Status: http.StatusOK, Message: "Offer created successfully", @@ -118,6 +126,7 @@ func NewOffer(c *gin.Context) { } +// Stores the offer as arrived from frontend type OfferUpdateInput struct { Id_Oferta int `json:"id_oferta"` IDEmpresa string `json:"id_empresa"` @@ -127,13 +136,14 @@ type OfferUpdateInput struct { Salario float64 `json:"salario"` IdCarreras []string `json:"id_carreras"` Jornada string `json:"jornada"` - HoraInicio time.Time `json:"hora_inicio"` + HoraInicio time.Time `json:"hora_inicio"` // this parameters are new. HoraFin time.Time `json:"hora_fin"` } +// Updates an offer in the database func UpdateOffer(c *gin.Context) { - var input OfferUpdateInput - var updatedOffer models.Oferta + var input OfferUpdateInput // Stores the offer as arrived from frontend + var updatedOffer models.Oferta // Stores the object to be updated if err := c.BindJSON(&input); err != nil { c.JSON(http.StatusBadRequest, responses.StandardResponse{ @@ -144,6 +154,7 @@ func UpdateOffer(c *gin.Context) { return } + // extract the username from the token user, err := utils.TokenExtractUsername(c) if err != nil { @@ -155,6 +166,7 @@ func UpdateOffer(c *gin.Context) { return } + // Verificación con el token para que no se pueda editar ofertas de otras empresas originalOffer := models.Oferta{} err = configs.DB.Where("id_oferta = ? AND id_empresa = ?", input.Id_Oferta, input.IDEmpresa).First(&originalOffer).Error @@ -167,6 +179,7 @@ func UpdateOffer(c *gin.Context) { return } + // Verificación con el token para que no se pueda editar ofertas de otras empresas if originalOffer.IDEmpresa != user { c.JSON(http.StatusForbidden, responses.StandardResponse{ Status: http.StatusForbidden, @@ -176,6 +189,7 @@ func UpdateOffer(c *gin.Context) { return } + // Verificación con el token para que no se pueda editar ofertas de otras empresas if user != input.IDEmpresa { c.JSON(http.StatusForbidden, responses.StandardResponse{ Status: http.StatusForbidden, @@ -185,6 +199,7 @@ func UpdateOffer(c *gin.Context) { return } + // Create the offer object updatedOffer = models.Oferta{ Puesto: input.Puesto, Descripcion: input.Descripcion, @@ -195,6 +210,7 @@ func UpdateOffer(c *gin.Context) { HoraFin: input.HoraFin, } + // Update oferta table err = configs.DB.Model(&updatedOffer).Where("id_oferta = ? AND id_empresa = ?", input.Id_Oferta, input.IDEmpresa).Updates(updatedOffer).Error if err != nil { @@ -248,6 +264,7 @@ func UpdateOffer(c *gin.Context) { } } + // Return a success response c.JSON(http.StatusOK, responses.StandardResponse{ Status: http.StatusOK, Message: "Offer updated successfully", @@ -255,10 +272,12 @@ func UpdateOffer(c *gin.Context) { }) } +// stores only the ID of the offer. Was developed in early stages of the project and should be deprecated, but we wont. type OfferGet struct { Id_Oferta string `json:"id_oferta"` } +// Returns the offer with the given ID func GetOffer(c *gin.Context) { var offer models.OfertaGet var Company models.Empresa @@ -274,6 +293,7 @@ func GetOffer(c *gin.Context) { return } + // gets the offer id from the input err := configs.DB.Where("id_oferta = ?", input.Id_Oferta).First(&offer).Error if err != nil { @@ -285,6 +305,7 @@ func GetOffer(c *gin.Context) { return } + // gets the company id from the offer err = configs.DB.Where("id_empresa = ?", offer.IDEmpresa).First(&Company).Error if err != nil { @@ -308,6 +329,7 @@ func GetOffer(c *gin.Context) { }) } +// stores the ID of the offer and the ID of the company. type GetOfferByCompanyInput struct { Id_Empresa string `json:"id_empresa"` } @@ -325,6 +347,7 @@ type GetOfferByCompanyResponse struct { HoraFin time.Time `json:"hora_fin"` } +// Returns all the offers from the company with the given ID func GetOfferByCompany(c *gin.Context) { var offersResponse []GetOfferByCompanyResponse var data map[string]interface{} @@ -339,6 +362,7 @@ func GetOfferByCompany(c *gin.Context) { return } + // gets a lot of information from the database query := ` SELECT o.id_oferta, @@ -360,7 +384,7 @@ func GetOfferByCompany(c *gin.Context) { ` - rows, err := configs.DB.Raw(query, input.Id_Empresa).Rows() + rows, err := configs.DB.Raw(query, input.Id_Empresa).Rows() // Execute the query if err != nil { c.JSON(http.StatusBadRequest, responses.StandardResponse{ Status: http.StatusBadRequest, @@ -369,7 +393,7 @@ func GetOfferByCompany(c *gin.Context) { }) return } - defer func(rows *sql.Rows) { + defer func(rows *sql.Rows) { // Close the rows when the function returns err := rows.Close() if err != nil { c.JSON(http.StatusBadRequest, responses.StandardResponse{ @@ -386,6 +410,7 @@ func GetOfferByCompany(c *gin.Context) { // ... + // Iterate over the rows for rows.Next() { var offer GetOfferByCompanyResponse var idOferta int @@ -446,10 +471,12 @@ func GetOfferByCompany(c *gin.Context) { }) } +// stores the ID of the offer and the ID of the company. type DeleteOfferInput struct { Id_Oferta string `json:"id_oferta"` } +// Deletes the offer with the given ID func DeleteOffer(c *gin.Context) { // Obtén el valor del parámetro "id_oferta" desde los query parameters idOferta := c.Query("id_oferta") @@ -514,11 +541,12 @@ func DeleteOffer(c *gin.Context) { }) } +// get aplicants from an offer func GetApplicants(c *gin.Context) { - var input GetPostulationInput - var tokenUsername string + var input GetPostulationInput // Stores the offer as arrived from frontend + var tokenUsername string // Stores the username extracted from the token - if err := c.ShouldBindJSON(&input); err != nil { + if err := c.ShouldBindJSON(&input); err != nil { // If the input is not valid, return an error c.JSON(http.StatusBadRequest, responses.StandardResponse{ Status: http.StatusBadRequest, Message: "Invalid input. " + err.Error(), @@ -527,6 +555,7 @@ func GetApplicants(c *gin.Context) { return } + // extract the username from the token tokenUsername, err := utils.TokenExtractUsername(c) if err != nil { @@ -543,6 +572,7 @@ func GetApplicants(c *gin.Context) { err = configs.DB.Where("id_oferta = ?", input.IdOferta).First(&offer).Error if err != nil { + // If the offer does not exist, return an error c.JSON(http.StatusNotFound, responses.StandardResponse{ Status: http.StatusNotFound, Message: "Error getting offer. " + err.Error(), @@ -560,6 +590,7 @@ func GetApplicants(c *gin.Context) { return } + // Get the postulations and maps them to a slice of maps var results []map[string]interface{} rows, err := configs.DB.Raw("SELECT p.id_estudiante, p.estado, e.nombre, e.apellido, e.nacimiento, e.foto, e.carrera, e.universidad FROM postulacion p JOIN estudiante e ON p.id_estudiante = e.id_estudiante WHERE id_oferta = ?", input.IdOferta).Rows() @@ -572,6 +603,7 @@ func GetApplicants(c *gin.Context) { }) return } + // Close the rows when the function returns defer func(rows *sql.Rows) { err := rows.Close() if err != nil { @@ -584,6 +616,7 @@ func GetApplicants(c *gin.Context) { } }(rows) + // Iterate over the rows for rows.Next() { var idEstudiante string var estado string @@ -605,7 +638,7 @@ func GetApplicants(c *gin.Context) { return } - result := map[string]interface{}{ + result := map[string]interface{}{ // Create a map to store the postulation details "id_estudiante": idEstudiante, "estado": estado, "nombre": nombre, From 4e8d85995bcf0f195fb12437792755725f5aa7d0 Mon Sep 17 00:00:00 2001 From: Javier Alejandro Azurdia Arrecis Date: Thu, 16 Nov 2023 21:02:05 -0600 Subject: [PATCH 3/8] Update postulation.go comments and final check --- backend/controllers/postulation.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/controllers/postulation.go b/backend/controllers/postulation.go index e2cbc79b..b5c4fa55 100644 --- a/backend/controllers/postulation.go +++ b/backend/controllers/postulation.go @@ -12,16 +12,19 @@ import ( "time" ) +// stores the input from frontend type PostulationInput struct { IdOferta int `json:"id_oferta"` IdEstudiante string `json:"id_estudiante"` Estado string `json:"estado"` } +// Postulation Input stores the input from frontend type GetPostulationInput struct { IdOferta int `json:"id_oferta"` } +// Puesto Result stores the result from the query type PuestoResult struct { Puesto string } @@ -38,6 +41,7 @@ func NewPostulation(c *gin.Context) { return } + // gets the user from the token user, err := utils.TokenExtractUsername(c) if err != nil { @@ -49,6 +53,7 @@ func NewPostulation(c *gin.Context) { return } + // verify that the token user is the same as the input user if user != input.IdEstudiante { c.JSON(http.StatusForbidden, responses.StandardResponse{ Status: http.StatusForbidden, @@ -58,14 +63,17 @@ func NewPostulation(c *gin.Context) { return } + // store the postulation postulation := models.Postulacion{ IdOferta: input.IdOferta, IdEstudiante: input.IdEstudiante, Estado: input.Estado, } + // insert the postulation var inserted models.PostulacionGet + // query to insert the postulation err = configs.DB.Raw("INSERT INTO postulacion (id_oferta, id_estudiante, estado) VALUES (?, ?, ?) RETURNING id_postulacion, id_oferta, id_estudiante, estado", postulation.IdOferta, postulation.IdEstudiante, postulation.Estado).Scan(&inserted).Error if err != nil { @@ -86,6 +94,7 @@ func NewPostulation(c *gin.Context) { return } + // Obtener el valor de "puesto" de la oferta var resultado PuestoResult // Obtener el valor de "puesto" de la oferta @@ -122,6 +131,7 @@ func NewPostulation(c *gin.Context) { }) } +// postulation result stores the result from the query type PostulationResult struct { IDEstudiante string `json:"id_estudiante"` Estado string `json:"estado"` @@ -139,6 +149,7 @@ type PostulationResult struct { Universidad string `json:"universidad"` } +// GetOfferPreviews retrieves the previews of the offers func GetOfferPreviews(c *gin.Context) { var postulations []models.ViewPrevPostulaciones @@ -156,10 +167,11 @@ func GetOfferPreviews(c *gin.Context) { c.JSON(http.StatusOK, responses.StandardResponse{ Status: http.StatusOK, Message: "Previews of offers retrieved successfully", - Data: map[string]interface{}{"postulations": postulations}, + Data: map[string]interface{}{"postulations": postulations}, // map[string]interface{}{"postulations": postulations}, }) } +// Stores the retrieval of all the postulations of a single student. type PostulationFromStudentResult struct { IDPostulacion int `json:"id_postulacion"` IDOferta int `json:"id_oferta"` @@ -173,6 +185,7 @@ type PostulationFromStudentResult struct { HoraFin time.Time `json:"hora_fin"` } +// GetPostulationFromStudent retrieves all the postulations of a single student func GetPostulationFromStudent(c *gin.Context) { var results []PostulationFromStudentResult var data map[string]interface{} @@ -188,6 +201,7 @@ func GetPostulationFromStudent(c *gin.Context) { return } + // query to get the postulations err = configs.DB.Raw("select id_postulacion, o.id_oferta, id_empresa, puesto, descripcion, requisitos, salario, jornada, hora_inicio, hora_fin from postulacion p join oferta o on p.id_oferta = o.id_oferta where id_estudiante = ?", idEstudiante).Scan(&results).Error if err != nil { @@ -211,6 +225,7 @@ func GetPostulationFromStudent(c *gin.Context) { } +// deletes the postulation. func RetirePostulation(c *gin.Context) { input := c.Query("id_postulacion") user, err := utils.TokenExtractUsername(c) From f6be54d2fb96d7722497418221e3e101555895ef Mon Sep 17 00:00:00 2001 From: Javier Alejandro Azurdia Arrecis Date: Thu, 16 Nov 2023 21:05:25 -0600 Subject: [PATCH 4/8] Update students.go comments and final check --- backend/controllers/students.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/backend/controllers/students.go b/backend/controllers/students.go index 473b4a9a..e2930050 100644 --- a/backend/controllers/students.go +++ b/backend/controllers/students.go @@ -11,6 +11,7 @@ import ( "time" ) +// stores the input from frontend (Estudiante, JSON) type EstudianteInput struct { Dpi string `json:"dpi"` Nombre string `json:"nombre"` @@ -24,6 +25,7 @@ type EstudianteInput struct { Universidad string `json:"universidad"` } +// Creates a new user (type Estudiante). func NewStudent(c *gin.Context) { var input EstudianteInput @@ -36,8 +38,10 @@ func NewStudent(c *gin.Context) { return } + // parsing of the date (SQL format) t, _ := time.Parse("2006-01-02", input.Nacimiento) + // Creates a new instance of Estudiante with the input data (local) e := models.Estudiante{ IdEstudiante: input.Correo, Dpi: input.Dpi, @@ -53,11 +57,14 @@ func NewStudent(c *gin.Context) { Universidad: input.Universidad, } + // Creates a new instance of Usuario with the input data (local) u := models.Usuario{ Usuario: input.Correo, Contra: input.Contra, } + // Both a new user and a new student are created in the database (they are the same) + err := configs.DB.Create(&u).Error // Se agrega el usuario a la base de datos if err != nil { @@ -99,6 +106,7 @@ func NewStudent(c *gin.Context) { }) } +// stores the input from frontend. type EstudianteUpdateInput struct { Nombre string `json:"nombre"` Apellido string `json:"apellido"` @@ -111,6 +119,7 @@ type EstudianteUpdateInput struct { Universidad string `json:"universidad"` } +// Updates the information of a student. func UpdateStudent(c *gin.Context) { var input EstudianteUpdateInput @@ -123,6 +132,7 @@ func UpdateStudent(c *gin.Context) { return } + // Gets the original student from the database var originalStudent models.Estudiante err := configs.DB.Where("id_estudiante = ?", input.Correo).First(&originalStudent).Error @@ -135,6 +145,7 @@ func UpdateStudent(c *gin.Context) { return } + // gets the user from the token user, err := utils.TokenExtractUsername(c) if err != nil { @@ -156,6 +167,7 @@ func UpdateStudent(c *gin.Context) { return } + // Parsing of the date (SQL format) nacimiento, _ := time.Parse("2006-01-02", input.Nacimiento) // Crear una instancia del modelo Estudiante con los datos actualizados @@ -169,6 +181,7 @@ func UpdateStudent(c *gin.Context) { Universidad: input.Universidad, } + // DB query where ALL of the fields are updated. err = configs.DB.Model(&models.Estudiante{}).Where("id_estudiante = ?", input.Correo).Updates(updatedStudent).Error if err != nil { From 1e3dfe335d2073e8752187715239bce981b32d55 Mon Sep 17 00:00:00 2001 From: Javier Alejandro Azurdia Arrecis Date: Thu, 16 Nov 2023 21:08:25 -0600 Subject: [PATCH 5/8] Update README.md minor changes --- backend/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/README.md b/backend/README.md index 345b2738..607296ff 100644 --- a/backend/README.md +++ b/backend/README.md @@ -73,6 +73,7 @@ Empresa } } ``` +----------------- ### [POST] api/users/details Obtener los detalles públicos de un usuario, dado su correo > **Note** @@ -121,7 +122,8 @@ Obtener los detalles públicos de un usuario, dado su correo } } ``` ---- + +----------------- ## Estudiante ### [POST] api/students Crea un estudiante From 0f06a43e29dfabf1e75d7e3d2b3e7aa5559d796f Mon Sep 17 00:00:00 2001 From: Javier Alejandro Azurdia Arrecis Date: Thu, 16 Nov 2023 21:09:21 -0600 Subject: [PATCH 6/8] Update README.md minor changes --- backend/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/README.md b/backend/README.md index 607296ff..8d818b40 100644 --- a/backend/README.md +++ b/backend/README.md @@ -186,7 +186,8 @@ Actualiza un estudiante "data": null } ``` ---- +----------------- + ## Mensajes ### [POST] api/messages/send Crea un mensaje From d5f5e37cc1172f0ce9c85e331a6210b28330d662 Mon Sep 17 00:00:00 2001 From: Javier Alejandro Azurdia Arrecis Date: Thu, 16 Nov 2023 21:13:44 -0600 Subject: [PATCH 7/8] Update README.md minor changes --- backend/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/README.md b/backend/README.md index 8d818b40..3636be85 100644 --- a/backend/README.md +++ b/backend/README.md @@ -304,7 +304,8 @@ Devuelve los mensajes de un chat dado el emisor y el receptor } } ``` ---- +----------------- + ## Empresas ### [POST] api/companies Crea una compañia @@ -645,7 +646,8 @@ Retorna los estudiantes que se han postulado a una oferta } ``` ---- +----------------- + ## Carreras ### [GET] api/careers Devuelve todas las carreras From f85eff6568edc44e8f3f4f5bdd60daf324ee7764 Mon Sep 17 00:00:00 2001 From: Javier Alejandro Azurdia Arrecis Date: Thu, 16 Nov 2023 21:14:32 -0600 Subject: [PATCH 8/8] Update README.md minor changes --- backend/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/README.md b/backend/README.md index 3636be85..26af7eeb 100644 --- a/backend/README.md +++ b/backend/README.md @@ -683,7 +683,8 @@ Devuelve todas las carreras } } ``` ---- +----------------- + ## Postulaciones ### [POST] api/postulation Crea una postulacíón de trabajo, cuando un estudiante se postula a una oferta @@ -734,7 +735,6 @@ Devuelve las postulaciones de un Estudiante. ] } } - ``` ### [DELETE] api/postulations/?id_postulacion=1 @@ -751,7 +751,7 @@ Elimina una postulación. El usuario se obtiene del token. Se pasa el id de la p } ``` ---- +----------------- ## Administradores ### [GET] api/admins/students Retorna información de estudiantes para el panel de administradores