addTask api route
This commit is contained in:
28
main.go
28
main.go
@@ -115,7 +115,6 @@ func completeTask(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
c.IndentedJSON(http.StatusOK, completedTask)
|
||||
|
||||
}
|
||||
|
||||
func getHistory(c *gin.Context) {
|
||||
@@ -139,16 +138,33 @@ func getHistory(c *gin.Context) {
|
||||
c.IndentedJSON(http.StatusOK, jsonHistory)
|
||||
}
|
||||
|
||||
//func addTask(c *gin.Context) {
|
||||
// // add a task to the list of tasks
|
||||
//}
|
||||
func addTask(c *gin.Context) {
|
||||
// get the data of the new task
|
||||
var newTask task
|
||||
if err := c.BindJSON(&newTask); err != nil {
|
||||
c.IndentedJSON(http.StatusBadRequest, newTask)
|
||||
return
|
||||
}
|
||||
// insert new task into the task table
|
||||
stmt, err := db.Prepare("INSERT INTO activities (name, points) VALUES (?,?)")
|
||||
if err != nil {
|
||||
c.IndentedJSON(http.StatusNotModified, newTask)
|
||||
return
|
||||
}
|
||||
_, err = stmt.Exec(newTask.Name, newTask.Points)
|
||||
if err != nil {
|
||||
c.IndentedJSON(http.StatusNotModified, newTask)
|
||||
return
|
||||
}
|
||||
c.IndentedJSON(http.StatusOK, newTask)
|
||||
}
|
||||
|
||||
func main() {
|
||||
router := gin.Default()
|
||||
router.POST("/login", login)
|
||||
router.GET("/getTasks", getTasks)
|
||||
router.POST("/completeTask", completeTask)
|
||||
//router.POST("/addTask", addTask)
|
||||
router.POST("/addTask", addTask)
|
||||
router.GET("/getTasks", getTasks)
|
||||
router.GET("/getHistory", getHistory)
|
||||
|
||||
router.Run("localhost:8080")
|
||||
|
||||
Reference in New Issue
Block a user