Skip to content
Closed
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
20 changes: 20 additions & 0 deletions acceptance/claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@ var _ = Describe("Claim model tests", func() {
sampleClaim2,
))
})

It("should return all claims for the given source digest", func() {
sourceClaimsUrl, err := url.JoinPath(baseUrl, "/api/v1/source", uriDigest3, "claims")
Expect(err).To(BeNil())

resp, err := doRequest(http.MethodGet, sourceClaimsUrl, nil)
Expect(err).To(BeNil())
defer resp.Body.Close()
Expect(resp.StatusCode).To(Equal(http.StatusOK))

var claims []api.Claim
err = json.NewDecoder(resp.Body).Decode(&claims)
Expect(err).To(BeNil())
Expect(len(claims)).To(BeNumerically(">=", 2))

Expect(claims).To(ContainElements(
sampleClaim1,
sampleClaim2,
))
})
})

When("GET request is sent to retrieve a single claim by digest", func() {
Expand Down
18 changes: 16 additions & 2 deletions acceptance/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ var _ = Describe("Proof model tests", func() {
Expect(p.UriDigest).To(Equal(proof1Digest))
Expect(p).To(Equal(sampleProof1))
})

It("should return all proofs for the given claim digest", func() {
claimProofsUrl, err := url.JoinPath(baseUrl, "/api/v1/claim", claim3Digest, "proofs")
Expect(err).To(BeNil())

resp, err := doRequest(http.MethodGet, claimProofsUrl, nil)
Expect(err).To(BeNil())
defer resp.Body.Close()
Expect(resp.StatusCode).To(Equal(http.StatusOK))

var proofs []api.Proof
err = json.NewDecoder(resp.Body).Decode(&proofs)
Expect(err).To(BeNil())
Expect(len(proofs)).To(BeNumerically(">=", 2))
Expect(proofs).To(ContainElements(sampleProof1, sampleProof2))
})
})

When("PATCH request is sent to update a proof", func() {
Expand Down Expand Up @@ -180,7 +196,6 @@ var _ = Describe("Proof model tests", func() {
Expect(err).To(BeNil())
addCommonHeaders(req)


resp, err := client.Do(req)
Expect(err).To(BeNil())
defer resp.Body.Close()
Expand Down Expand Up @@ -329,7 +344,6 @@ var _ = Describe("Proof model tests", func() {
Expect(err).To(BeNil())
addCommonHeaders(req)


resp, err := client.Do(req)
Expect(err).To(BeNil())
defer resp.Body.Close()
Expand Down
50 changes: 50 additions & 0 deletions api/source-score.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,31 @@ paths:
404:
description: Source not found

/api/v1/source/{uriDigest}/claims:
get:
summary: Get all the claims made by a source
description: Retrieves a list of all the claims made by a given source
tags:
- claims
- source
operationId: getClaimsBySourceDigest
parameters:
- in: path
name: uriDigest
required: true
description: SHA-256 hash of the source URI
schema:
type: string
responses:
200:
description: List of claims retrieved successfully
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Claim'

/api/v1/claims:
get:
summary: Get all claims
Expand Down Expand Up @@ -285,6 +310,31 @@ paths:
404:
description: Claim not found

/api/v1/claim/{uriDigest}/proofs:
get:
summary: Get all the proofs provided for a claim
description: Retrieves a list of all the proofs stored for a given claim
tags:
- proofs
- claim
operationId: getProofsByClaimDigest
parameters:
- in: path
name: uriDigest
required: true
description: SHA-256 hash of the claim URI
schema:
type: string
responses:
200:
description: List of proofs retrieved successfully
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Proof'

/api/v1/proofs:
get:
summary: Get all proofs
Expand Down
60 changes: 60 additions & 0 deletions pkg/api/server.gen.go

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

13 changes: 13 additions & 0 deletions pkg/domain/claim/claim_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type ClaimRepository interface {
VerifyClaimByUriDigest(ctx context.Context, claimVerification *api.ClaimVerification, uriDigest string) error
VerifyAllClaims(ctx context.Context, updatedClaims []api.Claim) error
GetCheckedClaimsBySources(ctx context.Context) (map[string][]api.Claim, error)
GetClaimsBySourceDigest(ctx context.Context, sourceDigest string) ([]api.Claim, error)
}

type claimRepository struct {
Expand Down Expand Up @@ -179,3 +180,15 @@ func (cr *claimRepository) GetCheckedClaimsBySources(ctx context.Context) (map[s

return srcsClaims, nil
}

func (cr *claimRepository) GetClaimsBySourceDigest(ctx context.Context, sourceDigest string) ([]api.Claim, error) {
var claims []api.Claim
result := cr.client.DB.WithContext(ctx).Where("source_uri_digest = ?", sourceDigest).Find(&claims)

if result.Error != nil {
return nil, result.Error
}
slog.InfoContext(ctx, fmt.Sprintf("returned %d claims", len(claims)))

return claims, nil
}
13 changes: 13 additions & 0 deletions pkg/domain/claim/claim_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ var _ = Describe("Claim repository layer unit tests", func() {
})
})

When("Retrieving claims by source uri digest", func() {
It("Should return all claims associated with the source digest", func() {
claims, err := claimRepo.GetClaimsBySourceDigest(context.TODO(), sampleSource.UriDigest)
Expect(err).ToNot(HaveOccurred())
Expect(len(claims)).To(Equal(2))

Expect(claims).To(ContainElements(
sampleClaim1,
sampleClaim2,
))
})
})

When("Patching a claim by its uri digest", func() {
It("Should update the correct claim record in the DB", func() {
newSummary := "Updated claim summary"
Expand Down
5 changes: 5 additions & 0 deletions pkg/domain/claim/claim_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ClaimService interface {
PatchClaimByUriDigest(ctx context.Context, claimInput *api.ClaimPatchInput, uriDigest string) error
VerifyClaimByUriDigest(ctx context.Context, claimVerification *api.ClaimVerification, uriDigest string) error
VerifyAllClaims(ctx context.Context) error
GetClaimsBySourceDigest(ctx context.Context, sourceDigest string) ([]api.Claim, error)
}

type claimService struct {
Expand Down Expand Up @@ -187,3 +188,7 @@ func (svc *claimService) VerifyAllClaims(ctx context.Context) error {

return nil
}

func (svc *claimService) GetClaimsBySourceDigest(ctx context.Context, digest string) ([]api.Claim, error) {
return svc.claimRepo.GetClaimsBySourceDigest(ctx, digest)
}
15 changes: 15 additions & 0 deletions pkg/domain/claim/claim_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ var _ = Describe("Claim model service layer unit tests", Ordered, func() {
})
})

When("Retrieving claims by source uri digest", func() {
It("Should return all claims associated with the source digest", func() {
expected := []api.Claim{sampleClaim1, sampleClaim2}
fakeClaimRepo.GetClaimsBySourceDigestReturnsOnCall(0, expected, nil)

claims, err := claimSvc.GetClaimsBySourceDigest(context.TODO(), sampleSource.UriDigest)
Expect(err).ToNot(HaveOccurred())
Expect(len(claims)).To(Equal(2))
Expect(claims).To(ContainElements(expected))
Expect(fakeClaimRepo.GetClaimsBySourceDigestCallCount()).To(Equal(1))
_, arg := fakeClaimRepo.GetClaimsBySourceDigestArgsForCall(0)
Expect(arg).To(Equal(sampleSource.UriDigest))
})
})

When("Deleting a claim by its uri digest", func() {
It("Should delete the correct claim record via repository", func() {
fakeClaimRepo.GetClaimByUriDigestReturnsOnCall(1, &sampleClaim1, nil)
Expand Down
Loading
Loading