Skip to content

Commit

Permalink
add schema_url to proofs; fix time format
Browse files Browse the repository at this point in the history
  • Loading branch information
freigeistig committed Jan 12, 2024
1 parent 9160956 commit 228a9ca
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 39 deletions.
5 changes: 3 additions & 2 deletions docs/spec/components/schemas/Link.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ allOf:
example: '05260b49-2c35-48b9-8300-d39ae48ca312'
created_at:
type: string
description: The date and time when the proof was created in the timestamp format
example: '1702480643'
format: time.Time
description: The date and time when the proof was created in the RFC3339 format
example: "2021-08-12T12:00:00Z"
9 changes: 7 additions & 2 deletions docs/spec/components/schemas/Proof.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ allOf:
- proof
- proof_type
- org_id
- schema_url
properties:
creator:
type: string
description: The ID of the user who created the proof
created_at:
type: string
description: The date and time when the proof was created in the timestamp format
example: '1702480643'
format: time.Time
description: The date and time when the proof was created in the RFC3339 format
example: "2021-08-12T12:00:00Z"
proof:
type: string
description: The proof object in JSON string format
Expand All @@ -30,3 +32,6 @@ allOf:
org_id:
type: string
description: The ID of the organization that issued the proof's claim
schema_url:
type: string
description: The schema URL of the claim the proof was created based on
4 changes: 4 additions & 0 deletions docs/spec/components/schemas/ProofCreate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ required:
- proof
- proof_type
- org_id
- schema_url
properties:
proof:
type: string
Expand All @@ -14,3 +15,6 @@ properties:
org_id:
type: string
description: The ID of the organization that issued the proof's claim
schema_url:
type: string
description: The schema URL of the claim the proof was created based on
5 changes: 5 additions & 0 deletions internal/assets/migrations/002_proof_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- +migrate Up
alter table proofs add column schema_url text not null default '';

-- +migrate Down
alter table proofs drop column schema_url;
4 changes: 2 additions & 2 deletions internal/data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/google/uuid"
)

//go:generate xo schema "postgres://link:link@localhost:15432/link-db?sslmode=disable" -o ./ --single=schema.xo.go --src templates
//go:generate xo schema "postgres://link:link@localhost:15432/link-db?sslmode=disable" -o pg --single=schema.xo.go --src=pg/templates --go-context=both
//go:generate xo schema "postgres://link:link@localhost:25432/link-db?sslmode=disable" -o ./ --single=schema.xo.go --src templates
//go:generate xo schema "postgres://link:link@localhost:25432/link-db?sslmode=disable" -o pg --single=schema.xo.go --src=pg/templates --go-context=both
//go:generate goimports -w ./

type Storage interface {
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.

12 changes: 6 additions & 6 deletions internal/services/api/handlers/create_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package handlers

import (
"encoding/json"
"net/http"
"time"

validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/google/uuid"
"github.com/rarimo/rarime-link-svc/internal/data"
"github.com/rarimo/rarime-link-svc/resources"
"gitlab.com/distributed_lab/ape"
"gitlab.com/distributed_lab/ape/problems"
"gitlab.com/distributed_lab/logan/v3/errors"
"net/http"
"strconv"
"time"
)

type proofCreateRequest struct {
Expand Down Expand Up @@ -40,8 +40,6 @@ func newProofCreateRequest(r *http.Request) (*proofCreateRequest, error) {
return &req, nil
}

// TODO add schema_url; change time format

func CreateProof(w http.ResponseWriter, r *http.Request) {
req, err := newProofCreateRequest(r)
if err != nil {
Expand All @@ -62,6 +60,7 @@ func CreateProof(w http.ResponseWriter, r *http.Request) {
Proof: []byte(req.Data.Proof),
Type: req.Data.ProofType,
OrgID: orgID,
SchemaURL: req.Data.SchemaUrl,
}

err = Storage(r).ProofQ().Insert(&proof)
Expand All @@ -78,11 +77,12 @@ func CreateProof(w http.ResponseWriter, r *http.Request) {
Type: resources.PROOFS,
},
Attributes: resources.ProofAttributes{
CreatedAt: strconv.FormatInt(proof.CreatedAt.Unix(), 10),
CreatedAt: proof.CreatedAt,
Creator: proof.Creator,
Proof: string(proof.Proof),
ProofType: proof.Type,
OrgId: proof.OrgID.String(),
SchemaUrl: req.Data.SchemaUrl,
},
},
Included: resources.Included{},
Expand Down
2 changes: 1 addition & 1 deletion internal/services/api/handlers/create_proof_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func CreateProofLink(w http.ResponseWriter, r *http.Request) {
},
Attributes: resources.LinkAttributes{
Link: linkID.String(),
CreatedAt: timestamp.String(),
CreatedAt: timestamp,
},
},
Included: resources.Included{},
Expand Down
3 changes: 1 addition & 2 deletions internal/services/api/handlers/get_links_by_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"gitlab.com/distributed_lab/ape/problems"
"gitlab.com/distributed_lab/urlval"
"net/http"
"strconv"
)

type proofsLinksByUserDIDRequest struct {
Expand Down Expand Up @@ -55,7 +54,7 @@ func GetLinks(w http.ResponseWriter, r *http.Request) {
Type: resources.LINKS,
},
Attributes: resources.LinkAttributes{
CreatedAt: strconv.FormatInt(link.CreatedAt.Unix(), 10),
CreatedAt: link.CreatedAt,
Link: link.ID.String(),
},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/services/api/handlers/get_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"gitlab.com/distributed_lab/ape/problems"
"gitlab.com/distributed_lab/logan/v3/errors"
"net/http"
"strconv"
)

type proofByIDRequest struct {
Expand Down Expand Up @@ -54,11 +53,12 @@ func ProofByID(w http.ResponseWriter, r *http.Request) {
Type: resources.PROOFS,
},
Attributes: resources.ProofAttributes{
CreatedAt: strconv.FormatInt(proof.CreatedAt.Unix(), 10),
CreatedAt: proof.CreatedAt,
Creator: proof.Creator,
Proof: string(proof.Proof),
ProofType: proof.Type,
OrgId: proof.OrgID.String(),
SchemaUrl: proof.SchemaURL,
},
},
Included: resources.Included{},
Expand Down
5 changes: 3 additions & 2 deletions internal/services/api/handlers/get_proofs_by_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func GetLinkByID(w http.ResponseWriter, r *http.Request) {
Type: resources.LINKS,
},
Attributes: resources.LinkAttributes{
CreatedAt: link.CreatedAt.UTC().String(),
CreatedAt: link.CreatedAt,
Link: link.ID.String(),
},
},
Expand All @@ -86,11 +86,12 @@ func GetLinkByID(w http.ResponseWriter, r *http.Request) {
Type: resources.PROOFS,
},
Attributes: resources.ProofAttributes{
CreatedAt: proof.CreatedAt.String(),
CreatedAt: proof.CreatedAt,
Creator: proof.Creator,
Proof: string(proof.Proof),
ProofType: proof.Type,
OrgId: proof.OrgID.String(),
SchemaUrl: proof.SchemaURL,
},
})
}
Expand Down
7 changes: 3 additions & 4 deletions internal/services/api/handlers/get_proofs_by_user.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package handlers

import (
"net/http"
"strconv"

validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/rarimo/rarime-link-svc/resources"
"gitlab.com/distributed_lab/ape"
"gitlab.com/distributed_lab/ape/problems"
"gitlab.com/distributed_lab/urlval"
"net/http"
)

type proofsByUserDIDRequest struct {
Expand Down Expand Up @@ -57,11 +55,12 @@ func GetProofs(w http.ResponseWriter, r *http.Request) {
Type: resources.PROOFS,
},
Attributes: resources.ProofAttributes{
CreatedAt: strconv.FormatInt(proof.CreatedAt.Unix(), 10),
CreatedAt: proof.CreatedAt,
Creator: proof.Creator,
Proof: string(proof.Proof),
ProofType: proof.Type,
OrgId: proof.OrgID.String(),
SchemaUrl: proof.SchemaURL,
},
},
}
Expand Down
6 changes: 4 additions & 2 deletions resources/model_link_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

package resources

import "time"

type LinkAttributes struct {
// The date and time when the proof was created in the timestamp format
CreatedAt string `json:"created_at"`
// The date and time when the proof was created in the RFC3339 format
CreatedAt time.Time `json:"created_at"`
// UUID Link to proofs
Link string `json:"link"`
}
8 changes: 6 additions & 2 deletions resources/model_proof_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

package resources

import "time"

type ProofAttributes struct {
// The date and time when the proof was created in the timestamp format
CreatedAt string `json:"created_at"`
// The date and time when the proof was created in the RFC3339 format
CreatedAt time.Time `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
Expand All @@ -15,4 +17,6 @@ type ProofAttributes struct {
Proof string `json:"proof"`
// The type of the proof
ProofType string `json:"proof_type"`
// The schema URL of the claim the proof was created based on
SchemaUrl string `json:"schema_url"`
}
2 changes: 2 additions & 0 deletions resources/model_proof_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ type ProofCreate struct {
Proof string `json:"proof"`
// The type of the proof
ProofType string `json:"proof_type"`
// The schema URL of the claim the proof was created based on
SchemaUrl string `json:"schema_url"`
}

0 comments on commit 228a9ca

Please sign in to comment.