Skip to content

Conversation

@WashingtonKK
Copy link
Contributor

What type of PR is this?

What does this do?

Which issue(s) does this PR fix/relate to?

  • Related Issue #
  • Resolves #

Have you included tests for your changes?

Did you document any new/modified feature?

Notes

@WashingtonKK WashingtonKK requested a review from a team as a code owner October 31, 2025 12:51
@WashingtonKK WashingtonKK self-assigned this Oct 31, 2025
@WashingtonKK WashingtonKK linked an issue Oct 31, 2025 that may be closed by this pull request
@WashingtonKK WashingtonKK marked this pull request as draft October 31, 2025 12:53
@@ -0,0 +1,27 @@
// Copyright (c) Abstract Machines
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename to file emails.proto.


// UsersService is a service that provides user-related functionalities
// for SuperMQ services.
service UsersService {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, let's use EmailService.

// UsersService is a service that provides user-related functionalities
// for SuperMQ services.
service UsersService {
rpc SendEmailWithUserId(SendEmailWithUserIdReq) returns (SendEmailWithUserIdRes) {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SendEmail

rpc SendEmailWithUserId(SendEmailWithUserIdReq) returns (SendEmailWithUserIdRes) {}
}

message SendEmailWithUserIdReq {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EmailReq

string header = 4; // Email header text
string user = 5; // User name
string content = 6; // Email content/URL
string footer = 7; // Email footer text
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it something like:

enum ContactType {
  ID = 0;
  Email = 1;
}

message EmailReq {
  string from = 1;              // Sender
  ContactType fromType = 2; // indicate sender id or email
  repeated string to = 3;       // recipients
  ContactType toType = 4; //  indicate recipient id or email
  string subject = 5;           // Email subject
  string content = 6;           // Email content/URL  
  optional string template = 10; // the whole template to be parsed by emailer
  optional string template_file = 11; // template file name to be parsed by emailer
  map<string, string> options = 12; // map that can be used in template
}

We will see what to put instead of this map as we progress with the server implementation. This can be used in emailer something like:

if req.Template != "" {
	t, err := template.New("body").Parse(req.Template)
	if err != nil {
		return err
	}
	buff := new(bytes.Buffer)
	if err := t.Execute(buff, req.Options); err != nil {
		return err
	}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, we can be able to send body already prepared (template parsed), but also we should be able to send something like template_file name, so that emailer takes care of it.

}

message SendEmailRes {
bool sent = 1; // Whether the email was sent successfully
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use error here. So we have very go-ish interface where we inspect if response has an error.

@codecov
Copy link

codecov bot commented Nov 3, 2025

Codecov Report

❌ Patch coverage is 18.85714% with 142 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.09%. Comparing base (cac6c64) to head (d112064).

Files with missing lines Patch % Lines
users/api/grpc/client.go 0.00% 50 Missing ⚠️
users/api/grpc/server.go 0.00% 41 Missing ⚠️
users/api/grpc/endpoint.go 0.00% 27 Missing ⚠️
pkg/grpcclient/client.go 0.00% 11 Missing ⚠️
users/emailer/emailer.go 0.00% 9 Missing ⚠️
domains/service.go 80.00% 1 Missing and 1 partial ⚠️
users/events/streams.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3216      +/-   ##
==========================================
+ Coverage   35.54%   45.09%   +9.54%     
==========================================
  Files         307      135     -172     
  Lines       39233    22355   -16878     
==========================================
- Hits        13947    10080    -3867     
+ Misses      24439    11636   -12803     
+ Partials      847      639     -208     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@WashingtonKK WashingtonKK marked this pull request as ready for review November 3, 2025 14:24
SammyOina
SammyOina previously approved these changes Nov 4, 2025
Comment on lines 62 to 67
res := grpcRes.(sendEmailRes)
errMsg := ""
if !res.sent {
errMsg = "failed to send email"
}
return &grpcUsersV1.SendEmailRes{Error: errMsg}, nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than this, please use the actual error from the service.

users/service.go Outdated
return *updated != old
}

func (svc service) SendEmailWithUserId(ctx context.Context, userIds []string, from, subject, header, user, content, footer string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to sendEmail and encapsulate logic (fetch ID vs send directly via address), as well as params using DTO similarly how we do it in gPRC API.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, add tests for this method.

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

Fix tests

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

update protoc version

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

fix tests

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

lint proto

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

lint proto

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send an email notification when user receives a notification

3 participants