package blogs

import (
	"context"
	"log"
	"net/http"

	"fr.latosa-escrima/core"
	"fr.latosa-escrima/core/models"
)

func HandleDelete(w http.ResponseWriter, r *http.Request) {
	uuid := r.PathValue("blog_uuid")
	var blog models.Blog
	res, err := core.DB.NewDelete().
		Model(&blog).
		Where("blog_id = ?", uuid).
		Returning("*").
		Exec(context.Background())
	if err != nil {
		core.JSONError{
			Status:  core.Error,
			Message: err.Error(),
		}.Respond(w, http.StatusInternalServerError)
		return
	}
	log.Println(res)

	core.JSONSuccess{
		Status:  core.Success,
		Message: "Blog deleted.",
	}.Respond(w, http.StatusOK)
}
