Repository: fossasia/open-event-server

Issue:
No Location Routes to the api available
Continuation from https://github.com/fossasia/open-event-server/pull/4982
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
Frontend needs a route (an URL) to call the locations in order for them to be loaded. and displayed in the footer.

See frontend: https://github.com/fossasia/open-event-frontend/pull/1304


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
@@ -10,6 +10,7 @@
     TicketRelationshipOptional
 from app.api.events import EventList, EventDetail, EventRelationship, EventCopyResource
 from app.api.event_types import EventTypeList, EventTypeDetail, EventTypeRelationship
+from app.api.event_locations import EventLocationList
 from app.api.event_topics import EventTopicList, EventTopicDetail, EventTopicRelationship
 from app.api.event_sub_topics import EventSubTopicList, EventSubTopicListPost, EventSubTopicDetail,\
     EventSubTopicRelationshipRequired, EventSubTopicRelationshipOptional
@@ -418,6 +419,9 @@
 api.route(AttendeeRelationshipRequired, 'attendee_order', '/attendees/<int:id>/relationships/order')
 api.route(AttendeeRelationshipOptional, 'attendee_user', '/attendees/<int:id>/relationships/user')
 
+# event locations
+api.route(EventLocationList, 'event_location_list', '/event-locations')
+
 # event types
 api.route(EventTypeList, 'event_type_list', '/event-types')
 api.route(EventTypeDetail, 'event_type_detail', '/event-types/<int:id>', '/events/<int:event_id>/event-type',
diff --git a/app/api/event_locations.py b/app/api/event_locations.py
new file mode 100644
--- /dev/null
+++ b/app/api/event_locations.py
@@ -0,0 +1,17 @@
+from flask_rest_jsonapi import ResourceList
+
+from app.api.bootstrap import api
+from app.api.schema.event_locations import EventLocationSchema
+from app.models import db
+from app.models.event_location import EventLocation
+
+
+class EventLocationList(ResourceList):
+
+    """
+    List event locations
+    """
+    decorators = (api.has_permission('is_admin', methods="POST"),)
+    schema = EventLocationSchema
+    data_layer = {'session': db.session,
+                  'model': EventLocation}
diff --git a/app/api/schema/event_locations.py b/app/api/schema/event_locations.py
new file mode 100644
--- /dev/null
+++ b/app/api/schema/event_locations.py
@@ -0,0 +1,28 @@
+from marshmallow_jsonapi import fields
+from marshmallow_jsonapi.flask import Relationship
+
+from app.api.helpers.utilities import dasherize
+from marshmallow_jsonapi.flask import Schema
+
+
+class EventLocationSchema(Schema):
+    """
+    Api Schema for event location model
+    """
+
+    class Meta:
+        """
+        Meta class for event type Api Schema
+        """
+        type_ = 'event-location'
+        inflect = dasherize
+
+    id = fields.Str(dump_only=True)
+    name = fields.Str(required=True)
+    slug = fields.Str(dump_only=True)
+    events = Relationship(attribute='event',
+                          related_view='v1.event_list',
+                          related_view_kwargs={'event_location_id': '<id>'},
+                          many=True,
+                          schema='EventSchemaPublic',
+                          type_='event')


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -3105,6 +3105,16 @@ def file_upload_post(transaction):
     transaction['skip'] = True
 
 
+# ------------------------- Event Locationss -------------------------
+@hooks.before("Event Locations > Event Locations Collection > List All Event Locations")
+def event_location_get_list(transaction):
+    """
+    GET /events-location
+    :param transaction:
+    :return:
+    """
+
+
 # ------------------------- Event Types -------------------------
 @hooks.before("Event Types > Event Types Collection > List All Event Types")
 def event_type_get_list(transaction):