package file

import (
	"fmt"
	"mini_server/internal/dao"
	"mini_server/internal/server/httpreply"
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
)

type DeleteURI struct {
	FileId string `uri:"file_id" binding:"len=32"`
}

// 文件删除接口

func Delete(c *gin.Context) {
	reply := httpreply.NewDefaultReplyData()
	defer httpreply.Reply(c, reply)

	var param DeleteURI
	if err := c.ShouldBindUri(&param); err != nil {
		reply.Status = http.StatusBadRequest
		reply.Message = fmt.Sprintf("invalid uri path,err:%v", err)
		return
	}

	if err := dao.File_Delete(param.FileId); err != nil {
		logrus.Errorf("删除文件失败，文件id:%s,err:%v", param.FileId, err)
		reply.Status = http.StatusInternalServerError
		reply.Message = "数据库删除失败"
		return
	}
}
