作者 陈志颖

feat:修改路由

package controllers
import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/columnSetting/command"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/columnSetting/query"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/columnSetting/service"
)
type ColumnSettingController struct {
beego.Controller
}
func (controller *ColumnSettingController) CreateColumnSetting() {
columnSettingService := service.NewColumnSettingService(nil)
createColumnSettingCommand := &command.CreateColumnSettingCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createColumnSettingCommand)
data, err := columnSettingService.CreateColumnSetting(createColumnSettingCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ColumnSettingController) UpdateColumnSetting() {
columnSettingService := service.NewColumnSettingService(nil)
updateColumnSettingCommand := &command.UpdateColumnSettingCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateColumnSettingCommand)
columnSettingId, _ := controller.GetInt64(":columnSettingId")
updateColumnSettingCommand.ColumnSettingId = columnSettingId
data, err := columnSettingService.UpdateColumnSetting(updateColumnSettingCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ColumnSettingController) GetColumnSetting() {
columnSettingService := service.NewColumnSettingService(nil)
getColumnSettingQuery := &query.GetColumnSettingQuery{}
columnSettingId, _ := controller.GetInt64(":columnSettingId")
getColumnSettingQuery.ColumnSettingId = columnSettingId
data, err := columnSettingService.GetColumnSetting(getColumnSettingQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ColumnSettingController) RemoveColumnSetting() {
columnSettingService := service.NewColumnSettingService(nil)
removeColumnSettingCommand := &command.RemoveColumnSettingCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), removeColumnSettingCommand)
columnSettingId, _ := controller.GetInt64(":columnSettingId")
removeColumnSettingCommand.ColumnSettingId = columnSettingId
data, err := columnSettingService.RemoveColumnSetting(removeColumnSettingCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ColumnSettingController) ResetColumn() {
columnSettingService := service.NewColumnSettingService(nil)
resetColumnCommand := &command.ResetColumnCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), resetColumnCommand)
data, err := columnSettingService.ResetColumn(resetColumnCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ColumnSettingController) ListColumnSetting() {
columnSettingService := service.NewColumnSettingService(nil)
listColumnSettingQuery := &query.ListColumnSettingQuery{}
offset, _ := controller.GetInt("offset")
listColumnSettingQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listColumnSettingQuery.Limit = limit
data, err := columnSettingService.ListColumnSetting(listColumnSettingQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
... ...
package routers
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/beego/controllers"
)
func init() {
beego.Router("/column-settings/", &controllers.ColumnSettingController{}, "Post:CreateColumnSetting")
beego.Router("/column-settings/:columnSettingId", &controllers.ColumnSettingController{}, "Put:UpdateColumnSetting")
beego.Router("/column-settings/:columnSettingId", &controllers.ColumnSettingController{}, "Get:GetColumnSetting")
beego.Router("/column-settings/:columnSettingId", &controllers.ColumnSettingController{}, "Delete:RemoveColumnSetting")
beego.Router("/column-settings/", &controllers.ColumnSettingController{}, "Post:ResetColumn")
beego.Router("/column-settings/", &controllers.ColumnSettingController{}, "Get:ListColumnSetting")
}
... ...
... ... @@ -41,8 +41,11 @@ func init() {
beego.NSRouter("/actual/del", &controllers.OrderInfoController{}, "POST:RemoveOrderReal"), // 删除实际订单
beego.NSRouter("/actual/update", &controllers.OrderInfoController{}, "POST:UpdateOrderReal"), // 新增实际订单
beego.NSRouter("/actual/close", &controllers.OrderInfoController{}, "POST:OrderDisable"),
beego.NSRouter("/fileImportTemplate", &controllers.OrderInfoController{}, "POST:DownloadTemplate"), // 下载导入模板
beego.NSRouter("/fileImport", &controllers.OrderInfoController{}, "POST:ImportOrderFromExcel"), // 导入订单数据
beego.NSRouter("/fileImportTemplate", &controllers.OrderInfoController{}, "POST:DownloadTemplate"), // 下载导入模板
beego.NSRouter("/fileImport", &controllers.OrderInfoController{}, "POST:ImportOrderFromExcel"), // 导入订单数据
beego.NSRouter("/actual/listColumn", &controllers.ColumnSettingController{}, "POST:ListColumnSetting"), // 返回栏目设置列表
beego.NSRouter("/actual/updateColumn", &controllers.ColumnSettingController{}, "POST:UpdateColumnSetting"), // 更新栏目设置
beego.NSRouter("/actual/resetColumn", &controllers.ColumnSettingController{}, "Post:ResetColumn"), // 重置栏目设置
),
beego.NSNamespace("/common",
beego.NSRouter("/partner", &controllers.CommonController{}, "POST:GetPartnerList"),
... ...
package column_setting
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/astaxie/beego"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/beego"
)
func TestColumnSetting(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port ColumnSetting Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = beego.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
... ...
package column_setting
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
)
var _ = Describe("创建栏目设置增删改查", func() {
Describe("提交数据创建栏目设置增删改查", func() {
Context("提交正确的新栏目设置数据", func() {
It("返回栏目设置数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"description": "string",
"userName": "string",
}
httpExpect.POST("/column-settings/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("id").ValueNotEqual("id", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM column_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package column_setting
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
)
var _ = Describe("返回栏目设置增删改查", func() {
var column_settingId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&column_settingId),
"INSERT INTO column_settings (column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testColumnSettingId", "testCompanyId", "testCreatedAt", "testDescription", "testKey", "testUid", "testUpdatedAt", "testUserName", "testValue")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据column_settingId参数返回栏目设置", func() {
Context("传入有效的column_settingId", func() {
It("返回栏目设置数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/column-settings/{columnSettingId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM column_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package column_setting
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
)
var _ = Describe("返回栏目设置增删改查列表", func() {
var column_settingId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&column_settingId),
"INSERT INTO column_settings (column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testColumnSettingId", "testCompanyId", "testCreatedAt", "testDescription", "testKey", "testUid", "testUpdatedAt", "testUserName", "testValue")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回栏目设置列表", func() {
Context("传入有效的参数", func() {
It("返回栏目设置数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/column-settings/").
WithQuery("offset", "int").
WithQuery("limit", "int").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("column_settings").Value("column_settings").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM column_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package column_setting
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
)
var _ = Describe("移除栏目设置增删改查", func() {
var column_settingId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&column_settingId),
"INSERT INTO column_settings (column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testColumnSettingId", "testCompanyId", "testCreatedAt", "testDescription", "testKey", "testUid", "testUpdatedAt", "testUserName", "testValue")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除栏目设置增删改查", func() {
Context("传入有效的column_settingId", func() {
It("返回被移除栏目设置的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/column-settings/{columnSettingId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM column_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package column_setting
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
)
var _ = Describe("重置栏目设置", func() {
var column_settingId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&column_settingId),
"INSERT INTO column_settings (column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testColumnSettingId", "testCompanyId", "testCreatedAt", "testDescription", "testKey", "testUid", "testUpdatedAt", "testUserName", "testValue")
Expect(err).NotTo(HaveOccurred())
})
Describe("重置栏目设置", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{}
httpExpect.POST("/column-settings/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM column_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package column_setting
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
)
var _ = Describe("更新栏目设置增删改查", func() {
var column_settingId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&column_settingId),
"INSERT INTO column_settings (column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testColumnSettingId", "testCompanyId", "testCreatedAt", "testDescription", "testKey", "testUid", "testUpdatedAt", "testUserName", "testValue")
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新栏目设置增删改查", func() {
Context("提交正确的栏目设置数据", func() {
It("返回更新后的栏目设置数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{}
httpExpect.PUT("/column-settings/{columnSettingId}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("id").ValueEqual("id", column_settingId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM column_settings WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...