Rename the module, proto service, and all identifiers from simple_bank/ SimpleBank to api_tmpl/ApiTmpl, and regenerate the gRPC/gateway/swagger/ mock code accordingly. - Scrub real secrets (SMTP password, auth token secret) from api.env/ api_test.env, untrack them, and add api.env.example/api_test.env.example - Remove committed build artifacts (tmp/main, tmp/build-errors.log, dbml-error.log) and gitignore them going forward - Fix Dockerfile paths (build target, migrations copy) that referenced a stale project layout - Rewrite README to match the actual cmd/ + internal/ structure and add a "using this as a template" section
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package gapi
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/FernandoJVideira/api_tmpl/internal/service"
|
|
"github.com/FernandoJVideira/api_tmpl/internal/val"
|
|
"github.com/FernandoJVideira/api_tmpl/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
|
|
}
|