def serialize(self) -> dict: """Serialize to JSON-compatible dict format.""" return { "issuer": IssuerSerializer(self.issuer).data, "schemas": [SchemaSerializer(schema).data for schema in self.schemas], "credential_types": [ CredentialTypeExtSerializer(credential_type).data for credential_type in self.credential_types ], }
def register_issuer(self, didauth, spec): user = self.update_user(didauth, spec["issuer"]) issuer = self.update_issuer(spec["issuer"]) schemas, credential_types = self.update_schemas_and_ctypes( issuer, spec.get("credential_types", [])) # TODO: use a serializer to return consistent data with REST API? # Do this at the view layer instead of this manager? result = { "issuer": IssuerSerializer(issuer).data, "schemas": [SchemaSerializer(schema).data for schema in schemas], "credential_types": [ CredentialTypeSerializer(credential_type).data for credential_type in credential_types ], } return result
def retrieve(self, request, pk=None): queryset = Schema.objects.all() item = get_object_or_404(queryset, pk=pk) serializer = SchemaSerializer(item) return Response(serializer.data)
def list(self, request): queryset = Schema.objects.all() serializer = SchemaSerializer(queryset, many=True) return Response(serializer.data)