Skip to content

Commit 93d2b3c

Browse files
authored
Merge pull request #5 from rarimo/feature/org-id
add org id to proofs
2 parents ffa1e90 + c3657e7 commit 93d2b3c

File tree

15 files changed

+57
-28
lines changed

15 files changed

+57
-28
lines changed

docs/spec/components/schemas/Proof.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ allOf:
1010
- creator
1111
- created_at
1212
- proof
13-
- type
13+
- proof_type
14+
- org_id
1415
properties:
1516
creator:
1617
type: string
@@ -23,6 +24,9 @@ allOf:
2324
type: string
2425
description: The proof object in JSON string format
2526
example: "{\"pub_signals\":[...],\"proof\":{\"pi_a\":[...],\"pi_b\":[],\"pi_c\":[...]}}"
26-
type:
27+
proof_type:
2728
type: string
2829
description: The type of the proof
30+
org_id:
31+
type: string
32+
description: The ID of the organization that issued the proof's claim
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
type: object
22
required:
33
- proof
4-
- type
4+
- proof_type
5+
- org_id
56
properties:
67
proof:
78
type: string
89
description: The proof object in JSON string format
910
example: "{\"pub_signals\":[...],\"proof\":{\"pi_a\":[...],\"pi_b\":[],\"pi_c\":[...]}}"
10-
type:
11+
proof_type:
1112
type: string
1213
description: The type of the proof
14+
org_id:
15+
type: string
16+
description: The ID of the organization that issued the proof's claim

internal/assets/migrations/001_initial.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ create table if not exists proofs(
44
creator text not null,
55
created_at timestamp without time zone not null default now(),
66
proof jsonb not null,
7+
org_id uuid not null,
78
type text not null
89
);
910

internal/data/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package data
22

33
import (
44
"context"
5+
56
"github.com/google/uuid"
67
)
78

internal/data/pg/link_schemas.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pg
22

33
import (
44
"context"
5+
56
"github.com/Masterminds/squirrel"
67
"github.com/rarimo/rarime-link-svc/internal/data"
78
)

internal/data/pg/links_to_proofs_schemas.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pg
22

33
import (
44
"context"
5+
56
"github.com/Masterminds/squirrel"
67
"github.com/google/uuid"
78
"github.com/rarimo/rarime-link-svc/internal/data"

internal/data/pg/proof_schemas.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pg
22

33
import (
44
"context"
5+
56
"github.com/Masterminds/squirrel"
67
"github.com/rarimo/rarime-link-svc/internal/data"
78
)

internal/data/pg/schema.xo.go

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/data/schema.xo.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/services/api/handlers/create_proof.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func newProofCreateRequest(r *http.Request) (*proofCreateRequest, error) {
3131
}
3232
}
3333

34-
if req.Data.Type == "" {
34+
if req.Data.ProofType == "" {
3535
return nil, validation.Errors{
3636
"type": errors.New("type is required"),
3737
}
@@ -47,12 +47,19 @@ func CreateProof(w http.ResponseWriter, r *http.Request) {
4747
return
4848
}
4949

50+
orgID, err := uuid.Parse(req.Data.OrgId)
51+
if err != nil {
52+
ape.RenderErr(w, problems.BadRequest(err)...)
53+
return
54+
}
55+
5056
proof := data.Proof{
5157
ID: uuid.New(),
5258
Creator: UserID(r),
5359
CreatedAt: time.Now().UTC(),
5460
Proof: []byte(req.Data.Proof),
55-
Type: req.Data.Type,
61+
Type: req.Data.ProofType,
62+
OrgID: orgID,
5663
}
5764

5865
err = Storage(r).ProofQ().Insert(&proof)
@@ -72,7 +79,8 @@ func CreateProof(w http.ResponseWriter, r *http.Request) {
7279
CreatedAt: strconv.FormatInt(proof.CreatedAt.Unix(), 10),
7380
Creator: proof.Creator,
7481
Proof: string(proof.Proof),
75-
Type: proof.Type,
82+
ProofType: proof.Type,
83+
OrgId: proof.OrgID.String(),
7684
},
7785
},
7886
Included: resources.Included{},

internal/services/api/handlers/get_proof.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ func ProofByID(w http.ResponseWriter, r *http.Request) {
5757
CreatedAt: strconv.FormatInt(proof.CreatedAt.Unix(), 10),
5858
Creator: proof.Creator,
5959
Proof: string(proof.Proof),
60-
Type: proof.Type,
60+
ProofType: proof.Type,
61+
OrgId: proof.OrgID.String(),
6162
},
6263
},
6364
Included: resources.Included{},

internal/services/api/handlers/get_proofs_by_link.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@ func GetProofsByLinkID(w http.ResponseWriter, r *http.Request) {
3535
return
3636
}
3737

38-
proofs, err := Storage(r).LinksToProofQ().GetLinksToProofsByLinkID(r.Context(), req.LinkID)
38+
links, err := Storage(r).LinksToProofQ().GetLinksToProofsByLinkID(r.Context(), req.LinkID)
3939
if err != nil {
4040
Log(r).WithError(err).Error("failed to get link to proofs")
4141
ape.RenderErr(w, problems.InternalError())
4242
return
4343
}
4444

45-
if proofs == nil {
45+
if links == nil {
4646
Log(r).WithField("link_id", req.LinkID).Warn("link not found")
4747
ape.RenderErr(w, problems.NotFound())
4848
return
4949
}
5050

5151
var response resources.ProofListResponse
52-
for _, proof := range proofs {
53-
proof, err := Storage(r).ProofQ().ProofByID(proof.ProofID, false)
52+
for _, link := range links {
53+
proof, err := Storage(r).ProofQ().ProofByID(link.ProofID, false)
5454
if err != nil {
5555
Log(r).WithError(err).Error("failed to get proof")
5656
ape.RenderErr(w, problems.InternalError())
@@ -66,7 +66,8 @@ func GetProofsByLinkID(w http.ResponseWriter, r *http.Request) {
6666
CreatedAt: proof.CreatedAt.String(),
6767
Creator: proof.Creator,
6868
Proof: string(proof.Proof),
69-
Type: proof.Type,
69+
ProofType: proof.Type,
70+
OrgId: proof.OrgID.String(),
7071
},
7172
},
7273
}

internal/services/api/handlers/get_proofs_by_user.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func GetProofsByUserDID(w http.ResponseWriter, r *http.Request) {
5959
CreatedAt: strconv.FormatInt(proof.CreatedAt.Unix(), 10),
6060
Creator: proof.Creator,
6161
Proof: string(proof.Proof),
62-
Type: proof.Type,
62+
ProofType: proof.Type,
63+
OrgId: proof.OrgID.String(),
6364
},
6465
},
6566
}

resources/model_proof_attributes.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ type ProofAttributes struct {
99
CreatedAt string `json:"created_at"`
1010
// The ID of the user who created the proof
1111
Creator string `json:"creator"`
12+
// The ID of the organization that issued the proof's claim
13+
OrgId string `json:"org_id"`
1214
// The proof object in JSON string format
1315
Proof string `json:"proof"`
1416
// The type of the proof
15-
Type string `json:"type"`
17+
ProofType string `json:"proof_type"`
1618
}

resources/model_proof_create.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
package resources
66

77
type ProofCreate struct {
8+
// The ID of the organization that issued the proof's claim
9+
OrgId string `json:"org_id"`
810
// The proof object in JSON string format
911
Proof string `json:"proof"`
1012
// The type of the proof
11-
Type string `json:"type"`
13+
ProofType string `json:"proof_type"`
1214
}

0 commit comments

Comments
 (0)