package message

import (
	"spaceofcheng/services/models/model"
)

// GetImgList 获取轮播图列表
func (c *MessageController) GetImgList() {
	org := c.Context.Get("org").(model.SysOrg)
	page, _ := c.GetInt("page")
	pageSize, _ := c.GetInt("pagesize")
	imgs, err := c.dao.GetImgList(org.OrgId, page, pageSize)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(imgs)
}

// GetImgByLocation 根据位置获取轮播图信息
func (c *MessageController) GetImgByLocation() {
	loctionid := c.GetString("locationid")
	orgid := c.GetString("orgid")
	imgs, err := c.dao.GetImgByLocation(loctionid, orgid)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(imgs)
}

// GetImgByID 根据id获取轮播图信息
func (c *MessageController) GetImgByID() {
	imgid := c.GetString(":imgid")
	img, err := c.dao.GetImgByID(imgid)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(img)
}

// SaveImage 保存轮播图信息
func (c *MessageController) SaveImage() {
	img := model.TaCmsImages{}
	if err := c.ParseForm(&img); err != nil {
		c.ResponseError(err)
	}
	newInfo, err := c.dao.SaveImg(img)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(newInfo)
}

// DelImg 删除轮播图信息
func (c *MessageController) DelImg() {
	imgid := c.GetString(":imgid")
	err := c.dao.DelImg(imgid)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON("删除成功！")
}
