0.1.0 boosted
This commit is contained in:
parent
126e90084e
commit
f29c40d25e
11 changed files with 181 additions and 22 deletions
24
htmx_patterns/boosted/models.py
Normal file
24
htmx_patterns/boosted/models.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from datetime import date, datetime
|
||||
from typing import List, Union
|
||||
|
||||
from faker import Faker
|
||||
from polyfactory.factories.pydantic_factory import ModelFactory
|
||||
from pydantic import UUID4, BaseModel
|
||||
|
||||
faker = Faker()
|
||||
|
||||
|
||||
class Person(BaseModel):
|
||||
id: UUID4
|
||||
name: str
|
||||
birthday: Union[datetime, date]
|
||||
phone_number: str
|
||||
|
||||
|
||||
class PersonFactory(ModelFactory):
|
||||
name = faker.name
|
||||
phone_number = faker.phone_number
|
||||
__model__ = Person
|
||||
|
||||
|
||||
# result = PersonFactory.build()
|
||||
37
htmx_patterns/boosted/router.py
Normal file
37
htmx_patterns/boosted/router.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import asyncio
|
||||
import time
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi.requests import Request
|
||||
|
||||
boosted_router = APIRouter(prefix="/boosted", tags=["Shots Methods"])
|
||||
|
||||
from htmx_patterns.boosted.models import PersonFactory
|
||||
from htmx_patterns.config import get_config
|
||||
|
||||
config = get_config()
|
||||
|
||||
|
||||
@boosted_router.get("/")
|
||||
@boosted_router.get("")
|
||||
async def boosted(request: Request, id: int = 0):
|
||||
# simulate getting a person by id
|
||||
person = PersonFactory.build()
|
||||
|
||||
if id > 0:
|
||||
prev_id = id - 1
|
||||
next_id = id + 1
|
||||
else:
|
||||
prev_id = None
|
||||
next_id = id + 1
|
||||
|
||||
return config.templates.TemplateResponse(
|
||||
"boosted/person.html",
|
||||
{
|
||||
"request": request,
|
||||
"person": person,
|
||||
"person_id": id,
|
||||
"prev_id": prev_id,
|
||||
"next_id": next_id,
|
||||
},
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue