diff --git a/internal/graph/attestation.resolvers.go b/internal/graph/attestation.resolvers.go index 0cded5fa..438adc13 100644 --- a/internal/graph/attestation.resolvers.go +++ b/internal/graph/attestation.resolvers.go @@ -12,5 +12,5 @@ import ( // Attestations is the resolver for the attestations field. func (r *queryResolver) Attestations(ctx context.Context, tokenID int, filter *model.AttestationFilter) ([]*model.Attestation, error) { - return r.AttestationRepo.GetAttestations(ctx, uint32(tokenID), filter) + return r.AttestationRepo.GetAttestations(ctx, tokenID, filter) } diff --git a/internal/graph/generated.go b/internal/graph/generated.go index 6c2e0dbd..1a2c6759 100644 --- a/internal/graph/generated.go +++ b/internal/graph/generated.go @@ -2326,6 +2326,11 @@ type Attestation { AttestationFilter holds the filter parameters for the attestation querys. """ input AttestationFilter { + """ + id is the id of the attestation. + """ + id: String + """ The attesting party. """ @@ -24549,13 +24554,20 @@ func (ec *executionContext) unmarshalInputAttestationFilter(ctx context.Context, asMap[k] = v } - fieldsInOrder := [...]string{"source", "dataVersion", "producer", "before", "after", "limit"} + fieldsInOrder := [...]string{"id", "source", "dataVersion", "producer", "before", "after", "limit"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { continue } switch k { + case "id": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.ID = data case "source": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("source")) data, err := ec.unmarshalOAddress2ᚖgithubᚗcomᚋethereumᚋgoᚑethereumᚋcommonᚐAddress(ctx, v) diff --git a/internal/graph/model/models_gen.go b/internal/graph/model/models_gen.go index 05aed6d9..851567b4 100644 --- a/internal/graph/model/models_gen.go +++ b/internal/graph/model/models_gen.go @@ -42,6 +42,8 @@ type Attestation struct { // AttestationFilter holds the filter parameters for the attestation querys. type AttestationFilter struct { + // id is the id of the attestation. + ID *string `json:"id,omitempty"` // The attesting party. Source *common.Address `json:"source,omitempty"` // Filter attestations by data version. diff --git a/internal/repositories/attestation/attestation.go b/internal/repositories/attestation/attestation.go index 279216e8..7120177d 100644 --- a/internal/repositories/attestation/attestation.go +++ b/internal/repositories/attestation/attestation.go @@ -34,7 +34,7 @@ func New(indexService indexRepoService, chainID uint64, vehicleAddress common.Ad } // GetAttestations fetches attestations for the given vehicle. -func (r *Repository) GetAttestations(ctx context.Context, vehicleTokenID uint32, filter *model.AttestationFilter) ([]*model.Attestation, error) { +func (r *Repository) GetAttestations(ctx context.Context, vehicleTokenID int, filter *model.AttestationFilter) ([]*model.Attestation, error) { vehicleDID := cloudevent.ERC721DID{ ChainID: r.chainID, ContractAddress: r.vehicleAddress, @@ -70,6 +70,10 @@ func (r *Repository) GetAttestations(ctx context.Context, vehicleTokenID uint32, if filter.Limit != nil { limit = *filter.Limit } + + if filter.ID != nil { + opts.Id = &wrapperspb.StringValue{Value: *filter.ID} + } } cloudEvents, err := r.indexService.GetAllCloudEvents(ctx, opts, int32(limit)) diff --git a/internal/repositories/attestation/attestation_test.go b/internal/repositories/attestation/attestation_test.go index cd6f63a2..130d5f72 100644 --- a/internal/repositories/attestation/attestation_test.go +++ b/internal/repositories/attestation/attestation_test.go @@ -43,7 +43,7 @@ func (m *MockRow) ScanStruct(any) error { return nil } -func TestAttestation(t *testing.T) { +func TestGetAttestations(t *testing.T) { // Initialize variables ctx := context.Background() validVehTknID := int(123) @@ -88,7 +88,7 @@ func TestAttestation(t *testing.T) { tests := []struct { name string mockSetup func() - vehTknID uint32 + vehTknID int filters *model.AttestationFilter expectedAtts []*model.Attestation expectedErr bool @@ -101,7 +101,7 @@ func TestAttestation(t *testing.T) { defaultEvent, }, nil) }, - vehTknID: uint32(validVehTknID), + vehTknID: validVehTknID, expectedAtts: []*model.Attestation{ &model.Attestation{ ID: id, @@ -130,7 +130,7 @@ func TestAttestation(t *testing.T) { Source: &validSigner, Limit: &limit, }, - vehTknID: uint32(validVehTknID), + vehTknID: validVehTknID, expectedAtts: []*model.Attestation{ &model.Attestation{ ID: id, @@ -149,7 +149,7 @@ func TestAttestation(t *testing.T) { mockSetup: func() { mockService.EXPECT().GetAllCloudEvents(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil) }, - vehTknID: uint32(invalidVehTknID), + vehTknID: invalidVehTknID, }, } diff --git a/schema/attestation.graphqls b/schema/attestation.graphqls index 26926c6f..22d1c9c8 100644 --- a/schema/attestation.graphqls +++ b/schema/attestation.graphqls @@ -71,6 +71,11 @@ type Attestation { AttestationFilter holds the filter parameters for the attestation querys. """ input AttestationFilter { + """ + id is the id of the attestation. + """ + id: String + """ The attesting party. """