implement family tree query

This commit is contained in:
2025-04-12 11:32:15 +02:00
parent e40e306faa
commit d054ec5c10
6 changed files with 115 additions and 33 deletions

View File

@@ -749,6 +749,64 @@
}
}
},
"/person/{id}/family-tree-with-spouses": {
"get": {
"summary": "Get family tree by person ID with spouses included",
"operationId": "getFamilyTreeById",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer"
}
}
],
"responses": {
"200": {
"description": "Family tree retrieved",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/FamilyTree"
}
}
}
},
"400": {
"description": "Bad request",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"msg": {
"type": "string"
}
}
}
}
}
},
"500": {
"description": "Internal server error",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"msg": {
"type": "string"
}
}
}
}
}
}
}
}
},
"/person/{id}/recipes": {
"get": {
"summary": "Get recipes by person ID",
@@ -2519,32 +2577,17 @@
"FamilyTree": {
"type": "object",
"properties": {
"ancestors": {
"people": {
"type": "array",
"items": {
"$ref": "#/components/schemas/OptimizedPersonNode"
}
},
"prel1": {
"$ref": "#/components/schemas/Relationship"
},
"children": {
"relationships": {
"type": "array",
"items": {
"$ref": "#/components/schemas/OptimizedPersonNode"
"items":{
"$ref": "#/components/schemas/Relationship"
}
},
"prel2": {
"$ref": "#/components/schemas/Relationship"
},
"spouses": {
"type": "string"
},
"srel": {
"$ref": "#/components/schemas/Relationship"
},
"user": {
"type": "string"
}
}
},

View File

@@ -125,3 +125,17 @@ var GetProfileAdminsCypherQuery string
//
//go:embed queries/get_managed_profiles.cypher
var GetManagedProfilesCypherQuery string
// Requires id parameter.
//
// returns people, relationships
//
//go:embed queries/get_blood_relations_by_id.cypher
var GetBloodRelativesCypherQuery string
// Requires id parameter.
//
// returns people, relationships
//
//go:embed queries/get_family_tree_with_spouses.cypher
var GetFamilyTreeWithSpousesCypherQuery string

View File

@@ -1,4 +1,19 @@
MATCH (n:Person)-[p:Parent*1..]->(family:Person)
MATCH (n:Person)
WHERE id(n) = $id
OPTIONAL MATCH (n)-[p:Parent*..]->(family:Person)
OPTIONAL MATCH (family)-[c:Child*1..4]->(children:Person)
RETURN collect(family) + collect(children) + collect(n), collect(c) + collect(p)
OPTIONAL MATCH (family)-[s:Sibling]->(siblings:Person)
OPTIONAL MATCH (n)-[ds:Sibling]->(direct_siblings:Person)
WITH collections.to_set(collect(n)+collect(family)+collect(children)+collect(direct_siblings)) as people,
collections.to_set(collect(c) + collect(p) + collect(s) + collect(ds)) as relationships
UNWIND people as ppl
RETURN collect({
id: id(ppl),
first_name: ppl.first_name,
middle_name: ppl.middle_name,
last_name: ppl.last_name,
born: ppl.born,
died: ppl.died,
profile_picture: ppl.profile_picture
}) as people,
relationships;

View File

@@ -1,8 +0,0 @@
MATCH (n:Person)-[p:Parent*1..]->(family:Person)
WHERE id(n) = $id
OPTIONAL MATCH (family)-[c:Child*..4]->(children:Person)
WITH family, p, children, c, n
OPTIONAL MATCH (children)<-[p2:Parent]-(OtherParents:Person)
WITH family, p, children, c, OtherParents, p2, n
OPTIONAL MATCH (family)-[s:Spouse]-(spouse:Person)
RETURN family, p, children, c, OtherParents, p2, spouse, s, n;

View File

@@ -0,0 +1,22 @@
MATCH (n:Person)
WHERE id(n) = $id
OPTIONAL MATCH (n)-[p:Parent*..]->(family:Person)
OPTIONAL MATCH (family)-[c:Child*1..4]->(children:Person)
OPTIONAL MATCH (family)-[s:Sibling]->(siblings:Person)
OPTIONAL MATCH (n)-[ds:Sibling]->(direct_siblings:Person)
OPTIONAL MATCH (family)-[fsp:Spouse]->(fspouse:Person)
OPTIONAL MATCH (children)-[csp:Spouse]->(cspouse:Person)
OPTIONAL MATCH (n)-[sp:Spouse]->(spouse:Person)
WITH collections.to_set(collect(n) + collect(family) + collect(children) + collect(direct_siblings) + collect(fspouse) + collect(cspouse) + collect(spouse)) as people,
collections.to_set(collect(c) + collect(p) + collect(s) + collect(ds) + collect(fsp) + collect(csp) + collect(sp)) as relationships
UNWIND people as ppl
RETURN collect({
id: id(ppl),
first_name: ppl.first_name,
middle_name: ppl.middle_name,
last_name: ppl.last_name,
born: ppl.born,
died: ppl.died,
profile_picture: ppl.profile_picture
}) as people,
relationships;

View File

@@ -1,4 +0,0 @@
MATCH (n:Person)-[p:Parent*1..]->(family:Person)
WHERE id(n) = $id
OPTIONAL MATCH (family)-[c:Child*..4]->(children:Person)
RETURN family, p, children, c, n