Repository: fossasia/open-event-server

Issue:
Implement image-size api with proper permissions and relationships



Discussion:
@magdalenesuo 
Should I proceed with this ?
@LuD1161 I've already started working on this. maybe checkout some other issues? Or you can open issues and work on it, most of the API implementation issues haven't been opened yet.

Resolving patch:
diff --git a/app/api/__init__.py b/app/api/__init__.py
--- a/app/api/__init__.py
+++ b/app/api/__init__.py
@@ -11,6 +11,7 @@
 from app.api.sponsors import SponsorList, SponsorDetail, SponsorRelationship
 from app.api.tracks import TrackList, TrackDetail, TrackRelationship
 from app.api.call_for_papers import CallForPaperList, CallForPaperDetail, CallForPaperRelationship
+from app.api.image_sizes import ImageSizeList, ImageSizeDetail
 
 
 api_v1 = Blueprint('v1', __name__, url_prefix='/v1')
@@ -26,6 +27,10 @@
 api.route(NotificationDetail, 'notification_detail', '/notifications/<int:id>')
 api.route(NotificationRelationship, 'notification_user', '/notifications/<int:id>/relationships/user')
 
+# image_sizes
+api.route(ImageSizeList, 'image_size_list', '/image_sizes')
+api.route(ImageSizeDetail, 'image_size_detail', '/image_sizes/<int:id>')
+
 # tickets
 api.route(AllTicketList, 'all_ticket_list', '/tickets', '/events/<int:id>/tickets')
 api.route(TicketDetail, 'ticket_detail', '/tickets/<int:id>', '/events/<int:event_id>/tickets')
diff --git a/app/api/image_sizes.py b/app/api/image_sizes.py
new file mode 100644
--- /dev/null
+++ b/app/api/image_sizes.py
@@ -0,0 +1,60 @@
+from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship
+from marshmallow_jsonapi.flask import Schema, Relationship
+from marshmallow_jsonapi import fields
+from app.models import db
+from app.api.helpers.permissions import jwt_required, is_admin, is_user_itself
+from sqlalchemy.orm.exc import NoResultFound
+from flask_rest_jsonapi.exceptions import ObjectNotFound
+from app.models.event import Event
+from app.models.image_size import ImageSizes
+
+
+class ImageSizeSchema(Schema):
+    """
+    Api schema for image_size Model
+    """
+    class Meta:
+        """
+        Meta class for image_size Api Schema
+        """
+        type_ = 'image_size'
+        self_view = 'v1.image_size_detail'
+        self_view_kwargs = {'id': '<id>'}
+
+    id = fields.Str(dump_only=True)
+    type = fields.Str()
+    full_width = fields.Integer()
+    full_height = fields.Integer()
+    full_aspect = fields.Str()
+    full_quality = fields.Integer()
+    icon_width = fields.Integer()
+    icon_height = fields.Integer()
+    icon_aspect = fields.Str()
+    icon_quality = fields.Integer()
+    thumbnail_width = fields.Integer()
+    thumbnail_height = fields.Integer()
+    thumbnail_aspect = fields.Str()
+    thumbnail_quality = fields.Integer()
+    logo_width = fields.Integer()
+    logo_height = fields.Integer()
+
+
+class ImageSizeList(ResourceList):
+    """
+    List and create image_sizes
+    """
+    post = is_admin(ResourceList.post.__func__)
+    schema = ImageSizeSchema
+    data_layer = {'session': db.session,
+                  'model': ImageSizes}
+
+
+class ImageSizeDetail(ResourceDetail):
+    """
+    image_size detail by id
+    """
+    patch = is_admin(ResourceDetail.patch.__func__)
+    delete = is_admin(ResourceDetail.delete.__func__)
+    schema = ImageSizeSchema
+    data_layer = {'session': db.session,
+                  'model': ImageSizes}


Test patch: