mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: courses refactor
This commit is contained in:
parent
0572368a32
commit
34e0413ee7
11 changed files with 17 additions and 18 deletions
48
src/routers/courses/collections.py
Normal file
48
src/routers/courses/collections.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
from fastapi import APIRouter, Depends
|
||||
from src.services.auth import get_current_user
|
||||
from src.services.users import PublicUser, User
|
||||
from src.services.courses.collections import Collection, create_collection, get_collection, get_collections, update_collection, delete_collection
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("/")
|
||||
async def api_create_collection(collection_object: Collection, current_user: PublicUser = Depends(get_current_user)):
|
||||
"""
|
||||
Create new Collection
|
||||
"""
|
||||
return await create_collection(collection_object, current_user)
|
||||
|
||||
|
||||
@router.get("/{collection_id}")
|
||||
async def api_get_collection(collection_id: str, current_user: PublicUser = Depends(get_current_user)):
|
||||
"""
|
||||
Get single collection by ID
|
||||
"""
|
||||
return await get_collection(collection_id, current_user)
|
||||
|
||||
|
||||
@router.get("/page/{page}/limit/{limit}")
|
||||
async def api_get_collection_by(page: int, limit: int, current_user: PublicUser = Depends(get_current_user)):
|
||||
"""
|
||||
Get collections by page and limit
|
||||
"""
|
||||
return await get_collections(page, limit)
|
||||
|
||||
|
||||
@router.put("/{collection_id}")
|
||||
async def api_update_collection(collection_object: Collection, collection_id: str, current_user: PublicUser = Depends(get_current_user)):
|
||||
"""
|
||||
Update collection by ID
|
||||
"""
|
||||
return await update_collection(collection_object, collection_id, current_user)
|
||||
|
||||
|
||||
@router.delete("/{collection_id}")
|
||||
async def api_delete_collection(collection_id: str, current_user: PublicUser = Depends(get_current_user)):
|
||||
"""
|
||||
Delete collection by ID
|
||||
"""
|
||||
|
||||
return await delete_collection(collection_id, current_user)
|
||||
Loading…
Add table
Add a link
Reference in a new issue