38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
package grpc
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
|
pb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/invite"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
func (h *InviteHandler) Generate(ctx context.Context, req *pb.GenerateRequest) (*pb.GenerateResponse, error) {
|
|
invite, err := h.inviteService.Generate(ctx, int(req.UserId), int(req.TtlDays), int(req.MaxUses))
|
|
if err != nil {
|
|
return nil, errors.ToGRPCError(err, h.logger, "InviteService.Generate")
|
|
}
|
|
|
|
return &pb.GenerateResponse{
|
|
Code: strconv.FormatInt(invite.Code, 10),
|
|
MaxUses: int32(invite.CanBeUsedCount),
|
|
ExpiresAt: timestamppb.New(invite.ExpiresAt),
|
|
}, nil
|
|
}
|
|
|
|
func (h *InviteHandler) GetInfo(ctx context.Context, req *pb.GetInfoRequest) (*pb.GetInfoResponse, error) {
|
|
invite, err := h.inviteService.GetInfo(ctx, int(req.UserId))
|
|
if err != nil {
|
|
return nil, errors.ToGRPCError(err, h.logger, "InviteService.GetInfo")
|
|
}
|
|
|
|
return &pb.GetInfoResponse{
|
|
Code: strconv.FormatInt(invite.Code, 10),
|
|
CanBeUsedCount: int32(invite.CanBeUsedCount),
|
|
ExpiresAt: timestamppb.New(invite.ExpiresAt),
|
|
CreatedAt: timestamppb.New(invite.CreatedAt),
|
|
}, nil
|
|
}
|