crud for collections

This commit is contained in:
bdrtr 2025-05-14 18:29:46 +03:00
parent bf71979982
commit 250d3f1f15
4 changed files with 195 additions and 13 deletions

View file

@ -1,8 +1,60 @@
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