mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
refac: renamed 'post' -> 'article'
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"GoCMS/api"
|
||||
"GoCMS/api/controllers/article"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
func GetArticleDeletePage(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseUint(chi.URLParam(r, "id"), 10, 32)
|
||||
if err != nil {
|
||||
http.Error(w, article.IdUint32ErrorMessage, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
localArticle, err := api.Container.GetArticleUseCase.GetArticle(uint32(id))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(localArticle.Images)
|
||||
for _, image := range localArticle.Images {
|
||||
err = api.Container.DeleteImageUseCase.DeleteImage(image.ID)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = api.Container.DeleteArticleUseCase.DeleteArticle(uint32(id))
|
||||
if err != nil {
|
||||
http.Error(w, http.StatusText(400), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/article", http.StatusSeeOther)
|
||||
}
|
||||
Reference in New Issue
Block a user