Repository: fossasia/open-event-server

Issue:
Notification API doesn't show attributes and relationships in response
**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 behavior:**
There is only type and id in the response of Notification API.

**Expected behavior:**
All attributes and relationships should be shown.



Discussion:

Resolving patch:
diff --git a/app/api/__init__.py b/app/api/__init__.py
--- a/app/api/__init__.py
+++ b/app/api/__init__.py
@@ -32,7 +32,7 @@
 api.route(UserRelationship, 'user_event_invoices', '/users/<int:id>/relationships/event-invoices')
 
 # notifications
-api.route(NotificationList, 'notification_list', '/notifications', '/users/<int:id>/notifications')
+api.route(NotificationList, 'notification_list','/users/<int:id>/notifications')
 api.route(NotificationDetail, 'notification_detail', '/notifications/<int:id>')
 api.route(NotificationRelationship, 'notification_user',
           '/notifications/<int:id>/relationships/user')
diff --git a/app/api/notifications.py b/app/api/notifications.py
--- a/app/api/notifications.py
+++ b/app/api/notifications.py
@@ -20,20 +20,20 @@ class Meta:
         type_ = 'notification'
         self_view = 'v1.notification_detail'
         self_view_kwargs = {'id': '<id>'}
-        self_view_many = 'v1.notification_list'
         inflect = dasherize
 
     id = fields.Str(dump_only=True)
     title = fields.Str()
     message = fields.Str()
     received_at = fields.DateTime()
+    accept = fields.Str()
     is_read = fields.Boolean()
     user = Relationship(
         attribute='user',
         self_view='v1.notification_user',
         self_view_kwargs={'id': '<id>'},
         related_view='v1.user_detail',
-        related_view_kwargs={'notification_id': '<notification_id>'},
+        related_view_kwargs={'notification_id': '<id>'},
         schema='UserSchema',
         type_='user'
     )
@@ -44,16 +44,17 @@ class NotificationList(ResourceList):
     List all the Notification
     '''
     def query(self, view_kwargs):
-        query_ = self.session.query(User)
-        if view_kwargs.get('user_id') is not None:
-            query_ = query_.join(User).filter(User.id == view_kwargs['user_id'])
+        query_ = self.session.query(Notification)
+        if view_kwargs.get('id') is not None:
+            query_ = query_.join(User).filter(User.id == view_kwargs['id'])
         return query_
 
     def before_create_object(self, data, view_kwargs):
-        if view_kwargs.get('user_id') is not None:
-            user = self.session.query(User).filter_by(id=view_kwargs['user_id']).one()
+        if view_kwargs.get('id') is not None:
+            user = self.session.query(User).filter_by(id=view_kwargs['id']).one()
             data['user_id'] = user.id
 
+    view_kwargs = True
     decorators = (is_user_itself, )
     schema = NotificationSchema
     data_layer = {'session': db.session,
diff --git a/app/models/notification.py b/app/models/notification.py
--- a/app/models/notification.py
+++ b/app/models/notification.py
@@ -32,8 +32,8 @@ class Notification(db.Model):
     received_at = db.Column(db.DateTime(timezone=True))
     is_read = db.Column(db.Boolean)
 
-    def __init__(self, user, title, message, action, received_at, is_read=False):
-        self.user = user
+    def __init__(self, user_id=None, title=None, message=None, action=None, received_at=None, is_read=False):
+        self.user_id = user_id
         self.title = title
         self.message = message
         self.action = action


Test patch:
diff --git a/tests/unittests/object_mother.py b/tests/unittests/object_mother.py
--- a/tests/unittests/object_mother.py
+++ b/tests/unittests/object_mother.py
@@ -85,7 +85,7 @@ def get_message_settings():
     def get_notification():
         user = ObjectMother.get_user()
         return Notification(
-            user=user,
+            user_id=user.id,
             title="test title",
             message="test msg",
             action="Testing",