package devices

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"server/global"
	"server/model/common/response"
	"server/model/devices"
)

type SoundPeriodApi struct{}

func (spa *SoundPeriodApi) CreateSoundPeriod(c *gin.Context) {
	var req devices.SoundPeriodReq
	if err := c.ShouldBindJSON(&req); err != nil {
		global.GVA_LOG.Error("CreateSoundPeriod === ", zap.Error(err))
		response.FailWithMessage("参数错误", c)
		return
	}
	err := soundPeriodService.CreateSoundPeriod(req)
	if err != nil {
		global.GVA_LOG.Error("CreateSoundPeriod === ", zap.Error(err))
		response.FailWithMessage("新增成功", c)
		return
	}
	response.Ok(c)
}

func (spa *SoundPeriodApi) UpdateSoundPeriod(c *gin.Context) {
	var req devices.SoundPeriodReq
	if err := c.ShouldBindJSON(&req); err != nil {
		global.GVA_LOG.Error("UpdateSoundPeriod === ", zap.Error(err))
		response.FailWithMessage("参数错误", c)
		return
	}
	err := soundPeriodService.UpdateSoundPeriod(req)
	if err != nil {
		global.GVA_LOG.Error("UpdateSoundPeriod === ", zap.Error(err))
		response.FailWithMessage("更新成功", c)
		return
	}
	response.Ok(c)
}
