remove task

This commit is contained in:
BENEDEK László 2024-10-10 23:15:49 +02:00
parent 95f6de950f
commit ec0075993e
3 changed files with 38 additions and 0 deletions

View File

@ -30,6 +30,7 @@ func Listen(address string, path string) {
apiAdmin := api.Group("admin").Use(auth.LoggedIn).Use(auth.IsAdmin)
{
apiAdmin.POST("task/add", task.Add)
apiAdmin.POST("task/remove/:id", task.Remove)
}
apiTest := api.Group("test").Use(auth.LoggedIn).Use(auth.IsAdmin)

View File

@ -2,6 +2,7 @@ package task
import (
"net/http"
"strconv"
"git.tek.govt.hu/dowerx/szoe-pontok/database/task"
"git.tek.govt.hu/dowerx/szoe-pontok/model"
@ -49,3 +50,29 @@ func Add(c *gin.Context) {
})
}
}
func Remove(c *gin.Context) {
id := c.Param("id")
idInt, err := strconv.Atoi(id)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"status": http.StatusBadRequest,
"error": err.Error(),
})
return
}
if err := task.Remove(idInt); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"status": http.StatusBadRequest,
"error": err.Error(),
})
} else {
c.JSON(http.StatusOK, gin.H{
"status": http.StatusOK,
"message": "removed",
})
}
}

View File

@ -17,3 +17,13 @@ func Add(task model.Task) error {
return err
}
func Remove(id int) error {
db := database.GetDB()
_, err := db.NamedExec(
`delete from "task" where "id" = :id`, map[string]interface{}{
"id": id,
})
return err
}