mgr.go 1.5 KB
Newer Older
kzkzzzz's avatar
kzkzzzz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
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}
}