package apis

import (
	"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
	"go-admin/common/utils"
	extConfig "go-admin/config"

	"github.com/gin-gonic/gin"
	"github.com/go-admin-team/go-admin-core/sdk/api"
	_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"

	"go-admin/app/operate/service/dto"
)

type OrgUpload struct {
	api.Api
}

// GetPage <俱乐部>获取俱乐部列表
// @Summary <俱乐部>获取俱乐部列表
// @Description <俱乐部>获取俱乐部列表
// @Tags <俱乐部>俱乐部
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Param data body dto.OrgClubGetPageReq true "data"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Router /api/v1/org/upload [post]
// @Security Bearer
func (e OrgUpload) OrgUpload(c *gin.Context) {
	//上传文件
	f, h, err := c.Request.FormFile("file")

	if err != nil {
		e.OK("", "上传失败")
	}

	defer f.Close()

	fullFileName, err := utils.UploadFile(f, h)

	if err != nil {
		e.OK("", "aliyun上传失败")
	}
	var reply dto.OrgUploadReply
	reply.Url = extConfig.ExtConfig.Aliyunoss.Uploaddir + fullFileName
	response.OK(c, reply, "上传")
}
