mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2025-12-06 07:05:36 +01:00
Init
This commit is contained in:
25
fastapi_book_server/app/views/source.py
Normal file
25
fastapi_book_server/app/views/source.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from fastapi_pagination import Params, Page
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
|
||||
from app.models import Source as SourceDB
|
||||
from app.serializers.source import Source, CreateSource
|
||||
|
||||
|
||||
source_router = APIRouter(
|
||||
prefix="/api/v1/sources",
|
||||
tags=["source"],
|
||||
)
|
||||
|
||||
|
||||
@source_router.get("", response_model=Page[Source], dependencies=[Depends(Params)])
|
||||
async def get_sources():
|
||||
return await paginate(SourceDB.objects)
|
||||
|
||||
|
||||
@source_router.post("", response_model=Source)
|
||||
async def create_source(data: CreateSource):
|
||||
return await SourceDB.objects.create(
|
||||
**data.dict()
|
||||
)
|
||||
Reference in New Issue
Block a user