Moved channel URLs to channels_urls table. Create CRUD endpoints for new table.
All checks were successful
AWS Deploy on Push / build (push) Successful in 1m8s
All checks were successful
AWS Deploy on Push / build (push) Successful in 1m8s
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from .db import Base, ChannelDB
|
||||
from .schemas import ChannelCreate, ChannelUpdate, ChannelResponse
|
||||
from .db import Base, ChannelDB, ChannelURL
|
||||
from .schemas import ChannelCreate, ChannelUpdate, ChannelResponse, ChannelURLCreate, ChannelURLResponse
|
||||
|
||||
__all__ = ["Base", "ChannelDB", "ChannelCreate", "ChannelUpdate", "ChannelResponse"]
|
||||
__all__ = ["Base", "ChannelDB", "ChannelCreate", "ChannelUpdate", "ChannelResponse", "ChannelURL", "ChannelURLCreate", "ChannelURLResponse"]
|
||||
@@ -1,8 +1,9 @@
|
||||
from datetime import datetime, timezone
|
||||
import uuid
|
||||
from sqlalchemy import Column, String, JSON, DateTime, UniqueConstraint
|
||||
from sqlalchemy import Column, String, JSON, DateTime, UniqueConstraint, ForeignKey
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
@@ -20,6 +21,21 @@ class ChannelDB(Base):
|
||||
UniqueConstraint('group_title', 'name', name='uix_group_title_name'),
|
||||
)
|
||||
tvg_logo = Column(String)
|
||||
urls = Column(JSON) # Stores list of URLs as JSON
|
||||
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
||||
updated_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc))
|
||||
updated_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc))
|
||||
|
||||
# Relationship with ChannelURL
|
||||
urls = relationship("ChannelURL", back_populates="channel", cascade="all, delete-orphan")
|
||||
|
||||
class ChannelURL(Base):
|
||||
"""SQLAlchemy model for channel URLs"""
|
||||
__tablename__ = "channels_urls"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
channel_id = Column(UUID(as_uuid=True), ForeignKey('channels.id', ondelete='CASCADE'), nullable=False)
|
||||
url = Column(String, nullable=False)
|
||||
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
||||
updated_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc))
|
||||
|
||||
# Relationship with ChannelDB
|
||||
channel = relationship("ChannelDB", back_populates="urls")
|
||||
@@ -3,22 +3,49 @@ from typing import List
|
||||
from uuid import UUID
|
||||
from pydantic import BaseModel
|
||||
|
||||
class ChannelURLCreate(BaseModel):
|
||||
"""Pydantic model for creating channel URLs"""
|
||||
url: str
|
||||
|
||||
class ChannelURLBase(ChannelURLCreate):
|
||||
"""Base Pydantic model for channel URL responses"""
|
||||
id: UUID
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
class ChannelURLResponse(ChannelURLBase):
|
||||
"""Pydantic model for channel URL responses"""
|
||||
pass
|
||||
|
||||
class ChannelCreate(BaseModel):
|
||||
"""Pydantic model for creating channels"""
|
||||
urls: List[str]
|
||||
urls: List[str] # List of URLs to create with the channel
|
||||
name: str
|
||||
group_title: str
|
||||
tvg_id: str
|
||||
tvg_logo: str
|
||||
tvg_name: str
|
||||
|
||||
class ChannelUpdate(ChannelCreate):
|
||||
class ChannelUpdate(BaseModel):
|
||||
"""Pydantic model for updating channels"""
|
||||
pass
|
||||
name: str | None = None
|
||||
group_title: str | None = None
|
||||
tvg_id: str | None = None
|
||||
tvg_logo: str | None = None
|
||||
tvg_name: str | None = None
|
||||
|
||||
class ChannelResponse(ChannelCreate):
|
||||
class ChannelResponse(BaseModel):
|
||||
"""Pydantic model for channel responses"""
|
||||
id: UUID
|
||||
name: str
|
||||
group_title: str
|
||||
tvg_id: str
|
||||
tvg_logo: str
|
||||
tvg_name: str
|
||||
urls: List[ChannelURLResponse] # List of URL objects without channel_id
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
Reference in New Issue
Block a user