tasks can be marked as finished

This commit is contained in:
Florian Hoss 2022-04-07 16:05:43 +02:00
parent 5e63fc1e38
commit 3bf957ee30
3 changed files with 44 additions and 7 deletions

View file

@ -55,10 +55,26 @@ func (wp *Webpage) defineRoutes() {
c.JSON(200, gin.H{"task": task})
}
})
tasks.DELETE(":id", func(c *gin.Context) {
tasks.DELETE("", func(c *gin.Context) {
if wp.isLoggedInMiddleware(c) {
id := c.Param("id")
wp.Database.DeleteTask(id)
id := c.Query("id")
ok := wp.Database.DeleteTask(id)
if !ok {
c.JSON(500, gin.H{"message": "cannot delete task"})
return
}
c.JSON(200, gin.H{"message": "success"})
}
})
tasks.PUT("", func(c *gin.Context) {
if wp.isLoggedInMiddleware(c) {
id := c.Query("id")
done := c.Query("done")
ok := wp.Database.UpdateTask(id, done)
if !ok {
c.JSON(500, gin.H{"message": "cannot update task"})
return
}
c.JSON(200, gin.H{"message": "success"})
}
})