feat: 0.0.1
This commit is contained in:
146 files changed
+10444
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package gapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/FernandoJVideira/simple_bank/internal/service"
|
||||
"github.com/FernandoJVideira/simple_bank/internal/val"
|
||||
"github.com/FernandoJVideira/simple_bank/pb"
|
||||
"google.golang.org/genproto/googleapis/rpc/errdetails"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func (s *Server) VerifyEmail(ctx context.Context, req *pb.VerifyEmailRequest) (*pb.VerifyEmailResponse, error) {
|
||||
violations := validateVerifyEmailRequest(req)
|
||||
if violations != nil {
|
||||
return nil, invalidArgumentError(violations)
|
||||
}
|
||||
|
||||
result, err := s.userService.VerifyEmail(ctx, service.EmailVerificationRequest{
|
||||
EmailID: req.GetId(),
|
||||
SecretCode: req.GetCode(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, "failed to verify email")
|
||||
}
|
||||
|
||||
resp := &pb.VerifyEmailResponse{
|
||||
IsVerified: result.User.IsEmailVerified,
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func validateVerifyEmailRequest(req *pb.VerifyEmailRequest) (violations []*errdetails.BadRequest_FieldViolation) {
|
||||
if err := val.ValidateEmailID(req.GetId()); err != nil {
|
||||
violations = append(violations, fieldViolation("id", err))
|
||||
}
|
||||
|
||||
if err := val.ValidateVerificationCode(req.GetCode()); err != nil {
|
||||
violations = append(violations, fieldViolation("secret_code", err))
|
||||
}
|
||||
|
||||
return violations
|
||||
}
|
||||
Reference in new issue
Block a user