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

Updates to many of the endpoint return schemas #103

Merged
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
179 changes: 81 additions & 98 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "geneweaver-api"
version = "0.11.0"
version = "0.12.0a0"
description = "The Geneweaver API"
authors = [
"Alexander Berger <alexander.berger@jax.org>",
Expand All @@ -19,7 +19,7 @@ packages = [
python = "^3.9"
geneweaver-core = "^0.10.0a3"
fastapi = {extras = ["all"], version = "^0.115.0"}
uvicorn = {extras = ["standard"], version = "^0.30.0"}
uvicorn = {extras = ["standard"], version = "^0.32.0"}
geneweaver-db = "^0.6.0a3"
psycopg-pool = "^3.1.7"
requests = "^2.32.3"
Expand Down
10 changes: 5 additions & 5 deletions src/geneweaver/api/controller/genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
GeneIdMappingAonReq,
GeneIdMappingReq,
GeneIdMappingResp,
GeneReturn,
)
from geneweaver.api.services import genes as genes_service
from geneweaver.core.enum import GeneIdentifier, Species
from geneweaver.core.schema.gene import Gene
from jax.apiutils import CollectionResponse, Response
from typing_extensions import Annotated

from . import message as api_message
Expand Down Expand Up @@ -50,15 +50,15 @@ def get_genes(
description=api_message.OFFSET,
),
] = None,
) -> GeneReturn:
) -> CollectionResponse[Gene]:
"""Get geneweaver list of genes."""
if limit is None:
limit = 100

response = genes_service.get_genes(
cursor, reference_id, gene_database, species, preferred, limit, offset
)
return response
return CollectionResponse[Gene](**response)


@router.get("/{gene_id}/preferred")
Expand All @@ -67,10 +67,10 @@ def get_gene_preferred(
int, Path(format="int64", minimum=0, maxiumum=9223372036854775807)
],
cursor: Optional[deps.Cursor] = Depends(deps.cursor),
) -> Gene:
) -> Response[Gene]:
"""Get preferred gene for a given gene ode_id."""
response = genes_service.get_gene_preferred(cursor, gene_id)
return response
return Response[Gene](response)


@router.post("/homologs", response_model=GeneIdMappingResp, deprecated=True)
Expand Down
58 changes: 30 additions & 28 deletions src/geneweaver/api/controller/genesets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
from fastapi import APIRouter, Depends, HTTPException, Path, Query, Request, Security
from fastapi.responses import FileResponse, StreamingResponse
from geneweaver.api import dependencies as deps
from geneweaver.api.schemas.apimodels import GeneValueReturn
from geneweaver.api.schemas.auth import UserInternal
from geneweaver.api.schemas.search import GenesetSearch
from geneweaver.api.services import geneset as genset_service
from geneweaver.api.services import geneset as geneset_service
from geneweaver.api.services import publications as publication_service
from geneweaver.core.enum import GeneIdentifier, GenesetTier, Species
from geneweaver.core.schema.geneset import GeneValue
from geneweaver.core.schema.publication import Publication
from geneweaver.core.schema.score import GenesetScoreType, ScoreType
from geneweaver.db import search as db_search
from jax.apiutils import CollectionResponse
from jax.apiutils import CollectionResponse, Response
from typing_extensions import Annotated

from . import message as api_message
Expand Down Expand Up @@ -114,9 +115,9 @@ def get_visible_genesets(
description=api_message.OFFSET,
),
] = None,
) -> dict:
) -> CollectionResponse:
"""Get all visible genesets."""
response = genset_service.get_visible_genesets(
response = geneset_service.get_visible_genesets(
cursor=cursor,
user=user,
gs_id=gs_id,
Expand Down Expand Up @@ -144,7 +145,7 @@ def get_visible_genesets(

raise_http_error(response)

return response
return CollectionResponse(**response)


@router.get("/search")
Expand Down Expand Up @@ -175,20 +176,20 @@ def get_geneset(
cursor: Optional[deps.Cursor] = Depends(deps.cursor),
gene_id_type: Optional[GeneIdentifier] = None,
in_threshold: Optional[bool] = None,
) -> dict:
) -> Response:
"""Get a geneset by ID. Optional filter results by gene identifier type."""
if gene_id_type:
response = genset_service.get_geneset_w_gene_id_type(
response = geneset_service.get_geneset_w_gene_id_type(
cursor, geneset_id, user, gene_id_type
)
else:
response = genset_service.get_geneset(
response = geneset_service.get_geneset(
cursor=cursor, geneset_id=geneset_id, user=user, in_threshold=in_threshold
)

raise_http_error(response)

return response
return Response(response)


@router.get("/{geneset_id}/values")
Expand All @@ -200,9 +201,9 @@ def get_geneset_values(
cursor: Optional[deps.Cursor] = Depends(deps.cursor),
gene_id_type: Optional[GeneIdentifier] = None,
in_threshold: Optional[bool] = None,
) -> GeneValueReturn:
) -> CollectionResponse[GeneValue]:
"""Get geneset gene values by geneset ID."""
response = genset_service.get_geneset_gene_values(
response = geneset_service.get_geneset_gene_values(
cursor=cursor,
geneset_id=geneset_id,
user=user,
Expand All @@ -217,7 +218,7 @@ def get_geneset_values(
status_code=404, detail=api_message.INACCESSIBLE_OR_FORBIDDEN
)

return response
return CollectionResponse(**response)


@router.get("/{geneset_id}/file", response_class=FileResponse)
Expand All @@ -236,11 +237,11 @@ def get_export_geneset_by_id_type(

# Validate gene identifier type
if gene_id_type:
response = genset_service.get_geneset_w_gene_id_type(
response = geneset_service.get_geneset_w_gene_id_type(
cursor, geneset_id, user, gene_id_type
)
else:
response = genset_service.get_geneset(cursor, geneset_id, user)
response = geneset_service.get_geneset(cursor, geneset_id, user)

if "error" in response:
raise_http_error(response)
Expand Down Expand Up @@ -276,15 +277,15 @@ def get_geneset_metadata(
user: deps.OptionalFullUserDep,
cursor: Optional[deps.Cursor] = Depends(deps.cursor),
include_pub_info: Optional[bool] = False,
) -> dict:
) -> Response:
"""Get a geneset metadata by geneset id."""
response = genset_service.get_geneset_metadata(
response = geneset_service.get_geneset_metadata(
cursor, geneset_id, user, include_pub_info
)

raise_http_error(response)

return response
return Response(**response)


@router.get("/{geneset_id}/publication")
Expand All @@ -294,14 +295,15 @@ def get_publication_for_geneset(
],
user: deps.OptionalFullUserDep,
cursor: Optional[deps.Cursor] = Depends(deps.cursor),
) -> dict:
) -> Response[Publication]:
"""Get the publication associated with the geneset."""
geneset_resp = genset_service.get_geneset_metadata(cursor, geneset_id, user, True)
geneset_resp = geneset_service.get_geneset_metadata(cursor, geneset_id, user, True)

if "error" in geneset_resp:
raise_http_error(geneset_resp)

geneset = geneset_resp.get("geneset")
geneset = geneset_resp.get("object")

if geneset is None:
raise HTTPException(status_code=404, detail=api_message.RECORD_NOT_FOUND_ERROR)

Expand All @@ -314,7 +316,7 @@ def get_publication_for_geneset(
if pub_resp is None:
raise HTTPException(status_code=404, detail=api_message.RECORD_NOT_FOUND_ERROR)

return pub_resp
return Response[Publication](pub_resp)


@router.put("/{geneset_id}/threshold", status_code=204)
Expand All @@ -327,7 +329,7 @@ def put_geneset_threshold(
cursor: Optional[deps.Cursor] = Depends(deps.cursor),
) -> None:
"""Set geneset threshold for geneset owner."""
response = genset_service.update_geneset_threshold(
response = geneset_service.update_geneset_threshold(
cursor, geneset_id, gene_score_type, user
)

Expand Down Expand Up @@ -359,15 +361,15 @@ def get_geneset_ontology_terms(
description=api_message.OFFSET,
),
] = None,
) -> dict:
) -> CollectionResponse:
"""Get geneset ontology terms."""
terms_resp = genset_service.get_geneset_ontology_terms(
terms_resp = geneset_service.get_geneset_ontology_terms(
cursor, geneset_id, user, limit, offset
)

raise_http_error(terms_resp)

return terms_resp
return CollectionResponse(**terms_resp)


@router.put("/{geneset_id}/ontologies", status_code=204)
Expand All @@ -386,7 +388,7 @@ def put_geneset_ontology_term(
cursor: Optional[deps.Cursor] = Depends(deps.cursor),
) -> None:
"""Set geneset threshold for geneset owner."""
response = genset_service.add_geneset_ontology_term(
response = geneset_service.add_geneset_ontology_term(
cursor=cursor,
geneset_id=geneset_id,
term_ref_id=ontology_id,
Expand All @@ -412,7 +414,7 @@ def delete_geneset_ontology_term(
cursor: Optional[deps.Cursor] = Depends(deps.cursor),
) -> None:
"""Set geneset threshold for geneset owner."""
response = genset_service.delete_geneset_ontology_term(
response = geneset_service.delete_geneset_ontology_term(
cursor=cursor,
geneset_id=geneset_id,
term_ref_id=ontology_id,
Expand Down
5 changes: 3 additions & 2 deletions src/geneweaver/api/controller/monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from fastapi import APIRouter, Depends, Query
from geneweaver.api import dependencies as deps
from geneweaver.api.services import monitors as monitors_service
from jax.apiutils import Response
from typing_extensions import Annotated

from . import message as api_message
Expand All @@ -19,7 +20,7 @@ def get_health_check(
db_health_check: Annotated[
Optional[bool], Query(description=api_message.CHECK_DB_HEALTH)
] = False,
) -> dict:
) -> Response:
"""Return 200 API response if reachable and optionally check db health."""
response = {
"status": "UP",
Expand All @@ -31,4 +32,4 @@ def get_health_check(
db_health_response = monitors_service.check_db_health(cursor)
response["DB_status"] = db_health_response

return response
return Response(response)
17 changes: 9 additions & 8 deletions src/geneweaver/api/controller/publications.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from geneweaver.api.schemas.auth import UserInternal
from geneweaver.api.services import publications as publication_service
from geneweaver.core.schema.publication import Publication
from jax.apiutils import CollectionResponse, Response
from typing_extensions import Annotated

from . import message as api_message
Expand Down Expand Up @@ -51,7 +52,7 @@ def get_publication(
description=api_message.OFFSET,
),
] = None,
) -> dict:
) -> CollectionResponse[Publication]:
"""Get all publication publications with optional filters."""
response = publication_service.get(
cursor,
Expand All @@ -70,7 +71,7 @@ def get_publication(
offset=offset,
)

return response
return CollectionResponse(**response)


@router.get("/{publication_id}")
Expand All @@ -80,19 +81,19 @@ def get_publication_by_id(
],
as_pubmed_id: Optional[bool] = True,
cursor: Optional[deps.Cursor] = Depends(deps.cursor),
) -> Publication:
) -> Response[Publication]:
"""Get a publication by id."""
if as_pubmed_id:
response = publication_service.get_publication_by_pubmed_id(
cursor, publication_id
cursor, str(publication_id)
)
else:
response = publication_service.get_publication(cursor, publication_id)

if response is None:
raise HTTPException(status_code=404, detail=api_message.RECORD_NOT_FOUND_ERROR)

return response
return Response(response)


@router.put("/{publication_id}")
Expand All @@ -102,10 +103,10 @@ def add_publication(
],
user: UserInternal = Security(deps.full_user),
cursor: Optional[deps.Cursor] = Depends(deps.cursor),
) -> NewPubmedRecord:
) -> Response[NewPubmedRecord]:
"""Add pubmed publication endpoint."""
response = publication_service.add_pubmed_record(
cursor=cursor, user=user, pubmed_id=publication_id
cursor=cursor, user=user, pubmed_id=str(publication_id)
)

if "error" in response:
Expand All @@ -120,4 +121,4 @@ def add_publication(
else:
raise HTTPException(status_code=500, detail=api_message.UNEXPECTED_ERROR)

return response
return Response(response)
7 changes: 4 additions & 3 deletions src/geneweaver/api/controller/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

from fastapi import APIRouter, Depends, Query, Security
from geneweaver.api import dependencies as deps
from geneweaver.api.schemas.apimodels import CombinedSearchResponse, GsPubSearchType
from geneweaver.api.schemas.apimodels import GsPubSearchType
from geneweaver.api.schemas.auth import UserInternal
from geneweaver.api.services import publications as publication_service
from geneweaver.db import search as db_search
from jax.apiutils import Response
from typing_extensions import Annotated

from . import message as api_message
Expand Down Expand Up @@ -41,7 +42,7 @@ def search(
description=api_message.OFFSET,
),
] = None,
) -> CombinedSearchResponse:
) -> Response:
"""Search genesets and publications."""
search_results = {}
if "genesets" in entities:
Expand All @@ -65,6 +66,6 @@ def search(

search_results["publications"] = pub_response.get("data")

return CombinedSearchResponse(
return Response(
object=search_results,
)
Loading
Loading