diff --git a/api/endpotins.go b/api/endpotins.go index ceff60c..ea304a3 100644 --- a/api/endpotins.go +++ b/api/endpotins.go @@ -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) diff --git a/api/task/task.go b/api/task/task.go index 5b87091..c98e5cf 100644 --- a/api/task/task.go +++ b/api/task/task.go @@ -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, + }) + } +} diff --git a/database/task/task.go b/database/task/task.go index 7b1f354..8155c13 100644 --- a/database/task/task.go +++ b/database/task/task.go @@ -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, })