60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
from fastapi import FastAPI, APIRouter
|
||
from .models import CollectionPublic, CollectionCreate, CollectionUpdate
|
||
from .models import get_collections, create_colletion, update_collection, delete_collection
|
||
|
||
router = APIRouter(
|
||
prefix="/collections",
|
||
tags=["collections"],
|
||
responses={404: {"description": "Not found"}},
|
||
dependencies=[],
|
||
)
|
||
|
||
|
||
|
||
@router.get("/{user_id}")
|
||
async def get_collections_api(user_id: int) -> list[CollectionPublic]:
|
||
"""
|
||
Kullanıcının collectionlarını döndürür
|
||
"""
|
||
|
||
_collections : list[CollectionPublic] = get_collections(user_id=user_id)
|
||
|
||
return _collections
|
||
|
||
|
||
|
||
@router.post("/{user_id}")
|
||
async def create_collection(
|
||
user_id: int,
|
||
collection: CollectionCreate
|
||
) -> bool:
|
||
"""
|
||
Collection oluşturma fonksiyonu
|
||
"""
|
||
_result = create_colletion(user_id=user_id, collection=collection)
|
||
return _result
|
||
|
||
|
||
@router.put("/{user_id}/{collection_id}")
|
||
async def update_collection_api(
|
||
user_id: int,
|
||
collection_id : int,
|
||
collection: CollectionUpdate
|
||
) -> bool:
|
||
"""
|
||
Collection güncelleme fonksiyonu
|
||
"""
|
||
_result = update_collection(user_id=user_id, collection_id=collection_id, collection=collection)
|
||
return _result
|
||
|
||
|
||
@router.delete("/{user_id}/{collection_id}")
|
||
async def delete_collection_api(
|
||
user_id: int,
|
||
collection_id : int
|
||
) -> bool:
|
||
"""
|
||
Collection silme fonksiyonu
|
||
"""
|
||
_result = delete_collection(user_id=user_id, collection_id=collection_id)
|
||
return _result |