95 lines
3.2 KiB
Go
95 lines
3.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"hpds-iot-web/internal/proto"
|
|
"hpds-iot-web/internal/service"
|
|
"hpds-iot-web/model"
|
|
e "hpds-iot-web/pkg/err"
|
|
)
|
|
|
|
func (s HandlerService) BrandList(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewSystemService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.BrandRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("BrandList", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
if req.Size < 1 {
|
|
req.Size = 20
|
|
}
|
|
if req.Size > 100 {
|
|
req.Size = 100
|
|
}
|
|
if req.Page < 1 {
|
|
req.Page = 1
|
|
}
|
|
data, err = repo.BrandList(c, req)
|
|
go s.SaveLog("获取品牌列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) BrandInfo(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewSystemService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.BrandItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("BrandInfo", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.BrandInfo(c, req)
|
|
go s.SaveLog("获取品牌信息", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) AddBrand(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewSystemService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.BrandItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("AddBrand", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.AddBrand(c, req)
|
|
go s.SaveLog("新增品牌", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) EditBrand(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewSystemService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.BrandItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("EditBrand", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.EditBrand(c, req)
|
|
go s.SaveLog("修改品牌", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) DeleteBrand(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewSystemService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.BrandItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("DeleteBrand", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.DeleteBrand(c, req)
|
|
go s.SaveLog("删除品牌", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|