Repository: fossasia/open-event-server

Issue:
Orders: Add related endpoints to docs and dredd tests 
Parent issue: #4009.
**Current behavior:**
<!-- Describe how the bug manifests. -->

**Expected behavior:**
<!-- Describe what the behavior would be without the bug. -->

**Steps to reproduce:**
<!-- If you are able to illustrate the bug or feature request with an example, please provide steps to reproduce -->

**Related code:**

```
insert any relevant code here else remove this section
```

**Other information:**
<!-- List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to fix, Stack Overflow links, forum links, etc. -->

**System information:** 

<!-- Add information about the system your facing this bug on. If you think this is irrelevant or if it's a UI bug or a feature request, please remove this section -->

```
Your operating system
```

```
output of `python --version`
```



Discussion:

Resolving patch:
diff --git a/app/api/events.py b/app/api/events.py
--- a/app/api/events.py
+++ b/app/api/events.py
@@ -283,6 +283,13 @@ def get_id(view_kwargs):
         else:
             view_kwargs['id'] = None
 
+    if view_kwargs.get('order_identifier') is not None:
+        order = safe_query(db, Order, 'identifier', view_kwargs['order_identifier'], 'order_identifier')
+        if order.event_id is not None:
+            view_kwargs['id'] = order.event_id
+        else:
+            view_kwargs['id'] = None
+
     return view_kwargs
 
 
@@ -294,16 +301,6 @@ def before_get(self, args, kwargs):
         else:
             self.schema = EventSchemaPublic
 
-    def before_get_object(self, view_kwargs):
-        get_id(view_kwargs)
-
-        if view_kwargs.get('order_identifier') is not None:
-            order = safe_query(self, Order, 'identifier', view_kwargs['order_identifier'], 'order_identifier')
-            if order.event_id is not None:
-                view_kwargs['id'] = order.event_id
-            else:
-                view_kwargs['id'] = None
-
     def before_update_object(self, event, data, view_kwargs):
         if data.get('original_image_url') and data['original_image_url'] != event.original_image_url:
             uploaded_images = create_save_image_sizes(data['original_image_url'], 'event', event.id)
@@ -318,7 +315,6 @@ def before_update_object(self, event, data, view_kwargs):
     data_layer = {'session': db.session,
                   'model': Event,
                   'methods': {
-                      'before_get_object': before_get_object,
                       'before_update_object': before_update_object
                   }}
 
diff --git a/app/api/tickets.py b/app/api/tickets.py
--- a/app/api/tickets.py
+++ b/app/api/tickets.py
@@ -50,7 +50,7 @@ def query(self, view_kwargs):
             query_ = Ticket.query.filter(Ticket.access_codes.any(id=access_code.id))
 
         if view_kwargs.get('order_identifier'):
-            order = safe_query(self, Order, 'identifer', view_kwargs['order_identifier'], 'order_identifer')
+            order = safe_query(self, Order, 'identifier', view_kwargs['order_identifier'], 'order_identifier')
             ticket_ids = []
             for ticket in order.tickets:
                 ticket_ids.append(ticket.id)
diff --git a/app/factories/order.py b/app/factories/order.py
new file mode 100644
--- /dev/null
+++ b/app/factories/order.py
@@ -0,0 +1,15 @@
+import factory
+
+from app.models.order import Order
+from app.models.ticket import db
+from app.factories.event import EventFactoryBasic
+
+
+class OrderFactory(factory.alchemy.SQLAlchemyModelFactory):
+    class Meta:
+        model = Order
+        sqlalchemy_session = db.session
+
+    event = factory.RelatedFactory(EventFactoryBasic)
+    event_id = 1
+    payment_mode = 'free'


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -50,6 +50,7 @@
 from app.factories.activities import ActivityFactory
 from app.factories.stripe_authorization import StripeAuthorizationFactory
 from app.factories.mail import MailFactory
+from app.factories.order import OrderFactory
 
 
 stash = {}
@@ -3316,3 +3317,45 @@ def create_event_copy(transaction):
         event = EventFactoryBasic()
         db.session.add(event)
         db.session.commit()
+
+
+@hooks.before("Events > Get Event for a Order > Event Details for a Order")
+def get_event_from_order(transaction):
+    """
+    GET /v1/orders/{identifier}/event
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        order = OrderFactory()
+        order.identifier = "7201904e"
+        db.session.add(order)
+        db.session.commit()
+
+
+@hooks.before("Tickets > List Tickets for an Order > List Tickets")
+def get_tickets_from_order(transaction):
+    """
+    GET /v1/orders/{identifier}/tickets
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        order = OrderFactory()
+        order.identifier = "7201904e"
+        db.session.add(order)
+        db.session.commit()
+
+
+@hooks.before("Attendees > List Attendees under an order > List All Attendees under an order")
+def get_attendees_from_order(transaction):
+    """
+    GET /v1/orders/{identifier}/attendees
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        order = OrderFactory()
+        order.identifier = "7201904e"
+        db.session.add(order)
+        db.session.commit()