Skip to content

Commit

Permalink
fix paths
Browse files Browse the repository at this point in the history
  • Loading branch information
freigeistig committed Jan 12, 2024
1 parent 93d2b3c commit 9160956
Show file tree
Hide file tree
Showing 21 changed files with 233 additions and 195 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
allOf:
- $ref: '#/components/schemas/ProofKey'
- $ref: '#/components/schemas/LinkKey'
- type: object
required:
- attributes
Expand Down
12 changes: 12 additions & 0 deletions docs/spec/components/schemas/LinkKey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type: object
required:
- id
- type
properties:
id:
type: string
example: "550e8400-e29b-41d4-a716-446655440000"
type:
type: string
enum:
- links
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,48 @@ post:
data:
type: object
$ref: '#/components/schemas/ProofLink'

400:
$ref: '#/components/responses/invalidParameter'
401:
$ref: '#/components/responses/invalidAuth'
500:
$ref: '#/components/responses/internalError'

get:
summary: Get Proofs Links by User DID
description: >
Returns information about the all links of the user.
operationId: proofsLinksByUserDID
security:
- Bearer: [ ]
tags:
- Proofs
parameters:
- in: path
name: 'did'
required: true
description: The User DID
schema:
type: string
example: "did:iden3:readonly:tM1QCJ7ytcbvLB7EFQhGsJPumc11DEE18gEvAzxE7"
responses:
'200':
description: OK
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
type: array
items:
$ref: '#/components/schemas/ProofLink'

400:
$ref: '#/components/responses/invalidParameter'
404:
$ref: '#/components/responses/notFound'
500:
$ref: '#/components/responses/internalError'
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ get:
type: array
items:
$ref: '#/components/schemas/Proof'

400:
$ref: '#/components/responses/invalidParameter'
404:
Expand Down
38 changes: 38 additions & 0 deletions docs/spec/paths/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,41 @@ post:
500:
$ref: '#/components/responses/internalError'

get:
summary: Get Proofs by User DID
description: >
Returns information about the all proofs of the user.
operationId: proofByUserDID
security:
- Bearer: [ ]
tags:
- Proofs
parameters:
- in: query
name: 'did'
required: true
description: The User DID
schema:
type: string
example: "did:iden3:readonly:tM1QCJ7ytcbvLB7EFQhGsJPumc11DEE18gEvAzxE7"
responses:
'200':
description: OK
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
type: array
items:
$ref: '#/components/schemas/Proof'
400:
$ref: '#/components/responses/invalidParameter'
404:
$ref: '#/components/responses/notFound'
500:
$ref: '#/components/responses/internalError'

38 changes: 0 additions & 38 deletions docs/spec/paths/v1@proofs@user@{user_did}.yaml

This file was deleted.

38 changes: 0 additions & 38 deletions docs/spec/paths/v1@proofs@user@{user_did}@link.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/rarimo/rarime-link-svc
go 1.20

require (
github.com/Masterminds/squirrel v1.4.0
github.com/alecthomas/kingpin v2.2.6+incompatible
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-ozzo/ozzo-validation/v4 v4.2.1
Expand All @@ -14,11 +15,11 @@ require (
gitlab.com/distributed_lab/kit v1.11.2
gitlab.com/distributed_lab/logan v3.8.1+incompatible
gitlab.com/distributed_lab/running v0.0.0-20200706131153-4af0e83eb96c
gitlab.com/distributed_lab/urlval v3.0.0+incompatible
gitlab.com/tokend/keypair v0.0.0-20190412110653-b9d7e0c8b312
)

require (
github.com/Masterminds/squirrel v1.4.0 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9 // indirect
github.com/certifi/gocertifi v0.0.0-20200211180108-c7c1fbc02894 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ gitlab.com/distributed_lab/lorem v0.2.0 h1:Rc7Ef3eGSpei8EtWcV6fzPW3O/QEF2zgZR4+h
gitlab.com/distributed_lab/lorem v0.2.0/go.mod h1:wkzrGoB1L/yUBu56SfoJ/vNiPqiHZcg75AnBkWNcjhQ=
gitlab.com/distributed_lab/running v0.0.0-20200706131153-4af0e83eb96c h1:cpIjV8C//7sLVvMcBaFGopI8sMcCw8Za7T0HIf52esU=
gitlab.com/distributed_lab/running v0.0.0-20200706131153-4af0e83eb96c/go.mod h1:4TnADX84dQjQMRHKIMPCVL0L97rD/Jxv0xDbrN6aKzk=
gitlab.com/distributed_lab/urlval v3.0.0+incompatible h1:OWU3CcZU+z0BVooufOSQFO9biDfsjM3e7YYauC278HU=
gitlab.com/distributed_lab/urlval v3.0.0+incompatible/go.mod h1:cKnUlnZCHUuke/l95YLvW5JoGC2yn53HVgF9rt1WiIg=
gitlab.com/tokend/keypair v0.0.0-20190412110653-b9d7e0c8b312 h1:u8pxrNw8QKIsrmClG71uuTPy22fkePAXBkHgxrXkMU8=
gitlab.com/tokend/keypair v0.0.0-20190412110653-b9d7e0c8b312/go.mod h1:vdlhN5/oQR7uY8EsGSqPf8bwnmQxxpaq7qrQn5Y3U/w=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down Expand Up @@ -288,4 +290,3 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion internal/data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ProofQ interface {
Update(p *Proof) error
Upsert(p *Proof) error
Delete(p *Proof) error
ProofsByUserDIDCtx(ctx context.Context, userDID string) ([]Proof, error)
ProofsByCreatorCtx(ctx context.Context, userDID string) ([]Proof, error)
}

type LinkQ interface {
Expand Down
4 changes: 2 additions & 2 deletions internal/data/pg/proof_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func (q ProofQ) SelectAllCtx(ctx context.Context) ([]*data.Proof, error) {
return proofs, nil
}

func (q ProofQ) ProofsByUserDIDCtx(ctx context.Context, userDID string) ([]data.Proof, error) {
stmt := squirrel.Select("*").From("public.proofs").Where(squirrel.Eq{"user_did": userDID})
func (q ProofQ) ProofsByCreatorCtx(ctx context.Context, userDID string) ([]data.Proof, error) {
stmt := squirrel.Select("*").From("public.proofs").Where(squirrel.Eq{"creator": userDID})

var proofs []data.Proof

Expand Down
2 changes: 2 additions & 0 deletions internal/services/api/handlers/create_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ 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 Down
8 changes: 4 additions & 4 deletions internal/services/api/handlers/create_proof_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ func CreateProofLink(w http.ResponseWriter, r *http.Request) {
return
}

ape.Render(w, resources.ProofLinkResponse{
Data: resources.ProofLink{
ape.Render(w, resources.LinkResponse{
Data: resources.Link{
Key: resources.Key{
Type: resources.PROOFS,
Type: resources.LINKS,
},
Attributes: resources.ProofLinkAttributes{
Attributes: resources.LinkAttributes{
Link: linkID.String(),
CreatedAt: timestamp.String(),
},
Expand Down
33 changes: 15 additions & 18 deletions internal/services/api/handlers/get_links_by_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package handlers

import (
"context"
"github.com/go-chi/chi"
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/logan/v3/errors"
"gitlab.com/distributed_lab/urlval"
"net/http"
"strconv"
)
Expand All @@ -16,19 +15,20 @@ type proofsLinksByUserDIDRequest struct {
UserDid string
}

func newProofLinkByUserDIDRequest(r *http.Request) (proofsLinksByUserDIDRequest, error) {
userDid := chi.URLParam(r, "user_did")
if userDid == "" {
return proofsLinksByUserDIDRequest{}, errors.New("user_did is required")
func newGetLinksRequest(r *http.Request) (proofsLinksByUserDIDRequest, error) {
request := proofsLinksByUserDIDRequest{}
if err := urlval.DecodeSilently(r.URL.Query(), &request); err != nil {
return request, err
}
request.UserDid = r.URL.Query().Get("filter[did]")

return proofsLinksByUserDIDRequest{userDid}, validation.Errors{
"user_did": validation.Validate(userDid, validation.Required),
return proofsLinksByUserDIDRequest{request.UserDid}, validation.Errors{
"did": validation.Validate(request.UserDid, validation.Required),
}.Filter()
}

func ProofsLinkByUserDID(w http.ResponseWriter, r *http.Request) {
req, err := newProofLinkByUserDIDRequest(r)
func GetLinks(w http.ResponseWriter, r *http.Request) {
req, err := newGetLinksRequest(r)
if err != nil {
ape.RenderErr(w, problems.BadRequest(err)...)
return
Expand All @@ -40,29 +40,26 @@ func ProofsLinkByUserDID(w http.ResponseWriter, r *http.Request) {
ape.RenderErr(w, problems.InternalError())
return
}

if proofsLinks == nil {
Log(r).WithField("user_did", req.UserDid).Warn("proofs not found")
ape.RenderErr(w, problems.NotFound())
return
}

var response resources.ProofLinkListResponse

var response resources.LinkListResponse
for _, link := range proofsLinks {
linkResponse := resources.ProofLinkResponse{
Data: resources.ProofLink{
linkResponse := resources.LinkResponse{
Data: resources.Link{
Key: resources.Key{
ID: link.ID.String(),
Type: resources.PROOFS,
Type: resources.LINKS,
},
Attributes: resources.ProofLinkAttributes{
Attributes: resources.LinkAttributes{
CreatedAt: strconv.FormatInt(link.CreatedAt.Unix(), 10),
Link: link.ID.String(),
},
},
}

response.Data = append(response.Data, linkResponse.Data)
}

Expand Down
Loading

0 comments on commit 9160956

Please sign in to comment.