Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add deeplink and universal link to getlinks endpoint #786

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/api/links.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *Server) GetLinks(ctx context.Context, request GetLinksRequestObject) (G
return GetLinks400JSONResponse{N400JSONResponse{Message: "unknown request type. Allowed: all|active|inactive|exceed"}}, nil
}
}
links, err := s.linkService.GetAll(ctx, *issuerDID, status, request.Params.Query)
links, err := s.linkService.GetAll(ctx, *issuerDID, status, request.Params.Query, s.cfg.ServerUrl)
if err != nil {
log.Error(ctx, "getting links", "err", err, "req", request)
}
Expand Down Expand Up @@ -162,7 +162,7 @@ func (s *Server) GetLink(ctx context.Context, request GetLinkRequestObject) (Get
log.Error(ctx, "obtaining a link", "err", err.Error(), "id", request.Id)
return GetLink500JSONResponse{N500JSONResponse{Message: "error getting link"}}, nil
}
return GetLink200JSONResponse(getLinkResponse(*link)), nil
return GetLink200JSONResponse(getLinkResponse(link)), nil
}

// ActivateLink - Activates or deactivates a link
Expand Down
8 changes: 4 additions & 4 deletions internal/api/links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func TestServer_GetAllLinks(t *testing.T) {
},
)
require.NoError(t, err)
linkActive := getLinkResponse(*link1)
linkActive := getLinkResponse(link1)

time.Sleep(10 * time.Millisecond)

Expand All @@ -560,15 +560,15 @@ func TestServer_GetAllLinks(t *testing.T) {
},
)
require.NoError(t, err)
linkExpired := getLinkResponse(*link2)
linkExpired := getLinkResponse(link2)
require.NoError(t, err)
time.Sleep(10 * time.Millisecond)

link3, err := server.Services.links.Save(ctx, *did, common.ToPointer(10), &yesterday, importedSchema.ID, &tomorrow, true, true, domain.CredentialSubject{"birthday": 19791109, "documentType": 12}, nil, nil)
link3.Active = false
require.NoError(t, err)
require.NoError(t, server.Services.links.Activate(ctx, *did, link3.ID, false))
linkInactive := getLinkResponse(*link3)
linkInactive := getLinkResponse(link3)
require.NoError(t, err)
time.Sleep(10 * time.Millisecond)

Expand Down Expand Up @@ -939,7 +939,7 @@ func TestServer_CreateLinkQRCode(t *testing.T) {

handler := getHandler(ctx, server)

linkDetail := getLinkResponse(*link)
linkDetail := getLinkResponse(link)

type expected struct {
linkDetail Link
Expand Down
6 changes: 3 additions & 3 deletions internal/api/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ func (response CustomQrContentResponse) visit(w http.ResponseWriter) error {
return err
}

func getLinkResponses(links []domain.Link) []Link {
func getLinkResponses(links []*domain.Link) []Link {
res := make([]Link, len(links))
for i, link := range links {
res[i] = getLinkResponse(link)
}
return res
}

func getLinkResponse(link domain.Link) Link {
func getLinkResponse(link *domain.Link) Link {
hash, _ := link.Schema.Hash.MarshalText()
var credentialExpiration *timeapi.Time
if link.CredentialExpiration != nil {
Expand Down Expand Up @@ -84,7 +84,7 @@ func getLinkResponse(link domain.Link) Link {
SchemaUrl: link.Schema.URL,
SchemaHash: string(hash),
Status: LinkStatus(link.Status()),
ProofTypes: getLinkProofs(link),
ProofTypes: getLinkProofs(*link),
CreatedAt: TimeUTC(link.CreatedAt),
Expiration: validUntil,
CredentialExpiration: credentialExpiration,
Expand Down
2 changes: 1 addition & 1 deletion internal/core/ports/link_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type LinkRepository interface {
Save(ctx context.Context, conn db.Querier, link *domain.Link) (*uuid.UUID, error)
GetByID(ctx context.Context, issuerID w3c.DID, id uuid.UUID) (*domain.Link, error)
GetAll(ctx context.Context, issuerDID w3c.DID, status LinkStatus, query *string) ([]domain.Link, error)
GetAll(ctx context.Context, issuerDID w3c.DID, status LinkStatus, query *string) ([]*domain.Link, error)
Delete(ctx context.Context, id uuid.UUID, issuerDID w3c.DID) error
AddAuthorizationRequest(ctx context.Context, linkID uuid.UUID, issuerDID w3c.DID, authorizationRequest *protocol.AuthorizationRequestMessage) error
}
2 changes: 1 addition & 1 deletion internal/core/ports/link_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type LinkService interface {
Activate(ctx context.Context, issuerID w3c.DID, linkID uuid.UUID, active bool) error
Delete(ctx context.Context, id uuid.UUID, did w3c.DID) error
GetByID(ctx context.Context, issuerID w3c.DID, id uuid.UUID, serverURL string) (*domain.Link, error)
GetAll(ctx context.Context, issuerDID w3c.DID, status LinkStatus, query *string) ([]domain.Link, error)
GetAll(ctx context.Context, issuerDID w3c.DID, status LinkStatus, query *string, serverURL string) ([]*domain.Link, error)
CreateQRCode(ctx context.Context, issuerDID w3c.DID, linkID uuid.UUID, serverURL string) (*CreateQRCodeResponse, error)
IssueOrFetchClaim(ctx context.Context, issuerDID w3c.DID, userDID w3c.DID, linkID uuid.UUID, hostURL string) (*protocol.CredentialsOfferMessage, error)
ProcessCallBack(ctx context.Context, issuerDID w3c.DID, message string, linkID uuid.UUID, hostURL string) (*protocol.CredentialsOfferMessage, error)
Expand Down
25 changes: 18 additions & 7 deletions internal/core/services/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,28 @@ func (ls *Link) GetByID(ctx context.Context, issuerID w3c.DID, id uuid.UUID, ser
return nil, err
}

if link.AuthorizationRequestMessage != nil {
link.DeepLink = common.ToPointer(ls.qrService.ToDeepLink(serverURL, id, &issuerID))
link.UniversalLink = common.ToPointer(ls.qrService.ToUniversalLink(ls.cfg.BaseUrl, ls.cfg.BaseUrl, link.ID, &issuerID))
}

ls.addLinksToLink(link, serverURL, issuerID)
return link, nil
}

// GetAll returns all links from issueDID of type lType filtered by query string
func (ls *Link) GetAll(ctx context.Context, issuerDID w3c.DID, status ports.LinkStatus, query *string) ([]domain.Link, error) {
return ls.linkRepository.GetAll(ctx, issuerDID, status, query)
func (ls *Link) GetAll(ctx context.Context, issuerDID w3c.DID, status ports.LinkStatus, query *string, serverURL string) ([]*domain.Link, error) {
links, err := ls.linkRepository.GetAll(ctx, issuerDID, status, query)
if err != nil {
return links, err
}

for _, link := range links {
ls.addLinksToLink(link, serverURL, issuerDID)
}
return links, nil
}

func (ls *Link) addLinksToLink(link *domain.Link, serverURL string, issuerDID w3c.DID) {
if link.AuthorizationRequestMessage != nil {
link.DeepLink = common.ToPointer(ls.qrService.ToDeepLink(serverURL, link.ID, &issuerDID))
link.UniversalLink = common.ToPointer(ls.qrService.ToUniversalLink(ls.cfg.BaseUrl, ls.cfg.BaseUrl, link.ID, &issuerDID))
}
}

// Delete - delete a link by id
Expand Down
9 changes: 6 additions & 3 deletions internal/repositories/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ GROUP BY links.id, schemas.id
return &link, err
}

func (l link) GetAll(ctx context.Context, issuerDID w3c.DID, status ports.LinkStatus, query *string) ([]domain.Link, error) {
func (l link) GetAll(ctx context.Context, issuerDID w3c.DID, status ports.LinkStatus, query *string) ([]*domain.Link, error) {
sql := `
SELECT links.id,
links.issuer_id,
Expand All @@ -152,6 +152,7 @@ SELECT links.id,
links.active,
links.refresh_service,
links.display_method,
links.authorization_request_message,
count(claims.id) as issued_claims,
schemas.id as schema_id,
schemas.issuer_id as schema_issuer_id,
Expand Down Expand Up @@ -198,10 +199,11 @@ WHERE links.issuer_id = $1
defer rows.Close()

schema := dbSchema{}
link := domain.Link{}
links := make([]domain.Link, 0)
var link *domain.Link
links := make([]*domain.Link, 0)
var credentialAttributes pgtype.JSONB
for rows.Next() {
link = &domain.Link{}
if err := rows.Scan(
&link.ID,
&link.IssuerDID,
Expand All @@ -215,6 +217,7 @@ WHERE links.issuer_id = $1
&link.Active,
&link.RefreshService,
&link.DisplayMethod,
&link.AuthorizationRequestMessage,
&link.IssuedClaims,
&schema.ID,
&schema.IssuerID,
Expand Down
Loading