Add DRF API app and real-time draft management UI
- Created new `api` Django app with serializers, viewsets, and routers to expose draft sessions, participants, and movie data. - Registered `api` app in settings and updated root URL configuration. - Extended WebSocket consumers with `inform.draft_status` / `request.draft_status` to allow fetching current draft state. - Updated `DraftSession` and related models to support reverse lookups for draft picks. - Enhanced draft state manager to include `draft_order` in summaries. - Added React WebSocket context provider, connection status component, and new admin/participant panels with phase and participant tracking. - Updated SCSS for participant lists, phase indicators, and status badges. - Modified Django templates to mount new React roots for admin and participant views. - Updated Webpack dev server config to proxy WebSocket connections.
This commit is contained in:
59
api/serializers.py
Normal file
59
api/serializers.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from rest_framework import serializers
|
||||
from django.contrib.auth import get_user_model
|
||||
from boxofficefantasy.models import Movie, Season
|
||||
from draft.models import DraftSession, DraftSessionSettings, DraftPick
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
full_name = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ("username", "first_name", "last_name", "email", "full_name")
|
||||
|
||||
def get_full_name(self, obj):
|
||||
return f"{obj.first_name} {obj.last_name}".strip()
|
||||
|
||||
class MovieSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Movie
|
||||
# fields = ("id", "imdb_id", "title", "year", "poster_url")
|
||||
fields = ("id", "title")
|
||||
|
||||
class DraftSessionSettingsSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = DraftSessionSettings
|
||||
fields = ("starting_budget",) # add any others you have
|
||||
|
||||
|
||||
class DraftPickSerializer(serializers.ModelSerializer):
|
||||
user = UserSerializer(read_only=True)
|
||||
movie = MovieSerializer(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = DraftPick
|
||||
fields = ("id", "movie", "winner", "bid_amount")
|
||||
|
||||
class DraftSessionSerializer(serializers.ModelSerializer):
|
||||
participants = UserSerializer(many=True, read_only=True)
|
||||
movies = MovieSerializer(many=True, read_only=True)
|
||||
settings = DraftSessionSettingsSerializer(read_only=True)
|
||||
draft_picks = DraftPickSerializer(many=True, read_only=True)
|
||||
|
||||
def hashid(self, obj):
|
||||
return f"{obj.hashid}".strip()
|
||||
|
||||
class Meta:
|
||||
model = DraftSession
|
||||
# include whatever else you want (phase, season info, hashed_id, etc.)
|
||||
fields = (
|
||||
"id",
|
||||
"hashid",
|
||||
"season", # will use __str__ unless you customize
|
||||
"participants",
|
||||
"movies",
|
||||
"settings",
|
||||
"draft_picks",
|
||||
# optionally include server time for client clock sync
|
||||
)
|
||||
Reference in New Issue
Block a user