company_profile_controller.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package controllers
  2. import (
  3. "github.com/kataras/iris/v12/mvc"
  4. "xps/datamodels"
  5. "xps/service/system"
  6. )
  7. type CompanyProfileController struct {
  8. Base
  9. Service system.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 := &datamodels.Company{OcId :ocId}
  27. err := c.Ctx.ReadJSON(cmp)
  28. if err != nil {
  29. return ResultErr(err.Error(), nil)
  30. }
  31. err = c.Service.Update(cmp)
  32. if err != nil {
  33. return ResultErr("更新失败", nil)
  34. }
  35. return ResultOk("更新成功", nil)
  36. }