|
@@ -0,0 +1,94 @@
|
|
|
+package storehouse
|
|
|
+
|
|
|
+import (
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
+ "server/dao"
|
|
|
+ "server/global"
|
|
|
+ "server/model/common/request"
|
|
|
+ "server/model/common/response"
|
|
|
+)
|
|
|
+
|
|
|
+type CommodityApi struct{}
|
|
|
+
|
|
|
+func (ca *CommodityApi) QueryAllCommodity(c *gin.Context) {
|
|
|
+ commodities, err := commodityService.QueryAllCommodity()
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("查询失败", c)
|
|
|
+ global.GVA_LOG.Error("QueryAllCommodity ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ response.OkWithData(commodities, c)
|
|
|
+}
|
|
|
+
|
|
|
+func (ca *CommodityApi) QueryCommodityList(c *gin.Context) {
|
|
|
+ var info request.PageInfo
|
|
|
+ err := c.ShouldBindJSON(&info)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("参数解析失败", c)
|
|
|
+ global.GVA_LOG.Error("QueryCommodityList ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ list, total, err := commodityService.QueryCommodityList(info)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("查询失败", c)
|
|
|
+ global.GVA_LOG.Error("QueryCommodityList ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ response.OkWithDetailed(response.PageResult{
|
|
|
+ List: list,
|
|
|
+ Total: total,
|
|
|
+ Page: info.Page,
|
|
|
+ PageSize: info.PageSize,
|
|
|
+ }, "获取成功", c)
|
|
|
+}
|
|
|
+
|
|
|
+func (ca *CommodityApi) CreateCommodity(c *gin.Context) {
|
|
|
+ var commodity dao.Commodity
|
|
|
+ err := c.ShouldBindJSON(&commodity)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("参数解析失败", c)
|
|
|
+ global.GVA_LOG.Error("CreateCommodity ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = commodityService.CreateCommodity(commodity)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("创建失败", c)
|
|
|
+ global.GVA_LOG.Error("CreateCommodity ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ response.OkWithMessage("创建成功", c)
|
|
|
+}
|
|
|
+
|
|
|
+func (ca *CommodityApi) UpdateCommodity(c *gin.Context) {
|
|
|
+ var commodity dao.Commodity
|
|
|
+ err := c.ShouldBindJSON(&commodity)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("参数解析失败", c)
|
|
|
+ global.GVA_LOG.Error("UpdateCommodity ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = commodityService.UpdateCommodity(commodity)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("更新失败", c)
|
|
|
+ global.GVA_LOG.Error("UpdateCommodity ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ response.OkWithMessage("更新成功", c)
|
|
|
+}
|
|
|
+
|
|
|
+func (ca *CommodityApi) DeleteCommodity(c *gin.Context) {
|
|
|
+ var commodity dao.Commodity
|
|
|
+ err := c.ShouldBindJSON(&commodity)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("参数解析失败", c)
|
|
|
+ global.GVA_LOG.Error("DeleteCommodity ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = commodityService.DeleteCommodity(commodity)
|
|
|
+ if err != nil {
|
|
|
+ response.FailWithMessage("删除失败", c)
|
|
|
+ global.GVA_LOG.Error("DeleteCommodity ====== " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ response.OkWithMessage("删除成功", c)
|
|
|
+}
|