Repository: fossasia/open-event-server

Issue:
Implement TicketFees API with permissions
API for model `TicketFees`.

Endpoints : 
**To get all the ticket-fees** : `/v1/ticket-fees`
**To get a ticket-fees by id** : `/v1/ticket-fees/<int:id>`

Parent [issue#3640](https://github.com/fossasia/open-event-orga-server/issues/3640)


Discussion:
@LuD1161 please add a description. Add a list of proposed endpoints etc. This is not the way to propose something. And also, the issue template is there just for this reason. Why would you ignore it ?
@LuD1161 please add _all_ the endpoints (including direct and relationships). Also, work on this _after_ #3771 and #3820
@niranjan94
Sure.

Resolving patch:
diff --git a/app/api/__init__.py b/app/api/__init__.py
--- a/app/api/__init__.py
+++ b/app/api/__init__.py
@@ -1,4 +1,5 @@
 from app.api.bootstrap import api
+from app.api.ticket_fees import TicketFeeList, TicketFeeDetail
 from app.api.users import UserList, UserDetail, UserRelationship
 from app.api.notifications import NotificationList, NotificationDetail, NotificationRelationship
 from app.api.tickets import AllTicketList, TicketDetail, TicketRelationship
@@ -224,3 +225,6 @@
 api.route(EventSubTopicRelationship, 'event_sub_topic_event', '/event-sub-topics/<int:id>/relationships/events')
 api.route(EventSubTopicRelationship, 'event_sub_topic_event_topic',
           '/event-sub-topics/<int:id>/relationships/event-topic')
+# ticket_fees
+api.route(TicketFeeList, 'ticket_fee_list', '/ticket-fees')
+api.route(TicketFeeDetail, 'ticket_fee_detail', '/ticket-fees/<int:id>')
diff --git a/app/api/helpers/static.py b/app/api/helpers/static.py
--- a/app/api/helpers/static.py
+++ b/app/api/helpers/static.py
@@ -395,3 +395,31 @@
     'Travel & Outdoor': 'TravelOutdoor.jpg',
     'Travel': 'Travel.jpg',
 }
+
+PAYMENT_CURRENCY_CHOICES = [
+    'AUD',
+    'BRL',
+    'CAD',
+    'CHF',
+    'CZK',
+    'DKK',
+    'EUR',
+    'GBP',
+    'HKD',
+    'HUF',
+    'ILS',
+    'INR',
+    'JPY',
+    'MXN',
+    'MYR',
+    'NOK',
+    'NZD',
+    'PHP',
+    'PLN',
+    'RUB',
+    'SEK',
+    'SGD',
+    'THB',
+    'TWD',
+    'USD'
+]
diff --git a/app/api/ticket_fees.py b/app/api/ticket_fees.py
new file mode 100644
--- /dev/null
+++ b/app/api/ticket_fees.py
@@ -0,0 +1,49 @@
+from app.api.bootstrap import api
+from flask_rest_jsonapi import ResourceDetail, ResourceList
+from marshmallow import validate
+from marshmallow_jsonapi.flask import Schema
+from marshmallow_jsonapi import fields
+
+from app import db
+from app.api.helpers.static import PAYMENT_CURRENCY_CHOICES
+from app.api.helpers.utilities import dasherize
+from app.models.ticket_fee import TicketFees
+
+
+class TicketFeesSchema(Schema):
+    """
+    Api schema for ticket_fee Model
+    """
+    class Meta:
+        """
+        Meta class for image_size Api Schema
+        """
+        type_ = 'ticket-fees'
+        self_view = 'v1.ticket_fee_detail'
+        self_view_kwargs = {'id': '<id>'}
+        inflect = dasherize
+
+    id = fields.Integer(dump_only=True)
+    currency = fields.Str(validate=validate.OneOf(choices=PAYMENT_CURRENCY_CHOICES))
+    service_fee = fields.Float(validate=lambda n: n >= 0)
+    maximum_fee = fields.Float(validate=lambda n: n >= 0)
+
+
+class TicketFeeList(ResourceList):
+    """
+    List and create TicketFees
+    """
+    decorators = (api.has_permission('is_admin'),)
+    schema = TicketFeesSchema
+    data_layer = {'session': db.session,
+                  'model': TicketFees}
+
+
+class TicketFeeDetail(ResourceDetail):
+    """
+    ticket_fee detail by id
+    """
+    decorators = (api.has_permission('is_admin'),)
+    schema = TicketFeesSchema
+    data_layer = {'session': db.session,
+                  'model': TicketFees}


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -1361,3 +1361,55 @@ def event_sub_topic_delete(transaction):
         event_sub_topic = EventSubTopicFactory()
         db.session.add(event_sub_topic)
         db.session.commit()
+
+# ------------------------- Ticket Fees -------------------------
+
+
+@hooks.before("Ticket Fees > Ticket Fees Collection > List Ticket Fees")
+def ticket_fees_get_list(transaction):
+    """
+    GET /ticket-fees
+    :param transaction:
+    :return:
+    """
+    transaction['skip'] = True
+
+
+@hooks.before("Ticket Fees > Ticket Fees Collection > Create Ticket Fee")
+def ticket_fees_post(transaction):
+    """
+    POST /ticket-fees
+    :param transaction:
+    :return:
+    """
+    transaction['skip'] = True
+
+
+@hooks.before("Ticket Fees > Ticket Fee Details > Get Ticket Fees Details")
+def ticket_fees_get_detail(transaction):
+    """
+    GET /ticket-fees/1
+    :param transaction:
+    :return:
+    """
+    transaction['skip'] = True
+
+
+@hooks.before("Ticket Fees > Ticket Fee Details > Update Ticket Fees")
+def ticket_fees_patch(transaction):
+    """
+    PATCH /ticket-fees/1
+    :param transaction:
+    :return:
+    """
+    transaction['skip'] = True
+
+
+@hooks.before("Ticket Fees > Ticket Fee Details > Delete Ticket Fees")
+def ticket_fees_delete(transaction):
+    """
+    DELETE /ticket-fees/1
+    :param transaction:
+    :return:
+    """
+    transaction['skip'] = True