-
Notifications
You must be signed in to change notification settings - Fork 673
NOISSUE - Send email on invitation #3216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
e508c53 to
0b3086a
Compare
353cdd3 to
11e7556
Compare
internal/proto/users/v1/users.proto
Outdated
| @@ -0,0 +1,27 @@ | |||
| // Copyright (c) Abstract Machines | |||
There was a problem hiding this comment.
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.
internal/proto/users/v1/users.proto
Outdated
|
|
||
| // UsersService is a service that provides user-related functionalities | ||
| // for SuperMQ services. | ||
| service UsersService { |
There was a problem hiding this comment.
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.
internal/proto/users/v1/users.proto
Outdated
| // UsersService is a service that provides user-related functionalities | ||
| // for SuperMQ services. | ||
| service UsersService { | ||
| rpc SendEmailWithUserId(SendEmailWithUserIdReq) returns (SendEmailWithUserIdRes) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SendEmail
internal/proto/users/v1/users.proto
Outdated
| rpc SendEmailWithUserId(SendEmailWithUserIdReq) returns (SendEmailWithUserIdRes) {} | ||
| } | ||
|
|
||
| message SendEmailWithUserIdReq { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EmailReq
internal/proto/users/v1/users.proto
Outdated
| string header = 4; // Email header text | ||
| string user = 5; // User name | ||
| string content = 6; // Email content/URL | ||
| string footer = 7; // Email footer text |
There was a problem hiding this comment.
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
}
}There was a problem hiding this comment.
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.
internal/proto/users/v1/users.proto
Outdated
| } | ||
|
|
||
| message SendEmailRes { | ||
| bool sent = 1; // Whether the email was sent successfully |
There was a problem hiding this comment.
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.
5071a72 to
63ac68b
Compare
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
| res := grpcRes.(sendEmailRes) | ||
| errMsg := "" | ||
| if !res.sent { | ||
| errMsg = "failed to send email" | ||
| } | ||
| return &grpcUsersV1.SendEmailRes{Error: errMsg}, nil |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
d411a75 to
a7c82f7
Compare
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
What type of PR is this?
What does this do?
Which issue(s) does this PR fix/relate to?
Have you included tests for your changes?
Did you document any new/modified feature?
Notes