Files
eventspace/backend/app/models/event_media.py
Felipe Cardoso 1fd1144bc1
All checks were successful
Build and Push Docker Images / changes (push) Successful in 4s
Build and Push Docker Images / build-backend (push) Successful in 49s
Build and Push Docker Images / build-frontend (push) Has been skipped
Add and extend test coverage for models and their methods
Enhanced test coverage includes `repr` methods, model functionality, and validation logic for key models like `GiftItem`, `GiftCategory`, `EventMedia`, `RSVP`, and `GiftPurchase`. Refactored and added fixtures to support comprehensive testing scenarios. Addresses validation for gift reordering and updates `EventMedia` representation format for consistency.
2025-02-28 15:57:32 +01:00

74 lines
2.2 KiB
Python

from enum import Enum
from sqlalchemy import Column, String, Integer, Boolean, ForeignKey, JSON, Enum as SQLEnum
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship, validates
from .base import Base, TimestampMixin, UUIDMixin
class MediaType(str, Enum):
IMAGE = "image"
VIDEO = "video"
DOCUMENT = "document"
class MediaPurpose(str, Enum):
BANNER = "banner"
GALLERY = "gallery"
ATTACHMENT = "attachment"
class EventMedia(Base, UUIDMixin, TimestampMixin):
__tablename__ = 'event_media'
# Foreign Keys
event_id = Column(UUID(as_uuid=True), ForeignKey('events.id'), nullable=False)
uploaded_by = Column(UUID(as_uuid=True), ForeignKey('users.id'), nullable=False)
# File Information
file_path = Column(String, nullable=False)
original_filename = Column(String, nullable=False)
media_type = Column(SQLEnum(MediaType), nullable=False)
content_type = Column(String, nullable=False)
file_size = Column(Integer, nullable=False)
# Organization
purpose = Column(SQLEnum(MediaPurpose), nullable=False)
is_public = Column(Boolean, default=True, nullable=False)
display_order = Column(Integer, default=0)
title = Column(String)
description = Column(String)
# Additional Metadata
media_metadata = Column(JSON, default=dict)
# Relationships
event = relationship("Event", back_populates="media")
uploader = relationship("User", foreign_keys=[uploaded_by])
def __repr__(self):
return f"<EventMedia {self.original_filename} ({self.media_type.value}) for event={self.event_id}>"
@validates('display_order')
def validate_display_order(self, key, value):
return value if value is not None else 0
@property
def is_image(self):
return self.media_type == MediaType.IMAGE
@property
def is_video(self):
return self.media_type == MediaType.VIDEO
@property
def is_document(self):
return self.media_type == MediaType.DOCUMENT
@property
def url(self):
"""Generate the URL for the media file"""
# This should be implemented based on your storage solution
# Example: return f"/media/{self.file_path}"
pass