Splat handler in their own files, added pagination

This commit is contained in:
Florian Sylvain
2023-01-18 23:33:34 +01:00
parent c681b5389c
commit 3376d88f56
7 changed files with 185 additions and 99 deletions
+25
View File
@@ -0,0 +1,25 @@
package articles
import (
"fmt"
"github.com/Floriansylvain/GohCMS/internal/api"
"github.com/Floriansylvain/GohCMS/internal/database"
"github.com/gin-gonic/gin"
)
func Delete(c *gin.Context) {
id := c.Params.ByName("id")
deleteCount, err := database.DeleteDocument(articlesLocation, map[string]any{"titleID": id})
if err != nil {
api.SendBadRequest(c, fmt.Sprintf(`Could not delete document(s) from DB: %v`, err.Error()))
return
}
if deleteCount != 0 {
api.SendOk(c, fmt.Sprintf("%d article(s) was/were successfully deleted!", deleteCount))
} else {
api.SendOk(c, "No articles were deleted.")
}
}