Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add references #13

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions aiida_optimade/routers/references.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from typing import Union

from fastapi import APIRouter, Depends
from starlette.requests import Request

from aiida import orm

from optimade.models import (
ErrorResponse,
ReferenceResource,
ReferenceResponseMany,
ReferenceResponseOne,
)

from aiida_optimade.query_params import EntryListingQueryParams, SingleEntryQueryParams
from aiida_optimade.entry_collections import AiidaCollection
from aiida_optimade.mappers import ReferenceMapper
from aiida_optimade.utils import get_backend

from .utils import get_entries, get_single_entry


router = APIRouter()

references = AiidaCollection(
orm.ReferenceData.objects, ReferenceResource, ReferenceMapper
)


@router.get(
"/references",
response_model=Union[ReferenceResponseMany, ErrorResponse],
response_model_skip_defaults=True,
tags=["Reference"],
)
def get_references(
request: Request,
params: EntryListingQueryParams = Depends(),
backend: orm.implementation.Backend = Depends(get_backend),
):
return get_entries(
backend=backend,
collection=references,
response=ReferenceResponseMany,
request=request,
params=params,
)


@router.get(
"/references/{entry_id}",
response_model=Union[ReferenceResponseOne, ErrorResponse],
response_model_skip_defaults=True,
tags=["Reference"],
)
def get_single_reference(
request: Request,
entry_id: int,
params: SingleEntryQueryParams = Depends(),
backend: orm.implementation.Backend = Depends(get_backend),
):
return get_single_entry(
backend=backend,
collection=references,
entry_id=entry_id,
response=ReferenceResponseOne,
request=request,
params=params,
)
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
filterwarnings =
ignore:.*PY_SSIZE_T_CLEAN will be required for '#' formats.*:DeprecationWarning
ignore:.*"@coroutine" decorator is deprecated since Python 3.8, use "async def" instead.*:DeprecationWarning
ignore:Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working:DeprecationWarning
ignore:.*Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated.*:DeprecationWarning