This commit is contained in:
BENEDEK László 2024-10-10 23:45:29 +02:00
parent 9fcc33b0ba
commit e3117f1475
3 changed files with 20 additions and 1 deletions

View File

@ -31,6 +31,7 @@ func Listen(address string, path string) {
{
apiAdmin.POST("task/add", task.Add)
apiAdmin.POST("task/remove/:id", task.Remove)
apiAdmin.GET("task/list/:neptun", task.ListUser)
}
apiUser := api.Group("user").Use(auth.LoggedIn)

View File

@ -100,3 +100,20 @@ func List(c *gin.Context) {
})
}
}
func ListUser(c *gin.Context) {
recipient := c.Param("neptun")
tasks, err := task.List(recipient)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"status": http.StatusInternalServerError,
"error": err.Error(),
})
} else {
c.JSON(http.StatusOK, gin.H{
"status": http.StatusOK,
"tasks": tasks,
})
}
}

View File

@ -22,7 +22,8 @@ func Remove(id int) error {
db := database.GetDB()
_, err := db.NamedExec(
`delete from "task" where "id" = :id`, map[string]interface{}{
`delete from "task" where "id" = :id`,
map[string]interface{}{
"id": id,
})