Archived
- Backend: Django 5 + DRF with accounts, documents, collections, and reading apps - Custom User model with email-based auth, JWT via SimpleJWT - Full CRUD viewsets with ModelSerializer + DRF routers - pytest, Ruff, drf-spectacular (OpenAPI), whitenoise - Dockerfile for production deployment - Frontend: React 18 + TypeScript + Vite - Lazy-loaded routes with ProtectedRoute/PublicRoute guards - Auth context with useReducer, token refresh interceptor - Pages: Login, Register, Library, Document Detail, Reader, Collections, Settings - Dark theme, responsive grid layout, Vite proxy to Django backend - Mobile: Expo SDK 51 + React Native + Expo Router - File-based routing with login, register, and library screens - AsyncStorage for token persistence, token refresh interceptor - Shared API types via @cloud-reader/shared workspace package - Shared: TypeScript types (API responses, auth, documents, etc.) - CI/CD: 3 independent GitHub Actions pipelines (backend, frontend, mobile)
33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
from rest_framework import serializers
|
|
|
|
from .models import Collection
|
|
|
|
|
|
class CollectionSerializer(serializers.ModelSerializer[Collection]):
|
|
cover_url = serializers.SerializerMethodField()
|
|
document_count = serializers.IntegerField(read_only=True)
|
|
|
|
class Meta:
|
|
model = Collection
|
|
fields = [
|
|
"id", "name", "description", "cover_url", "document_count",
|
|
"is_public", "created_at", "updated_at",
|
|
]
|
|
read_only_fields = ["id", "document_count", "created_at", "updated_at"]
|
|
|
|
def get_cover_url(self, obj: Collection) -> str | None:
|
|
return obj.cover_url
|
|
|
|
|
|
class CollectionDetailSerializer(CollectionSerializer):
|
|
documents = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
|
|
|
|
class Meta(CollectionSerializer.Meta):
|
|
fields = CollectionSerializer.Meta.fields + ["documents", "owner"]
|
|
|
|
|
|
class CollectionDocumentActionSerializer(serializers.Serializer):
|
|
document_ids = serializers.ListField(
|
|
child=serializers.IntegerField(),
|
|
allow_empty=False,
|
|
) |