From b0ebbfa6e32b5a82697afcd26375e5fec6cf0c71 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simon=20K=C3=BCnzel?= <simonk@fsmpi.rwth-aachen.de>
Date: Sun, 13 Oct 2024 19:52:16 +0200
Subject: [PATCH] Add image target medium

---
 src/videoag_common/objects/medium.py | 39 +++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 7 deletions(-)

diff --git a/src/videoag_common/objects/medium.py b/src/videoag_common/objects/medium.py
index 8a5e722..fdcb44b 100644
--- a/src/videoag_common/objects/medium.py
+++ b/src/videoag_common/objects/medium.py
@@ -156,6 +156,7 @@ class TargetMediumType(Enum):
     PLAIN_VIDEO = "plain_video"
     PLAIN_AUDIO = "plain_audio"
     THUMBNAIL = "thumbnail"
+    IMAGE = "image"
 
 
 _TARGET_MEDIUM_TYPE_ENUM = create_enum_type(TargetMediumType)
@@ -194,12 +195,12 @@ class TargetMedium(DeletableApiObject, Base):
             name="check_audio_channel_count_not_null"
         ),
         CheckConstraint(
-            f"type NOT IN ('plain_video') OR NOT is_produced OR video_vertical_resolution IS NOT NULL",
-            name="check_video_vertical_resolution_not_null"
+            f"type NOT IN ('plain_video', 'thumbnail') OR NOT is_produced OR vertical_resolution IS NOT NULL",
+            name="check_vertical_resolution_not_null"
         ),
         CheckConstraint(
-            f"type NOT IN ('plain_video') OR NOT is_produced OR video_horizontal_resolution IS NOT NULL",
-            name="check_video_horizontal_resolution_not_null"
+            f"type NOT IN ('plain_video', 'thumbnail') OR NOT is_produced OR horizontal_resolution IS NOT NULL",
+            name="check_horizontal_resolution_not_null"
         ),
         CheckConstraint(
             f"type NOT IN ('plain_video') OR NOT is_produced OR video_frame_rate_numerator IS NOT NULL",
@@ -371,13 +372,13 @@ class SingleAudioContainingMedium(ApiObject):
 
 class SingleVideoContainingMedium(ApiObject):
     
-    video_vertical_resolution: Mapped[int] = api_mapped(
+    vertical_resolution: Mapped[int] = api_mapped(
         mapped_column(nullable=True, use_existing_column=True),
         ApiIntegerField(
             include_in_data=True
         )
     )
-    video_horizontal_resolution: Mapped[int] = api_mapped(
+    horizontal_resolution: Mapped[int] = api_mapped(
         mapped_column(nullable=True, use_existing_column=True),
         ApiIntegerField(
             include_in_data=True
@@ -397,6 +398,22 @@ class SingleVideoContainingMedium(ApiObject):
     )
 
 
+class SingleImageContainingMedium(ApiObject):
+    
+    vertical_resolution: Mapped[int] = api_mapped(
+        mapped_column(nullable=True, use_existing_column=True),
+        ApiIntegerField(
+            include_in_data=True
+        )
+    )
+    horizontal_resolution: Mapped[int] = api_mapped(
+        mapped_column(nullable=True, use_existing_column=True),
+        ApiIntegerField(
+            include_in_data=True
+        )
+    )
+
+
 class PlainVideoTargetMedium(TargetMedium, FileMedium, SingleVideoContainingMedium, SingleAudioContainingMedium):
     __tablename__ = None  # Prevent our own base from adding a table name. This should be a single-table inheritance
     __mapper_args__ = {
@@ -425,13 +442,21 @@ class PlainAudioTargetMedium(TargetMedium, FileMedium, SingleAudioContainingMedi
     )
 
 
-class ThumbnailTargetMedium(TargetMedium, FileMedium):
+# Thumbnail is a different type so that the Frontend knows what to display as the thumbnail
+class ThumbnailTargetMedium(TargetMedium, FileMedium, SingleImageContainingMedium):
     __tablename__ = None  # Prevent our own base from adding a table name. This should be a single-table inheritance
     __mapper_args__ = {
         "polymorphic_identity": TargetMediumType.THUMBNAIL
     }
 
 
+class ImageTargetMedium(TargetMedium, FileMedium, SingleImageContainingMedium):
+    __tablename__ = None  # Prevent our own base from adding a table name. This should be a single-table inheritance
+    __mapper_args__ = {
+        "polymorphic_identity": TargetMediumType.IMAGE
+    }
+
+
 class PublishMedium(VisibilityApiObject, DeletableApiObject, Base):
     __api_data__ = ApiObjectClass(
         parent_relationship_config_ids=["lecture"]
-- 
GitLab