Skip to content

Commit

Permalink
feat: support history filter by transactionID & vcID (#1743)
Browse files Browse the repository at this point in the history
  • Loading branch information
skynet2 authored Jul 10, 2024
1 parent 5adfa04 commit 9a622cf
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 71 deletions.
90 changes: 45 additions & 45 deletions api/spec/openapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions docs/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ paths:
in: path
required: true
description: Profile ID
- schema:
type: string
name: txID
in: query
required: false
description: Issuance transaction ID
- schema:
type: string
name: credentialID
in: query
required: false
description: Credential ID
get:
summary: Request Credential Issuance history.
responses:
Expand Down
15 changes: 13 additions & 2 deletions pkg/restapi/v1/issuer/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type credentialIssuanceHistoryStore interface {
GetIssuedCredentialsMetadata(
ctx context.Context,
profileID string,
txID *string,
credentialID *string,
) ([]*credentialstatus.CredentialMetadata, error)
}

Expand Down Expand Up @@ -1027,9 +1029,18 @@ func (c *Controller) PrepareBatchCredential(e echo.Context) error {

// CredentialIssuanceHistory returns Credential Issuance history.
// GET /issuer/profiles/{profileID}/issued-credentials.
func (c *Controller) CredentialIssuanceHistory(e echo.Context, profileID string) error {
func (c *Controller) CredentialIssuanceHistory(
e echo.Context,
profileID string,
extraParams CredentialIssuanceHistoryParams,
) error {
credentialMetadata, err := c.credentialIssuanceHistoryStore.
GetIssuedCredentialsMetadata(e.Request().Context(), profileID)
GetIssuedCredentialsMetadata(
e.Request().Context(),
profileID,
extraParams.TxID,
extraParams.CredentialID,
)
if err != nil {
return err
}
Expand Down
21 changes: 13 additions & 8 deletions pkg/restapi/v1/issuer/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/stretchr/testify/require"
timeutil "github.com/trustbloc/did-go/doc/util/time"
"github.com/trustbloc/vc-go/verifiable"
nooptracer "go.opentelemetry.io/otel/trace/noop"

"github.com/trustbloc/vcs/pkg/doc/vc"
vcsverifiable "github.com/trustbloc/vcs/pkg/doc/verifiable"
"github.com/trustbloc/vcs/pkg/event/spi"
Expand All @@ -37,7 +39,6 @@ import (
"github.com/trustbloc/vcs/pkg/restapi/v1/util"
"github.com/trustbloc/vcs/pkg/service/credentialstatus"
"github.com/trustbloc/vcs/pkg/service/oidc4ci"
nooptracer "go.opentelemetry.io/otel/trace/noop"
)

const (
Expand Down Expand Up @@ -2825,21 +2826,22 @@ func TestCredentialIssuanceHistory(t *testing.T) {
credentialIssuanceStore := NewMockCredentialIssuanceHistoryStore(gomock.NewController(t))

t.Run("Success", func(t *testing.T) {
txID := uuid.NewString()
txID := lo.ToPtr(uuid.NewString())
iss := timeutil.NewTime(time.Now())
credID := lo.ToPtr(uuid.NewString())

credentialMetadata := &credentialstatus.CredentialMetadata{
CredentialID: "credentialID",
Issuer: "testIssuer",
ProfileVersion: profileVersion,
CredentialType: []string{"verifiableCredential"},
TransactionID: txID,
TransactionID: *txID,
IssuanceDate: iss,
ExpirationDate: nil,
}

credentialIssuanceStore.EXPECT().
GetIssuedCredentialsMetadata(gomock.Any(), profileID).
GetIssuedCredentialsMetadata(gomock.Any(), profileID, txID, credID).
Times(1).
Return([]*credentialstatus.CredentialMetadata{credentialMetadata}, nil)

Expand All @@ -2851,7 +2853,10 @@ func TestCredentialIssuanceHistory(t *testing.T) {

echoCtx := echoContext(withRecorder(recorder))

err := c.CredentialIssuanceHistory(echoCtx, profileID)
err := c.CredentialIssuanceHistory(echoCtx, profileID, CredentialIssuanceHistoryParams{
TxID: txID,
CredentialID: credID,
})
assert.NoError(t, err)

var gotResponse []CredentialIssuanceHistoryData
Expand All @@ -2865,7 +2870,7 @@ func TestCredentialIssuanceHistory(t *testing.T) {
ExpirationDate: nil,
IssuanceDate: lo.ToPtr(iss.Time.Format(time.RFC3339)),
Issuer: "testIssuer",
TransactionId: &txID,
TransactionId: txID,
ProfileVersion: lo.ToPtr(profileVersion),
},
}
Expand All @@ -2875,7 +2880,7 @@ func TestCredentialIssuanceHistory(t *testing.T) {

t.Run("credentialIssuanceHistoryStore error", func(t *testing.T) {
credentialIssuanceStore.EXPECT().
GetIssuedCredentialsMetadata(gomock.Any(), profileID).
GetIssuedCredentialsMetadata(gomock.Any(), profileID, nil, nil).
Times(1).
Return(nil, errors.New("some error"))

Expand All @@ -2887,7 +2892,7 @@ func TestCredentialIssuanceHistory(t *testing.T) {

echoCtx := echoContext(withRecorder(recorder))

err := c.CredentialIssuanceHistory(echoCtx, profileID)
err := c.CredentialIssuanceHistory(echoCtx, profileID, CredentialIssuanceHistoryParams{})
assert.Error(t, err)
})
}
Expand Down
79 changes: 70 additions & 9 deletions pkg/restapi/v1/issuer/openapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9a622cf

Please sign in to comment.