diff --git a/cmd/serverFunc.go b/cmd/serverFunc.go index 5d6c899..4e43263 100644 --- a/cmd/serverFunc.go +++ b/cmd/serverFunc.go @@ -98,10 +98,24 @@ func server() { r.GET("/", helloWorld) // TODO: Have fun creating new endpoints r.GET("/api/users", getUsers) + r.GET("/api/user/:userid", getUser) r.Run(":" + ListenPort) } +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) + 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) +} + func getUsers(c *gin.Context) { users := []user{} rows, err := db.Query("SELECT * FROM alumnos")