diff --git a/pfp_api/main.py b/pfp_api/main.py
index 8a7d6f2..9deb87d 100644
--- a/pfp_api/main.py
+++ b/pfp_api/main.py
@@ -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()
@@ -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())
diff --git a/pfp_api/models.py b/pfp_api/models.py
index 34c6482..9da0c68 100644
--- a/pfp_api/models.py
+++ b/pfp_api/models.py
@@ -1,4 +1,5 @@
from pydantic import BaseModel, Field
+from typing import List, Optional
class Entity(BaseModel): ...
@@ -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
diff --git a/pfp_api/templates/person.j2 b/pfp_api/templates/person.j2
new file mode 100644
index 0000000..a8f9b2d
--- /dev/null
+++ b/pfp_api/templates/person.j2
@@ -0,0 +1,6 @@
+PREFIX crm:
+PREFIX rdfs:
+SELECT ?subject
+WHERE {
+ ?subject proxy_for <{{ person_id }}> .
+}