Started to work on media upload and organization

This commit is contained in:
cdricms
2025-01-23 20:10:15 +01:00
parent f9dce4b40b
commit cdd8e34096
21 changed files with 1069 additions and 159 deletions

View File

@@ -0,0 +1,41 @@
package api
import (
"context"
"log"
"net/http"
"os"
"fr.latosa-escrima/api/core"
)
func HandleDeleteMedia(w http.ResponseWriter, r *http.Request) {
uuid := r.PathValue("media_uuid")
var media core.Media
res, err := core.DB.NewDelete().
Model(&media).
Where("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)
err = os.Remove(media.Path)
if err != nil {
core.JSONError{
Status: core.Error,
Message: err.Error(),
}.Respond(w, http.StatusInternalServerError)
return
}
core.JSONSuccess{
Status: core.Success,
Message: "Image successfully deleted.",
}.Respond(w, http.StatusOK)
}