Skip to content

Commit

Permalink
fix dummy view
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsung-Ju Lii committed Aug 23, 2023
1 parent a1c24ba commit 6ad4f3a
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from fastapi import APIRouter
from fastapi.param_functions import Depends
{%- if cookiecutter.db_info.name != "mongodb" %}
from {{cookiecutter.project_name}}.db.dao.dummy_dao import DummyDAO
{%- endif %}
from {{cookiecutter.project_name}}.db.models.dummy_model import DummyModel
from {{cookiecutter.project_name}}.web.api.dummy.schema import (DummyModelDTO,
DummyModelInputDTO)
Expand All @@ -14,28 +16,44 @@
async def get_dummy_models(
limit: int = 10,
offset: int = 0,
{%- if cookiecutter.db_info.name != "mongodb" %}
dummy_dao: DummyDAO = Depends(),
{%- endif %}
) -> List[DummyModel]:
"""
Retrieve all dummy objects from the database.
:param limit: limit of dummy objects, defaults to 10.
:param offset: offset of dummy objects, defaults to 0.
{%- if cookiecutter.db_info.name != "mongodb" %}
:param dummy_dao: DAO for dummy models.
{%- endif %}
:return: list of dummy objects from database.
"""
{%- if cookiecutter.db_info.name != "mongodb" %}
return await dummy_dao.get_all_dummies(limit=limit, offset=offset)
{%- else %}
return await DummyModel.find_all(skip=offset, limit=limit).to_list()
{%- endif %}


@router.put("/")
async def create_dummy_model(
new_dummy_object: DummyModelInputDTO,
{%- if cookiecutter.db_info.name != "mongodb" %}
dummy_dao: DummyDAO = Depends(),
{%- endif %}
) -> None:
"""
Creates dummy model in the database.
:param new_dummy_object: new dummy model item.
{%- if cookiecutter.db_info.name != "mongodb" %}
:param dummy_dao: DAO for dummy models.
{%- endif %}
"""
{%- if cookiecutter.db_info.name != "mongodb" %}
await dummy_dao.create_dummy_model(name=new_dummy_object.name)
{%- else %}
await DummyModel.insert_one(DummyModel(name=new_dummy_object.name))
{%- endif %}

0 comments on commit 6ad4f3a

Please sign in to comment.