Added method to delete a list
This commit is contained in:
parent
853fb2a2b7
commit
dcb046665f
4 changed files with 49 additions and 0 deletions
|
@ -40,6 +40,8 @@ Ab v0.3 können wir mit clients anfangen.
|
||||||
* [ ] Bearbeiten (abhaken)
|
* [ ] Bearbeiten (abhaken)
|
||||||
* [x] Löschen
|
* [x] Löschen
|
||||||
|
|
||||||
|
* [ ] Swaggerdocs !!!!
|
||||||
|
|
||||||
#### v0.2
|
#### v0.2
|
||||||
|
|
||||||
* [ ] Listen teilbar
|
* [ ] Listen teilbar
|
||||||
|
|
21
models/list_delete.go
Normal file
21
models/list_delete.go
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
func DeleteListByID(listID int64) (err error) {
|
||||||
|
|
||||||
|
// Check if the list exists
|
||||||
|
_, err = GetListByID(listID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the list
|
||||||
|
_, err = x.ID(listID).Delete(&List{})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete all todoitems on that list
|
||||||
|
_, err = x.Where("list_id = ?", listID).Delete(&ListItem{})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
25
routes/api/v1/list_delete.go
Normal file
25
routes/api/v1/list_delete.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/labstack/echo"
|
||||||
|
"strconv"
|
||||||
|
"net/http"
|
||||||
|
"git.kolaente.de/konrad/list/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func DeleteListByID(c echo.Context) error {
|
||||||
|
// 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."})
|
||||||
|
}
|
||||||
|
|
||||||
|
err = models.DeleteListByID(itemID)
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, models.Message{"The list was deleted with success."})
|
||||||
|
}
|
|
@ -58,6 +58,7 @@ func RegisterRoutes(e *echo.Echo) {
|
||||||
a.GET("/lists/:id", apiv1.GetListByID)
|
a.GET("/lists/:id", apiv1.GetListByID)
|
||||||
a.POST("/lists/:id", apiv1.AddOrUpdateList)
|
a.POST("/lists/:id", apiv1.AddOrUpdateList)
|
||||||
a.PUT("/lists/:id", apiv1.AddOrUpdateListItem)
|
a.PUT("/lists/:id", apiv1.AddOrUpdateListItem)
|
||||||
|
a.DELETE("/lists/:id", apiv1.DeleteListByID)
|
||||||
|
|
||||||
a.DELETE("/item/:id", apiv1.DeleteListItemByIDtemByID)
|
a.DELETE("/item/:id", apiv1.DeleteListItemByIDtemByID)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue