Repository: fossasia/open-event-server

Issue:
Notifications API is sending same responses for different users.


**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server

**Current**:
Making a GET request to
```
http://open-event-api.herokuapp.com/v1/users/{user_id}/notifications
```
is sending same notifications for me for different user id. I am getting correct notifications for the user I created notifications for but even if I create a new user, I am getting the same notifications for it also.

Expected:
A user should have only notifications created for him/her.


Discussion:
please share proper request and response as a pastebin link
@sumedh123 Please share the responses
@shubham-padia Sharing. give me a moment.
@shubham-padia So I checked for a couple of users. I created some sample notifications for a user and tried to get them in postman, I got them correctly. Whereas, I created a new user and tried to get the notifications, then I got the notifications of my previous user. Here is the response of both the GET requests for different users:
```
{
    "data": [
        {
            "type": "notification",
            "relationships": {
                "user": {
                    "links": {
                        "related": "/v1/notifications/7/user",
                        "self": "/v1/notifications/7/relationships/user"
                    }
                }
            },
            "links": {
                "self": "/v1/notifications/7"
            },
            "id": "7",
            "attributes": {
                "is-read": true,
                "title": "fifth one",
                "message": "example",
                "received-at": "2017-07-29T10:35:17.837335+00:00"
            }
        },
        {
            "type": "notification",
            "relationships": {
                "user": {
                    "links": {
                        "related": "/v1/notifications/6/user",
                        "self": "/v1/notifications/6/relationships/user"
                    }
                }
            },
            "links": {
                "self": "/v1/notifications/6"
            },
            "id": "6",
            "attributes": {
                "is-read": true,
                "title": "fourth one",
                "message": "example",
                "received-at": "2017-07-29T04:20:54.490061+00:00"
            }
        },
        {
            "type": "notification",
            "relationships": {
                "user": {
                    "links": {
                        "related": "/v1/notifications/9/user",
                        "self": "/v1/notifications/9/relationships/user"
                    }
                }
            },
            "links": {
                "self": "/v1/notifications/9"
            },
            "id": "9",
            "attributes": {
                "is-read": true,
                "title": "sixth one",
                "message": "example",
                "received-at": "2017-07-30T16:22:46.816095+00:00"
            }
        },
        {
            "type": "notification",
            "relationships": {
                "user": {
                    "links": {
                        "related": "/v1/notifications/1/user",
                        "self": "/v1/notifications/1/relationships/user"
                    }
                }
            },
            "links": {
                "self": "/v1/notifications/1"
            },
            "id": "1",
            "attributes": {
                "is-read": true,
                "title": "example",
                "message": "example",
                "received-at": "2017-07-27T08:48:20.436744+00:00"
            }
        },
        {
            "type": "notification",
            "relationships": {
                "user": {
                    "links": {
                        "related": "/v1/notifications/4/user",
                        "self": "/v1/notifications/4/relationships/user"
                    }
                }
            },
            "links": {
                "self": "/v1/notifications/4"
            },
            "id": "4",
            "attributes": {
                "is-read": true,
                "title": "third one",
                "message": "example",
                "received-at": "2017-07-27T08:49:35.370359+00:00"
            }
        },
        {
            "type": "notification",
            "relationships": {
                "user": {
                    "links": {
                        "related": "/v1/notifications/8/user",
                        "self": "/v1/notifications/8/relationships/user"
                    }
                }
            },
            "links": {
                "self": "/v1/notifications/8"
            },
            "id": "8",
            "attributes": {
                "is-read": true,
                "title": "fifth one",
                "message": "example",
                "received-at": "2017-07-29T10:46:04.088523+00:00"
            }
        },
        {
            "type": "notification",
            "relationships": {
                "user": {
                    "links": {
                        "related": "/v1/notifications/2/user",
                        "self": "/v1/notifications/2/relationships/user"
                    }
                }
            },
            "links": {
                "self": "/v1/notifications/2"
            },
            "id": "2",
            "attributes": {
                "is-read": false,
                "title": "example",
                "message": "example",
                "received-at": "2017-07-27T08:48:51.702135+00:00"
            }
        },
        {
            "type": "notification",
            "relationships": {
                "user": {
                    "links": {
                        "related": "/v1/notifications/5/user",
                        "self": "/v1/notifications/5/relationships/user"
                    }
                }
            },
            "links": {
                "self": "/v1/notifications/5"
            },
            "id": "5",
            "attributes": {
                "is-read": false,
                "title": "fourth one",
                "message": "example",
                "received-at": "2017-07-27T08:49:48.110550+00:00"
            }
        },
        {
            "type": "notification",
            "relationships": {
                "user": {
                    "links": {
                        "related": "/v1/notifications/3/user",
                        "self": "/v1/notifications/3/relationships/user"
                    }
                }
            },
            "links": {
                "self": "/v1/notifications/3"
            },
            "id": "3",
            "attributes": {
                "is-read": false,
                "title": "second notificatoin",
                "message": "example",
                "received-at": "2017-07-27T08:49:27.081447+00:00"
            }
        }
    ],
    "jsonapi": {
        "version": "1.0"
    },
    "meta": {
        "count": 9
    },
    "links": {
        "self": "/v1/users/173/notifications"
    }
}
```

Resolving patch:
diff --git a/app/api/notifications.py b/app/api/notifications.py
--- a/app/api/notifications.py
+++ b/app/api/notifications.py
@@ -63,8 +63,8 @@ def query(self, view_kwargs):
         :return:
         """
         query_ = self.session.query(Notification)
-        if view_kwargs.get('id'):
-            user = safe_query(self, User, 'id', view_kwargs['id'], 'id')
+        if view_kwargs.get('user_id'):
+            user = safe_query(self, User, 'id', view_kwargs['user_id'], 'user_id')
             query_ = query_.join(User).filter(User.id == user.id)
         return query_
 


Test patch: