Exemple #1
0
from typing import List
from fastapi import Depends
from auth.backend import authenticate
from auth.schemas import User
from base.database import engine, Base, get_db
from questions.router import ItemRouter
from questions.schemas import events as schemas
from sqlalchemy.orm import Session
from .. import models

Base.metadata.create_all(bind=engine)

event_router = ItemRouter(
    model=models.Event,
    get_schema=schemas.Event,
    create_schema=schemas.EventCreate,
    update_schema=schemas.EventUpdate,
    prefix='/events',
    tags=['events'],
)


@event_router.get('/user/{user_pk}', response_model=List[schemas.Event])
async def get_events_by_user(user_pk, db: Session = Depends(get_db)):
    event = models.Event.manager(db).filter(owner_pk=user_pk)
    return event


@event_router.get('/my/', response_model=List[schemas.Event])
async def get_my_events(db: Session = Depends(get_db),
                        user: User = Depends(authenticate)):
    event = models.Event.manager(db).filter(owner_pk=user.pk)
Exemple #2
0
from base.database import engine, Base
from questions.router import ItemRouter

from .. import models
from questions.schemas import polls as schemas

Base.metadata.create_all(bind=engine)

options_router = ItemRouter(
    model=models.Option,
    get_schema=schemas.Option,
    create_schema=schemas.OptionCreate,
    update_schema=schemas.OptionUpdate,
    prefix='/options',
    tags=['options'],
)
Exemple #3
0
from auth.backend import authenticate
from auth.schemas import User
from base.database import engine, Base, get_db
from questions.router import ItemRouter

from .. import models
from questions.schemas import questions as schemas


Base.metadata.create_all(bind=engine)


questions_router = ItemRouter(
    model=models.Question,
    get_schema=schemas.Question,
    create_schema=schemas.QuestionCreate,
    update_schema=schemas.QuestionPatch,
    prefix='/questions',
    tags=['questions'],
)


@questions_router.get('/my/', response_model=List[schemas.Question])
async def get_my_questions(
    skip: int = 0,
    limit: int = 100,
    db: Session = Depends(get_db),
    user: User = Depends(authenticate)
):
    questions = models.Question.manager(db).filter(author_pk=user.pk)
    return questions
Exemple #4
0
from base.database import engine, Base
from questions.router import ItemRouter

from .. import models
from questions.schemas import polls as schemas

Base.metadata.create_all(bind=engine)

polls_router = ItemRouter(
    model=models.Poll,
    get_schema=schemas.Poll,
    create_schema=schemas.PollCreate,
    update_schema=schemas.PollUpdate,
    prefix='/polls',
    tags=['polls'],
)
def item_router():
    return ItemRouter(model=Question,
                      get_schema=questions.Question,
                      create_schema=questions.QuestionCreateTest,
                      update_schema=questions.QuestionPatch,
                      prefix='/test')
def test_get_schemas_diff_models_exclude_user(item_router: ItemRouter):
    models = item_router._get_schema_diff_models_exclude_user()

    assert [Event] == models
def test_get_schemas_diff_models(item_router: ItemRouter):
    models = item_router._get_schema_diff_models()

    assert [Event, User] == models
def test_get_schemas_diff(item_router: ItemRouter):
    assert len(item_router._get_schemas_diff()) == 2
    assert 'event' in item_router._get_schemas_diff()
    assert 'author' in item_router._get_schemas_diff()
Exemple #9
0
from base.database import engine, Base
from questions.router import ItemRouter

from .. import models
from questions.schemas import polls as schemas

Base.metadata.create_all(bind=engine)

votes_router = ItemRouter(
    model=models.Vote,
    get_schema=schemas.Vote,
    create_schema=schemas.VoteCreate,
    update_schema=schemas.VoteCreate,
    prefix='/votes',
    tags=['votes'],
)