mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2025-12-06 15:15:36 +01:00
Add random endpoints
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from random import choice as random_choice
|
||||
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
|
||||
from fastapi_pagination import Params
|
||||
@@ -24,6 +26,15 @@ async def get_sequences():
|
||||
)
|
||||
|
||||
|
||||
@sequence_router.get("/random", response_model=Sequence)
|
||||
async def get_random_sequence():
|
||||
sequence_ids: list[int] = await SequenceDB.objects.values_list("id", flatten=True)
|
||||
|
||||
sequence_id = random_choice(sequence_ids)
|
||||
|
||||
return await SequenceDB.objects.get(id=sequence_id)
|
||||
|
||||
|
||||
@sequence_router.get("/{id}", response_model=Sequence)
|
||||
async def get_sequence(id: int):
|
||||
return await SequenceDB.objects.get(id=id)
|
||||
|
||||
Reference in New Issue
Block a user