Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

feat(notifications_service): adds endpoint to list registered devices of a user #339

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from

Conversation

RohanSreerama5
Copy link

@RohanSreerama5 RohanSreerama5 commented Sep 15, 2020

Adds 2 new endpoints:

  1. to list user's registered devices
  2. to list user's subscriptions

Note: This is part of my application to be on the Backend HackIllinois team. Hope you like it! : )

arbor.Route{
"GetAllSubscriptions",
"GET",
"/notifications/subscriptions",
Copy link
Contributor

Choose a reason for hiding this comment

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

add a "/" to the end

arbor.Route{
"GetAllRegisteredDevices",
"GET",
"/notifications/devices",
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

alice.New(middleware.IdentificationMiddleware, middleware.AuthMiddleware([]models.Role{models.UserRole})).ThenFunc(GetAllSubscriptions).ServeHTTP,
},
arbor.Route{
"GetAllRegisteredDevices",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think something more like "GetUserRegisteredDevices" might be better, since you're getting the registered devices of a specific user, not all users.

)

const NotificationsFormat string = "JSON"

var NotificationsRoutes = arbor.RouteCollection{
arbor.Route{
"GetAllSubscriptions",
Copy link
Contributor

Choose a reason for hiding this comment

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

same thing as my comment below about the naming -- "GetUserSubscriptions"

topics, err := service.GetSubscriptions(id)

if err != nil {
errors.WriteError(w, r, errors.DatabaseError(err.Error(), "Could not retrieve notifications."))
Copy link
Contributor

Choose a reason for hiding this comment

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

Error message should be changed from "notifications" to "subscriptions"

devices, err := service.GetUserDevices(id)

if err != nil {
errors.WriteError(w, r, errors.DatabaseError(err.Error(), "Could not retrieve notifications."))
Copy link
Contributor

Choose a reason for hiding this comment

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

change this too

Copy link
Author

Choose a reason for hiding this comment

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

Hi Heesoo,

After revisiting, I think you're right. My interpretation of the PR was a bit different. Based on the work done so far, I'd like to merge these into master and hopefully open a new PR to address #247 more properly soon. Additionally, I think this can count as my "coding challenge" for the API team right? Please get back to me when you get a chance : )

@heesooy
Copy link
Contributor

heesooy commented Sep 18, 2020

Hey @RohanSreerama5!

Other than some small things, the new endpoints look good! But your PR doesn't close #247 -- I think you might have misinterpreted the issue.

We have a stats service that aggregates and returns information from other services. For instance, GET /stats/registration/ will return something like
"school": { "University of Illinois Urbana-Champaign": 5, "Northwestern University": 3 }, "major": { "Computer Science": 4, "Computer Engineering": 4 }

We want to add endpoints to the notifications service so that the stats service can interface with it and return info about how many devices there are, how many topics there are, ... in the entire service, not just limited to one user.

Take a look at
https://docs.hackillinois.org/reference/services/Statistics/
and
https://github.com/HackIllinois/api/blob/staging/services/registration/controller/controller.go#L34

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants