Skip to content

Commit

Permalink
refactor: GET endponit for DRPC record list includes tags
Browse files Browse the repository at this point in the history
Signed-off-by: Akiff Manji <akiff.manji@quartech.com>
  • Loading branch information
amanji committed Jan 30, 2024
1 parent 1b1f2f5 commit 32a2bf9
Showing 1 changed file with 48 additions and 16 deletions.
64 changes: 48 additions & 16 deletions rpc/rpc/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@
import logging

from aiohttp import web
from aiohttp_apispec import docs, querystring_schema, request_schema, response_schema
from aiohttp_apispec import (
docs,
querystring_schema,
request_schema,
response_schema,
)
from marshmallow import fields, validate

from aries_cloudagent.admin.request_context import AdminRequestContext
from aries_cloudagent.connections.models.conn_record import ConnRecord
from aries_cloudagent.messaging.models.base import (
BaseModel,
BaseModelSchema,
BaseModelError,
)
from aries_cloudagent.messaging.models.base_record import match_post_filter
from aries_cloudagent.messaging.models.openapi import OpenAPISchema
from aries_cloudagent.messaging.valid import UUID4_EXAMPLE
from aries_cloudagent.messaging.models.base import BaseModel, BaseModelSchema
from aries_cloudagent.storage.base import BaseStorage, StorageRecord
from aries_cloudagent.storage.error import StorageNotFoundError, StorageError

Expand Down Expand Up @@ -117,19 +127,19 @@ class Meta:


class DRPCRecordListQuerySchema(OpenAPISchema):
"""Parameters and validators for credential exchange record list query."""
"""Parameters and validators for DIDComm RPC request/response exchange query."""

connection_id = fields.Str(
connection_id = fields.String(
required=False,
metadata={"description": "Connection identifier", "example": UUID4_EXAMPLE},
)

thread_id = fields.Str(
thread_id = fields.String(
required=False,
metadata={"description": "Thread identifier", "example": UUID4_EXAMPLE},
)

state = fields.Str(
state = fields.String(
required=False,
validate=validate.OneOf(
[
Expand All @@ -152,6 +162,17 @@ class DRPCRecordListSchema(OpenAPISchema):
)


class DRPCRecordMatchInfoSchema(OpenAPISchema):
"""Parameters and validators for DIDComm RPC request/response exchange match."""

record_id = fields.String(
required=True,
metadata={
"description": "DRPC record identifier",
},
)


@docs(
tags=["drpc"],
summary="Send a DIDComm RPC request message",
Expand Down Expand Up @@ -305,17 +326,28 @@ async def drpc_get_records(request: web.BaseRequest):

async with context.session() as session:
try:
records = await DRPCRecord.query(
session,
tag_filter=tag_filter,
post_filter_positive=post_filter,
alt=True,
storage = session.inject(BaseStorage)
rows = await storage.find_all_records(
DRPCRecord.RECORD_TYPE,
DRPCRecord.prefix_tag_filter(tag_filter),
{"forUpdate": False, "retrieveTags": False},
)
results = [
{**record.serialize(), "id": record.storage_record.id}
for record in records
]
except StorageError as err:
results = []
for record in rows:
val = json.loads(record.value)
if match_post_filter(val, post_filter, positive=True, alt=True):
try:
drpc_record = DRPCRecord.from_storage(record.id, val)
results.append(
{
**drpc_record.serialize(),
"id": record.id,
"tags": record.tags,
}
)
except BaseModelError as err:
raise BaseModelError(f"{err}, for record id {record.id}")
except (StorageError, BaseModelError) as err:
raise web.HTTPInternalServerError(reason=err.roll_up) from err

return web.json_response({"results": results})
Expand Down

0 comments on commit 32a2bf9

Please sign in to comment.