package handler import ( "context" "google.golang.org/protobuf/types/known/timestamppb" "hilo/api/service/mgr" "hilo/app/service/mgr/internal/service" ) // MgrHandler is a mgr handler. type MgrHandler struct { mgr.UnimplementedMgrServer svc *service.MgrService } func (h *MgrHandler) IsAgent(ctx context.Context, req *mgr.IsAgentReq) (*mgr.OkRep, error) { ok := h.svc.IsAgent(req.UserId) return &mgr.OkRep{Ok: ok}, nil } func (h *MgrHandler) GetMgrUserStatus(ctx context.Context, req *mgr.GetMgrUserStatusReq) (*mgr.MMgrUserStatus, error) { res, err := h.svc.GetMgrUserStatus(req.UserId) if err != nil { return nil, err } return &mgr.MMgrUserStatus{ Id: res.Id, UserId: res.UserId, Status: mgr.UserStatus(res.Status), EndTime: timestamppb.New(res.EndTime), CreatedTime: timestamppb.New(res.CreatedTime), UpdatedTime: timestamppb.New(res.UpdatedTime), }, nil } func (h *MgrHandler) CheckMgrImeiExist(ctx context.Context, req *mgr.CheckMgrImeiExistReq) (*mgr.OkRep, error) { ok, err := h.svc.CheckMgrImeiExist(req.Imei) if err != nil { return nil, err } return &mgr.OkRep{Ok: ok}, nil } func (h *MgrHandler) CheckMgrIpExist(ctx context.Context, req *mgr.CheckMgrIpExistReq) (*mgr.OkRep, error) { ok, err := h.svc.CheckMgrIpExist(req.Ip) if err != nil { return nil, err } return &mgr.OkRep{Ok: ok}, nil } var _ mgr.MgrServer = &MgrHandler{} // NewMgrHandler new a mgr handler. func NewMgrHandler(uc *service.MgrService) *MgrHandler { return &MgrHandler{svc: uc} }