mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
26 lines
620 B
Go
26 lines
620 B
Go
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.")
|
|
}
|
|
}
|