Skip to content

Commit

Permalink
add org id to proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
freigeistig committed Jan 10, 2024
1 parent ffa1e90 commit c3657e7
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 28 deletions.
8 changes: 6 additions & 2 deletions docs/spec/components/schemas/Proof.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ allOf:
- creator
- created_at
- proof
- type
- proof_type
- org_id
properties:
creator:
type: string
Expand All @@ -23,6 +24,9 @@ allOf:
type: string
description: The proof object in JSON string format
example: "{\"pub_signals\":[...],\"proof\":{\"pi_a\":[...],\"pi_b\":[],\"pi_c\":[...]}}"
type:
proof_type:
type: string
description: The type of the proof
org_id:
type: string
description: The ID of the organization that issued the proof's claim
8 changes: 6 additions & 2 deletions docs/spec/components/schemas/ProofCreate.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
type: object
required:
- proof
- type
- proof_type
- org_id
properties:
proof:
type: string
description: The proof object in JSON string format
example: "{\"pub_signals\":[...],\"proof\":{\"pi_a\":[...],\"pi_b\":[],\"pi_c\":[...]}}"
type:
proof_type:
type: string
description: The type of the proof
org_id:
type: string
description: The ID of the organization that issued the proof's claim
1 change: 1 addition & 0 deletions internal/assets/migrations/001_initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ create table if not exists proofs(
creator text not null,
created_at timestamp without time zone not null default now(),
proof jsonb not null,
org_id uuid not null,
type text not null
);

Expand Down
1 change: 1 addition & 0 deletions internal/data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package data

import (
"context"

"github.com/google/uuid"
)

Expand Down
1 change: 1 addition & 0 deletions internal/data/pg/link_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pg

import (
"context"

"github.com/Masterminds/squirrel"
"github.com/rarimo/rarime-link-svc/internal/data"
)
Expand Down
1 change: 1 addition & 0 deletions internal/data/pg/links_to_proofs_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pg

import (
"context"

"github.com/Masterminds/squirrel"
"github.com/google/uuid"
"github.com/rarimo/rarime-link-svc/internal/data"
Expand Down
1 change: 1 addition & 0 deletions internal/data/pg/proof_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pg

import (
"context"

"github.com/Masterminds/squirrel"
"github.com/rarimo/rarime-link-svc/internal/data"
)
Expand Down
24 changes: 12 additions & 12 deletions internal/data/pg/schema.xo.go

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

1 change: 1 addition & 0 deletions internal/data/schema.xo.go

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

14 changes: 11 additions & 3 deletions internal/services/api/handlers/create_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func newProofCreateRequest(r *http.Request) (*proofCreateRequest, error) {
}
}

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

orgID, err := uuid.Parse(req.Data.OrgId)
if err != nil {
ape.RenderErr(w, problems.BadRequest(err)...)
return
}

proof := data.Proof{
ID: uuid.New(),
Creator: UserID(r),
CreatedAt: time.Now().UTC(),
Proof: []byte(req.Data.Proof),
Type: req.Data.Type,
Type: req.Data.ProofType,
OrgID: orgID,
}

err = Storage(r).ProofQ().Insert(&proof)
Expand All @@ -72,7 +79,8 @@ func CreateProof(w http.ResponseWriter, r *http.Request) {
CreatedAt: strconv.FormatInt(proof.CreatedAt.Unix(), 10),
Creator: proof.Creator,
Proof: string(proof.Proof),
Type: proof.Type,
ProofType: proof.Type,
OrgId: proof.OrgID.String(),
},
},
Included: resources.Included{},
Expand Down
3 changes: 2 additions & 1 deletion internal/services/api/handlers/get_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func ProofByID(w http.ResponseWriter, r *http.Request) {
CreatedAt: strconv.FormatInt(proof.CreatedAt.Unix(), 10),
Creator: proof.Creator,
Proof: string(proof.Proof),
Type: proof.Type,
ProofType: proof.Type,
OrgId: proof.OrgID.String(),
},
},
Included: resources.Included{},
Expand Down
11 changes: 6 additions & 5 deletions internal/services/api/handlers/get_proofs_by_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ func GetProofsByLinkID(w http.ResponseWriter, r *http.Request) {
return
}

proofs, err := Storage(r).LinksToProofQ().GetLinksToProofsByLinkID(r.Context(), req.LinkID)
links, err := Storage(r).LinksToProofQ().GetLinksToProofsByLinkID(r.Context(), req.LinkID)
if err != nil {
Log(r).WithError(err).Error("failed to get link to proofs")
ape.RenderErr(w, problems.InternalError())
return
}

if proofs == nil {
if links == nil {
Log(r).WithField("link_id", req.LinkID).Warn("link not found")
ape.RenderErr(w, problems.NotFound())
return
}

var response resources.ProofListResponse
for _, proof := range proofs {
proof, err := Storage(r).ProofQ().ProofByID(proof.ProofID, false)
for _, link := range links {
proof, err := Storage(r).ProofQ().ProofByID(link.ProofID, false)
if err != nil {
Log(r).WithError(err).Error("failed to get proof")
ape.RenderErr(w, problems.InternalError())
Expand All @@ -66,7 +66,8 @@ func GetProofsByLinkID(w http.ResponseWriter, r *http.Request) {
CreatedAt: proof.CreatedAt.String(),
Creator: proof.Creator,
Proof: string(proof.Proof),
Type: proof.Type,
ProofType: proof.Type,
OrgId: proof.OrgID.String(),
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion internal/services/api/handlers/get_proofs_by_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func GetProofsByUserDID(w http.ResponseWriter, r *http.Request) {
CreatedAt: strconv.FormatInt(proof.CreatedAt.Unix(), 10),
Creator: proof.Creator,
Proof: string(proof.Proof),
Type: proof.Type,
ProofType: proof.Type,
OrgId: proof.OrgID.String(),
},
},
}
Expand Down
4 changes: 3 additions & 1 deletion resources/model_proof_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ type ProofAttributes struct {
CreatedAt string `json:"created_at"`
// The ID of the user who created the proof
Creator string `json:"creator"`
// The ID of the organization that issued the proof's claim
OrgId string `json:"org_id"`
// The proof object in JSON string format
Proof string `json:"proof"`
// The type of the proof
Type string `json:"type"`
ProofType string `json:"proof_type"`
}
4 changes: 3 additions & 1 deletion resources/model_proof_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
package resources

type ProofCreate struct {
// The ID of the organization that issued the proof's claim
OrgId string `json:"org_id"`
// The proof object in JSON string format
Proof string `json:"proof"`
// The type of the proof
Type string `json:"type"`
ProofType string `json:"proof_type"`
}

0 comments on commit c3657e7

Please sign in to comment.