Skip to content
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

Fixed RFC email notifications, adjusting to the feedback received #79

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

dazanez
Copy link

@dazanez dazanez commented Mar 3, 2022

This is a fixed version of the RFC for email notifications, following recommendations received.

@dazanez
Copy link
Author

dazanez commented Mar 3, 2022

This RFC already has a discussion opened by my partner @efrenruizrubio here.

@dazanez
Copy link
Author

dazanez commented Mar 5, 2022

While we were fixing the RFC, I thought that sending email notifications could be a REST API active 27/7 listening for requests to send emails, since doing it through the notification system module requires the developers of the other modules to execute a method to send the email. In this sense, we have to make a request to a REST API or execute a method of the notification module (in both cases passing the required data), each time we want to send email notifications to users.

The problem with the REST API is that (from what I understood) it would not be compatible with what we call an SDK.


```json
{
"user": "oneMoreUser",

Choose a reason for hiding this comment

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

Is this information required? The endpoint should return info about a specific user notifications, usually the returned data have a format like:

{
  status: 200,
  message: 'The request was successful,
  data: []
  pagination: {}
}


**Requests need the user's token to return its corresponding notifications. For the example, imagine that the token belongs to the user 'oneMoreUser'.**

- `[GET] /notifications/` - Get all notifications

Choose a reason for hiding this comment

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

As we dont need to get all notifications info this looks good, but im thinking if using user/:id/notifications could be a more semantic approach?

How are you planning to send used info?

Copy link
Author

Choose a reason for hiding this comment

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

I thought getting the user by its token or something related to the authentication, I noticed that MercadoLibre and Facebook, for example, do not send user information in the endpoint, so I guess they get it from authentication.

Choose a reason for hiding this comment

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

I have use that method in a project and It's very useful and comfortable 👌🏼


## Get only one notification by its ID

- **Endpoint:** `[GET] /notfications/:notification`

Choose a reason for hiding this comment

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

Where this endpoint will be used in the UI?

Copy link
Author

Choose a reason for hiding this comment

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

This and the "get all notifications" endpoints would be more used to make queries from an admin user, or for other teams that need to consult the information about notifications. This way they don't access our database directly, but by our endpoints.

Choose a reason for hiding this comment

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

That makes sense to me 🧐


## Mark a notification as read

- **Endpoint:** `[POST] /notifications/:notification/mark_read`

Choose a reason for hiding this comment

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

POST is usually used to indicate a resource creation not a modification, to edit something there a two ways:

PUT: This is used when the payload that you send contains all the fields of the resource
PATCH: This is used when you want to modify a particular property of a resource

For this case I recommend to use the second one since you are only going to send something like:

{
  read: true
}

This endpoint could help us to mark it as read or viceversa.

Choose a reason for hiding this comment

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

  1. What if we send the notification id as part of the payload? This will eliminate the id from the url
  2. I encourage you to use hyphens instead of underscore, mark_read -> mark-read

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the clarification, I'll make the corrections


## Set all notifications as read

- **Endpoint:** `[POST] /notifications/all_read`

Choose a reason for hiding this comment

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

  1. Same comment with the format of all_read -> all-read

@Basultobd Basultobd self-requested a review May 3, 2022 15:53
Copy link

@Basultobd Basultobd left a comment

Choose a reason for hiding this comment

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

Some changes :)

Comment on lines 73 to 75
{
"token": "theuserauthtoken"
}

Choose a reason for hiding this comment

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

Usually the token will be place in the authorization header, check this https://www.loginradius.com/blog/engineering/everything-you-want-to-know-about-authorization-headers/

"read": true,
"action": {}
},
"token:": "theusertauthtoken"

Choose a reason for hiding this comment

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

same comment related with the authorization header


```json
{
"token:": "theusertauthtoken"

Choose a reason for hiding this comment

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

same comment related with the authorization token

"read": true,
...
"token:": "theusertauthtoken",
"id": "123abcd"

Choose a reason for hiding this comment

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

To be honest, I didn't consider this approach in the past, where you pass the id in the body, looks very clean!

...
"read": true,
...
"token:": "theusertauthtoken",

Choose a reason for hiding this comment

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

same comment related with the authorization token

Comment on lines 252 to 272
"data": [
{
"id": "123abcd",
...
"read": true,
...
},
{
"id": "124abce",
...
"read": true,
...
}
{
"id": "125abcf",
...
"read": true,
...
}
...
]

Choose a reason for hiding this comment

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

The update operation usually doesn't return anything, the status code its usually 204 (check this).

I suggest a response body like:

{
  status: 204,
  message: 'Operation successful',
  body: {}
}

@dazanez dazanez requested a review from Basultobd May 9, 2022 23:47
Copy link

@Basultobd Basultobd left a comment

Choose a reason for hiding this comment

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

Nice, we can work with this, good job @dazanez !

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.

3 participants