feat(main): main

This commit is contained in:
2026-03-09 08:26:45 -04:00
parent f37382d2b8
commit f14454b4c8
12 changed files with 598 additions and 62 deletions

View File

@@ -1,5 +1,6 @@
from ninja import Router, Schema
from typing import List, Optional
from datetime import date, time
from core.models import ScheduleTemplate, Channel, ScheduleBlock
from django.shortcuts import get_object_or_404
from datetime import date
@@ -27,6 +28,28 @@ class ScheduleTemplateCreateSchema(Schema):
is_active: bool = True
channel_id: int
class ScheduleBlockSchema(Schema):
id: int
schedule_template_id: int
name: str
block_type: str
start_local_time: time
end_local_time: time
day_of_week_mask: int
spills_past_midnight: bool
target_content_rating: Optional[int] = None
default_genre_id: Optional[int] = None
class ScheduleBlockCreateSchema(Schema):
schedule_template_id: int
name: str
block_type: str
start_local_time: time
end_local_time: time
day_of_week_mask: int
spills_past_midnight: bool = False
target_content_rating: Optional[int] = None
@router.get("/template/", response=List[ScheduleTemplateSchema])
def list_schedule_templates(request):
return ScheduleTemplate.objects.all()
@@ -92,3 +115,29 @@ def generate_schedule_today(request, channel_id: int):
generator = ScheduleGenerator(channel=channel)
airings_created = generator.generate_for_date(date.today())
return {"status": "success", "airings_created": airings_created}
@router.get("/template/{template_id}/blocks", response=List[ScheduleBlockSchema])
def list_schedule_blocks(request, template_id: int):
template = get_object_or_404(ScheduleTemplate, id=template_id)
return template.scheduleblock_set.all().order_by('start_local_time')
@router.post("/block/", response={201: ScheduleBlockSchema})
def create_schedule_block(request, payload: ScheduleBlockCreateSchema):
template = get_object_or_404(ScheduleTemplate, id=payload.schedule_template_id)
block = ScheduleBlock.objects.create(
schedule_template=template,
name=payload.name,
block_type=payload.block_type,
start_local_time=payload.start_local_time,
end_local_time=payload.end_local_time,
day_of_week_mask=payload.day_of_week_mask,
spills_past_midnight=payload.spills_past_midnight,
target_content_rating=payload.target_content_rating,
)
return 201, block
@router.delete("/block/{block_id}", response={204: None})
def delete_schedule_block(request, block_id: int):
block = get_object_or_404(ScheduleBlock, id=block_id)
block.delete()
return 204, None