get_agent_by_id_logic.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package agent
  2. import (
  3. "context"
  4. "wechat-api/ent/agent"
  5. "wechat-api/internal/svc"
  6. "wechat-api/internal/types"
  7. "wechat-api/internal/utils/dberrorhandler"
  8. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  9. "github.com/suyuan32/simple-admin-common/utils/pointy"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type GetAgentByIdLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewGetAgentByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAgentByIdLogic {
  18. return &GetAgentByIdLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. func (l *GetAgentByIdLogic) GetAgentById(req *types.IDReq) (*types.AgentInfoResp, error) {
  25. organizationId := l.ctx.Value("organizationId").(uint64)
  26. data, err := l.svcCtx.DB.Agent.Query().Where(agent.ID(req.Id), agent.OrganizationID(organizationId)).First(l.ctx)
  27. if err != nil {
  28. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  29. }
  30. return &types.AgentInfoResp{
  31. BaseDataInfo: types.BaseDataInfo{
  32. Code: 0,
  33. Msg: errormsg.Success,
  34. },
  35. Data: types.AgentInfo{
  36. BaseIDInfo: types.BaseIDInfo{
  37. Id: &data.ID,
  38. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  39. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  40. },
  41. Name: &data.Name,
  42. Role: &data.Role,
  43. Status: &data.Status,
  44. Background: &data.Background,
  45. Examples: &data.Examples,
  46. },
  47. }, nil
  48. }