package cases

import "spaceofcheng/services/models/model"

// GetCaseTable 获取案场桌位列表
func (c *CaseController) GetCaseTable() {
	caseids := c.GetString("caseid")
	if caseids == "" {
		cases := c.Context.Get("cases").([]model.SysUserCase)
		caseids = c.GetCaseIDs(cases)
	}
	page, _ := c.GetInt("page")
	pageSize, _ := c.GetInt("pagesize")
	tables, err := c.dao.GetCaseTable(caseids, page, pageSize)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(tables)
}

// GetCaseTableByID 根据ID获取案场桌位
func (c *CaseController) GetCaseTableByID() {
	tableid := c.GetString(":tableid")
	table, err := c.dao.GetCaseTableByID(tableid)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(table)
}

// SaveCaseTable 保存案场桌位
func (c *CaseController) SaveCaseTable() {
	table := model.SysCaseTable{}
	if err := c.ParseForm(&table); err != nil {
		c.ResponseError(err)
	}
	newinfo, err := c.dao.SaveCaseTable(table)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(newinfo)
}

// DelCaseTable 删除案场桌位
func (c *CaseController) DelCaseTable() {
	tableid := c.GetString(":tableid")
	err := c.dao.DelCaseTable(tableid)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON("删除成功！")
}
