company_profile_controller.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package controller
  2. import (
  3. "github.com/kataras/iris/v12/mvc"
  4. "xps/pkg/system/datamodel"
  5. "xps/pkg/system/service"
  6. )
  7. type CompanyProfileController struct {
  8. Base
  9. Service service.CompanyProfileService
  10. }
  11. func (c *CompanyProfileController) BeforeActivation(b mvc.BeforeActivation) {
  12. b.Handle("GET", "/", "GetById" )
  13. b.Handle("PUT", "/update", "Update" )
  14. }
  15. func (c *CompanyProfileController) GetById() *JsonResult {
  16. ocId := c.GetCurOcId()
  17. data, err := c.Service.GetById(ocId)
  18. if err != nil {
  19. return ResultErr("数据不存在", nil)
  20. } else {
  21. return ResultOk("获取成功", data)
  22. }
  23. }
  24. func (c *CompanyProfileController) Update() *JsonResult {
  25. ocId := c.GetCurOcId()
  26. cmp := &datamodel.Company{OcId: ocId}
  27. if err := c.Ctx.ReadJSON(cmp); err != nil {
  28. return ResultErr(err.Error(), nil)
  29. }
  30. if err := c.Service.Update(cmp); err != nil {
  31. return ResultErr("更新失败", nil)
  32. }
  33. return ResultOk("更新成功", nil)
  34. }