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

feat: introduce persondetail endpoint, model & template #6

Merged
merged 1 commit into from
Jan 13, 2025
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
21 changes: 19 additions & 2 deletions pfp_api/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import binascii
from base64 import urlsafe_b64decode
from jinja2 import Environment, PackageLoader
from typing import Annotated
from fastapi import FastAPI, Query, Response, status
from fastapi import FastAPI, Query, Response, status, HTTPException

from rdfproxy import Page, SPARQLModelAdapter, QueryParameters

from pfp_api.models import Person
from pfp_api.models import Person, PersonDetail


app = FastAPI()
Expand All @@ -29,3 +31,18 @@ def persons(query_parameters: Annotated[PersonParams, Query()]) -> Page[Person]:
model=Person,
)
return adapter.query(query_parameters)


@app.get("/person/{person_id}")
def person(person_id: str):
template = env.get_template("person.j2")
try:
person_id = urlsafe_b64decode(person_id).decode()
except binascii.Error:
raise HTTPException(status_code=404, detail="Person not found")
adapter = SPARQLModelAdapter(
target="https://pfp-ts-backend.acdh-ch-dev.oeaw.ac.at/",
query=template.render({"person_id": person_id}),
model=PersonDetail
)
return adapter.query(QueryParameters())
7 changes: 7 additions & 0 deletions pfp_api/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pydantic import BaseModel, Field
from typing import List, Optional


class Entity(BaseModel): ...
Expand All @@ -12,3 +13,9 @@ class Person(Entity):
person: str = None
label: str = Field(..., example="Arthur Schnitzler")
graph: str = None


class PersonDetail(Entity):
person: str = None
label: str = Field(..., example="Arthur Schnitzler")
events: Optional[List[Event]] = None
6 changes: 6 additions & 0 deletions pfp_api/templates/person.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?subject
WHERE {
?subject proxy_for <{{ person_id }}> .
}
Loading