From 2eb05ad8c28218c6169ba73eba3d81f1eda7e192 Mon Sep 17 00:00:00 2001 From: Christian Carlsson Date: Mon, 23 Dec 2024 01:14:01 +0000 Subject: [PATCH] refact: email: rename methods (#324) --- server/email/email.go | 12 ++++++------ server/email/email_test.go | 2 +- server/email/noop.go | 4 ++-- server/rpc/handlers/v1/auth.go | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/server/email/email.go b/server/email/email.go index 5f17fcd6..1062077b 100644 --- a/server/email/email.go +++ b/server/email/email.go @@ -14,8 +14,8 @@ import ( ) type Email interface { - SendVerificationEmail(ctx context.Context, req SendVerificationEmail) error - SendPasswordResetEmail(ctx context.Context, req SendPasswordResetEmail) error + SendVerification(ctx context.Context, req SendVerification) error + SendPasswordReset(ctx context.Context, req SendPasswordReset) error } type email struct { @@ -51,13 +51,13 @@ func MustNew(c *c.Config) Email { return e } -type SendVerificationEmail struct { +type SendVerification struct { Name string Email string Token string } -func (e *email) SendVerificationEmail(ctx context.Context, req SendVerificationEmail) error { +func (e *email) SendVerification(ctx context.Context, req SendVerification) error { sender := "noreply@getstronger.pro" subject := "[GetStronger] Verify your email" body := fmt.Sprintf(`Hi %s, @@ -89,13 +89,13 @@ Please verify your email address by clicking on the link below. return nil } -type SendPasswordResetEmail struct { +type SendPasswordReset struct { Name string Email string Token string } -func (e *email) SendPasswordResetEmail(ctx context.Context, req SendPasswordResetEmail) error { +func (e *email) SendPasswordReset(ctx context.Context, req SendPasswordReset) error { sender := "noreply@getstronger.pro" subject := "[GetStronger] Reset your password" body := fmt.Sprintf(`Hi %s, diff --git a/server/email/email_test.go b/server/email/email_test.go index 50d16825..ed2bcaf4 100644 --- a/server/email/email_test.go +++ b/server/email/email_test.go @@ -17,7 +17,7 @@ func TestSendEmail(t *testing.T) { t.Parallel() email := MustNew(&config.Config{}) - err := email.SendVerificationEmail(context.Background(), SendVerificationEmail{ + err := email.SendVerification(context.Background(), SendVerification{ Name: "John Doe", Email: os.Getenv("GET_STRONGER_EMAIL_ADDRESS"), Token: "1234", diff --git a/server/email/noop.go b/server/email/noop.go index eeb62816..49c26d8e 100644 --- a/server/email/noop.go +++ b/server/email/noop.go @@ -8,11 +8,11 @@ func NewNoop() Email { return &noop{} } -func (n *noop) SendVerificationEmail(_ context.Context, _ SendVerificationEmail) error { +func (n *noop) SendVerification(_ context.Context, _ SendVerification) error { return nil } -func (n *noop) SendPasswordResetEmail(_ context.Context, _ SendPasswordResetEmail) error { +func (n *noop) SendPasswordReset(_ context.Context, _ SendPasswordReset) error { return nil } diff --git a/server/rpc/handlers/v1/auth.go b/server/rpc/handlers/v1/auth.go index 08556a69..ddfb8a56 100644 --- a/server/rpc/handlers/v1/auth.go +++ b/server/rpc/handlers/v1/auth.go @@ -89,7 +89,7 @@ func (h *authHandler) Signup(ctx context.Context, req *connect.Request[apiv1.Sig return fmt.Errorf("create user: %w", err) } - if err = h.email.SendVerificationEmail(ctx, email.SendVerificationEmail{ + if err = h.email.SendVerification(ctx, email.SendVerification{ Name: user.FirstName, Email: auth.Email, Token: auth.EmailToken, @@ -276,7 +276,7 @@ func (h *authHandler) ResetPassword(ctx context.Context, req *connect.Request[ap return nil, connect.NewError(connect.CodeInternal, nil) } - if err = h.email.SendPasswordResetEmail(ctx, email.SendPasswordResetEmail{ + if err = h.email.SendPasswordReset(ctx, email.SendPasswordReset{ Name: auth.R.User.FirstName, Email: auth.Email, Token: token,