vikunja-api/routes/api/v1/list_delete.go

71 lines
1.8 KiB
Go
Raw Normal View History

2018-06-12 18:17:21 +02:00
package v1
import (
2018-07-10 14:02:23 +02:00
// "git.kolaente.de/konrad/list/models"
2018-06-12 18:17:21 +02:00
"github.com/labstack/echo"
2018-07-10 14:02:23 +02:00
// "net/http"
// "strconv"
2018-06-12 18:17:21 +02:00
"net/http"
)
2018-07-10 14:02:23 +02:00
// DeleteListByID ...
2018-06-12 18:17:21 +02:00
func DeleteListByID(c echo.Context) error {
2018-06-13 13:45:22 +02:00
// swagger:operation DELETE /lists/{listID} lists deleteList
// ---
// summary: Deletes a list with all items on it
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: listID
// in: path
// description: ID of the list to delete
// type: string
// required: true
// responses:
// "200":
// "$ref": "#/responses/Message"
// "400":
// "$ref": "#/responses/Message"
// "403":
// "$ref": "#/responses/Message"
// "404":
// "$ref": "#/responses/Message"
// "500":
// "$ref": "#/responses/Message"
2018-07-10 13:27:25 +02:00
/*
2018-07-11 00:28:53 +02:00
// Check if we have our ID
id := c.Param("id")
// Make int
itemID, err := strconv.ParseInt(id, 10, 64)
if err != nil {
return c.JSON(http.StatusBadRequest, models.Message{"Invalid ID."})
2018-07-10 14:02:23 +02:00
}
2018-07-11 00:28:53 +02:00
// Check if the user has the right to delete that list
user, err := models.GetCurrentUser(c)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
2018-07-10 14:02:23 +02:00
}
2018-07-11 00:28:53 +02:00
// err = models.DeleteListByID(itemID, &user)
if err != nil {
if models.IsErrNeedToBeListAdmin(err) {
return c.JSON(http.StatusForbidden, models.Message{"You need to be the list owner to delete a list."})
}
if models.IsErrListDoesNotExist(err) {
return c.JSON(http.StatusNotFound, models.Message{"This list does not exist."})
}
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
2018-07-11 00:28:53 +02:00
return c.JSON(http.StatusOK, models.Message{"The list was deleted with success."})
2018-07-10 13:27:25 +02:00
*/
return echo.NewHTTPError(http.StatusNotImplemented)
2018-06-13 13:45:22 +02:00
}