All checks were successful
Deploy Smart Search Backend Test / deploy (push) Successful in 1m36s
45 lines
1.4 KiB
Go
45 lines
1.4 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) {
|
|
code, err := strconv.ParseInt(req.Code, 10, 64)
|
|
if err != nil {
|
|
return nil, errors.ToGRPCError(err, h.logger, "InviteService.GetInfo")
|
|
}
|
|
|
|
invite, err := h.inviteService.GetInfo(ctx, code)
|
|
if err != nil {
|
|
return nil, errors.ToGRPCError(err, h.logger, "InviteService.GetInfo")
|
|
}
|
|
|
|
return &pb.GetInfoResponse{
|
|
Code: strconv.FormatInt(invite.Code, 10),
|
|
UserId: int64(invite.UserID),
|
|
CanBeUsedCount: int32(invite.CanBeUsedCount),
|
|
ExpiresAt: timestamppb.New(invite.ExpiresAt),
|
|
IsActive: invite.IsActive,
|
|
CreatedAt: timestamppb.New(invite.CreatedAt),
|
|
}, nil
|
|
}
|