feat(main): main
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
from ninja import Router, Schema
|
||||
from typing import List, Optional
|
||||
from core.models import Library, AppUser
|
||||
from core.models import Library, AppUser, MediaCollection
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
router = Router(tags=["library"])
|
||||
collections_router = Router(tags=["collections"])
|
||||
|
||||
class LibrarySchema(Schema):
|
||||
id: int
|
||||
@@ -18,6 +19,12 @@ class LibraryCreateSchema(Schema):
|
||||
visibility: Optional[str] = 'private'
|
||||
owner_user_id: int # In a real app with auth, this would come from request.user
|
||||
|
||||
class MediaCollectionSchema(Schema):
|
||||
id: int
|
||||
name: str
|
||||
library_id: int
|
||||
collection_type: str
|
||||
|
||||
@router.get("/", response=List[LibrarySchema])
|
||||
def list_libraries(request):
|
||||
return Library.objects.all()
|
||||
@@ -36,3 +43,8 @@ def create_library(request, payload: LibraryCreateSchema):
|
||||
visibility=payload.visibility
|
||||
)
|
||||
return 201, library
|
||||
|
||||
@collections_router.get("/", response=List[MediaCollectionSchema])
|
||||
def list_collections(request):
|
||||
"""List all MediaCollections across all libraries."""
|
||||
return MediaCollection.objects.select_related('library').all()
|
||||
|
||||
Reference in New Issue
Block a user