Parse partOf relationships in API response

This adds new functionality to the CCE API that enables the parent/child relationship between CCE entries
add-new-regnum-params
Mike Benowitz 2019-07-09 13:08:25 -04:00
parent 10247a07ab
commit a3c66b6aa5
3 changed files with 13 additions and 2 deletions

View File

@ -26,3 +26,6 @@ class QueryManager():
def orphanRenewalQuery(self, uuid):
return self.session.query(Renewal).filter(Renewal.uuid == uuid).one()
def getParentCCE(self, parentID):
return self.session.query(CCE).get(parentID)

View File

@ -28,6 +28,8 @@ def fullTextQuery():
for entry in matchingDocs:
if entry.meta.index == 'cce':
dbEntry = qManager.registrationQuery(entry.uuid)
if dbEntry.parent_cce_id:
dbEntry = qManager.getParentCCE(dbEntry.parent_cce_id)
textResponse.addResult(MultiResponse.parseEntry(
dbEntry,
xml=sourceReturn
@ -66,6 +68,8 @@ def regQuery(regnum):
qManager = QueryManager(db.session)
for entry in matchingDocs:
dbEntry = qManager.registrationQuery(entry.uuid)
if dbEntry.parent_cce_id:
dbEntry = qManager.getParentCCE(dbEntry.parent_cce_id)
regResponse.addResult(MultiResponse.parseEntry(
dbEntry,
xml=sourceReturn

View File

@ -39,7 +39,11 @@ class Response():
'part': dbEntry.volume.part,
'page': dbEntry.page,
'page_position': dbEntry.page_position
}
},
'has_parts': [
Response.parseEntry(part)
for part in dbEntry.children_cces
]
}
response['renewals'] = [
cls.parseRenewal(ren, source=xml)