Skip to content

Commit 9160956

Browse files
committed
fix paths
1 parent 93d2b3c commit 9160956

21 files changed

+233
-195
lines changed

docs/spec/components/schemas/ProofLink.yaml renamed to docs/spec/components/schemas/Link.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
allOf:
2-
- $ref: '#/components/schemas/ProofKey'
2+
- $ref: '#/components/schemas/LinkKey'
33
- type: object
44
required:
55
- attributes
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
type: object
2+
required:
3+
- id
4+
- type
5+
properties:
6+
id:
7+
type: string
8+
example: "550e8400-e29b-41d4-a716-446655440000"
9+
type:
10+
type: string
11+
enum:
12+
- links

docs/spec/paths/v1@proofs@link.yaml renamed to docs/spec/paths/v1@links.yaml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,48 @@ post:
3535
data:
3636
type: object
3737
$ref: '#/components/schemas/ProofLink'
38-
3938
400:
4039
$ref: '#/components/responses/invalidParameter'
4140
401:
4241
$ref: '#/components/responses/invalidAuth'
4342
500:
4443
$ref: '#/components/responses/internalError'
4544

45+
get:
46+
summary: Get Proofs Links by User DID
47+
description: >
48+
Returns information about the all links of the user.
49+
operationId: proofsLinksByUserDID
50+
security:
51+
- Bearer: [ ]
52+
tags:
53+
- Proofs
54+
parameters:
55+
- in: path
56+
name: 'did'
57+
required: true
58+
description: The User DID
59+
schema:
60+
type: string
61+
example: "did:iden3:readonly:tM1QCJ7ytcbvLB7EFQhGsJPumc11DEE18gEvAzxE7"
62+
responses:
63+
'200':
64+
description: OK
65+
content:
66+
application/vnd.api+json:
67+
schema:
68+
type: object
69+
required:
70+
- data
71+
properties:
72+
data:
73+
type: array
74+
items:
75+
$ref: '#/components/schemas/ProofLink'
76+
77+
400:
78+
$ref: '#/components/responses/invalidParameter'
79+
404:
80+
$ref: '#/components/responses/notFound'
81+
500:
82+
$ref: '#/components/responses/internalError'

docs/spec/paths/v1@proofs@link@{link_id}.yaml renamed to docs/spec/paths/v1@links@{link_id}.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ get:
2929
type: array
3030
items:
3131
$ref: '#/components/schemas/Proof'
32-
3332
400:
3433
$ref: '#/components/responses/invalidParameter'
3534
404:

docs/spec/paths/v1@proofs.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,41 @@ post:
3636
500:
3737
$ref: '#/components/responses/internalError'
3838

39+
get:
40+
summary: Get Proofs by User DID
41+
description: >
42+
Returns information about the all proofs of the user.
43+
operationId: proofByUserDID
44+
security:
45+
- Bearer: [ ]
46+
tags:
47+
- Proofs
48+
parameters:
49+
- in: query
50+
name: 'did'
51+
required: true
52+
description: The User DID
53+
schema:
54+
type: string
55+
example: "did:iden3:readonly:tM1QCJ7ytcbvLB7EFQhGsJPumc11DEE18gEvAzxE7"
56+
responses:
57+
'200':
58+
description: OK
59+
content:
60+
application/vnd.api+json:
61+
schema:
62+
type: object
63+
required:
64+
- data
65+
properties:
66+
data:
67+
type: array
68+
items:
69+
$ref: '#/components/schemas/Proof'
70+
400:
71+
$ref: '#/components/responses/invalidParameter'
72+
404:
73+
$ref: '#/components/responses/notFound'
74+
500:
75+
$ref: '#/components/responses/internalError'
76+

docs/spec/paths/v1@proofs@user@{user_did}.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.

docs/spec/paths/v1@proofs@user@{user_did}@link.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/rarimo/rarime-link-svc
33
go 1.20
44

55
require (
6+
github.com/Masterminds/squirrel v1.4.0
67
github.com/alecthomas/kingpin v2.2.6+incompatible
78
github.com/go-chi/chi v4.1.2+incompatible
89
github.com/go-ozzo/ozzo-validation/v4 v4.2.1
@@ -14,11 +15,11 @@ require (
1415
gitlab.com/distributed_lab/kit v1.11.2
1516
gitlab.com/distributed_lab/logan v3.8.1+incompatible
1617
gitlab.com/distributed_lab/running v0.0.0-20200706131153-4af0e83eb96c
18+
gitlab.com/distributed_lab/urlval v3.0.0+incompatible
1719
gitlab.com/tokend/keypair v0.0.0-20190412110653-b9d7e0c8b312
1820
)
1921

2022
require (
21-
github.com/Masterminds/squirrel v1.4.0 // indirect
2223
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
2324
github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9 // indirect
2425
github.com/certifi/gocertifi v0.0.0-20200211180108-c7c1fbc02894 // indirect

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ gitlab.com/distributed_lab/lorem v0.2.0 h1:Rc7Ef3eGSpei8EtWcV6fzPW3O/QEF2zgZR4+h
228228
gitlab.com/distributed_lab/lorem v0.2.0/go.mod h1:wkzrGoB1L/yUBu56SfoJ/vNiPqiHZcg75AnBkWNcjhQ=
229229
gitlab.com/distributed_lab/running v0.0.0-20200706131153-4af0e83eb96c h1:cpIjV8C//7sLVvMcBaFGopI8sMcCw8Za7T0HIf52esU=
230230
gitlab.com/distributed_lab/running v0.0.0-20200706131153-4af0e83eb96c/go.mod h1:4TnADX84dQjQMRHKIMPCVL0L97rD/Jxv0xDbrN6aKzk=
231+
gitlab.com/distributed_lab/urlval v3.0.0+incompatible h1:OWU3CcZU+z0BVooufOSQFO9biDfsjM3e7YYauC278HU=
232+
gitlab.com/distributed_lab/urlval v3.0.0+incompatible/go.mod h1:cKnUlnZCHUuke/l95YLvW5JoGC2yn53HVgF9rt1WiIg=
231233
gitlab.com/tokend/keypair v0.0.0-20190412110653-b9d7e0c8b312 h1:u8pxrNw8QKIsrmClG71uuTPy22fkePAXBkHgxrXkMU8=
232234
gitlab.com/tokend/keypair v0.0.0-20190412110653-b9d7e0c8b312/go.mod h1:vdlhN5/oQR7uY8EsGSqPf8bwnmQxxpaq7qrQn5Y3U/w=
233235
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@@ -288,4 +290,3 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
288290
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
289291
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
290292
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
291-
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/data/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type ProofQ interface {
2424
Update(p *Proof) error
2525
Upsert(p *Proof) error
2626
Delete(p *Proof) error
27-
ProofsByUserDIDCtx(ctx context.Context, userDID string) ([]Proof, error)
27+
ProofsByCreatorCtx(ctx context.Context, userDID string) ([]Proof, error)
2828
}
2929

3030
type LinkQ interface {

internal/data/pg/proof_schemas.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func (q ProofQ) SelectAllCtx(ctx context.Context) ([]*data.Proof, error) {
1919
return proofs, nil
2020
}
2121

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

2525
var proofs []data.Proof
2626

internal/services/api/handlers/create_proof.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ func newProofCreateRequest(r *http.Request) (*proofCreateRequest, error) {
4040
return &req, nil
4141
}
4242

43+
// TODO add schema_url; change time format
44+
4345
func CreateProof(w http.ResponseWriter, r *http.Request) {
4446
req, err := newProofCreateRequest(r)
4547
if err != nil {

internal/services/api/handlers/create_proof_link.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ func CreateProofLink(w http.ResponseWriter, r *http.Request) {
8585
return
8686
}
8787

88-
ape.Render(w, resources.ProofLinkResponse{
89-
Data: resources.ProofLink{
88+
ape.Render(w, resources.LinkResponse{
89+
Data: resources.Link{
9090
Key: resources.Key{
91-
Type: resources.PROOFS,
91+
Type: resources.LINKS,
9292
},
93-
Attributes: resources.ProofLinkAttributes{
93+
Attributes: resources.LinkAttributes{
9494
Link: linkID.String(),
9595
CreatedAt: timestamp.String(),
9696
},

internal/services/api/handlers/get_links_by_user.go

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package handlers
22

33
import (
44
"context"
5-
"github.com/go-chi/chi"
65
validation "github.com/go-ozzo/ozzo-validation/v4"
76
"github.com/rarimo/rarime-link-svc/resources"
87
"gitlab.com/distributed_lab/ape"
98
"gitlab.com/distributed_lab/ape/problems"
10-
"gitlab.com/distributed_lab/logan/v3/errors"
9+
"gitlab.com/distributed_lab/urlval"
1110
"net/http"
1211
"strconv"
1312
)
@@ -16,19 +15,20 @@ type proofsLinksByUserDIDRequest struct {
1615
UserDid string
1716
}
1817

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

25-
return proofsLinksByUserDIDRequest{userDid}, validation.Errors{
26-
"user_did": validation.Validate(userDid, validation.Required),
25+
return proofsLinksByUserDIDRequest{request.UserDid}, validation.Errors{
26+
"did": validation.Validate(request.UserDid, validation.Required),
2727
}.Filter()
2828
}
2929

30-
func ProofsLinkByUserDID(w http.ResponseWriter, r *http.Request) {
31-
req, err := newProofLinkByUserDIDRequest(r)
30+
func GetLinks(w http.ResponseWriter, r *http.Request) {
31+
req, err := newGetLinksRequest(r)
3232
if err != nil {
3333
ape.RenderErr(w, problems.BadRequest(err)...)
3434
return
@@ -40,29 +40,26 @@ func ProofsLinkByUserDID(w http.ResponseWriter, r *http.Request) {
4040
ape.RenderErr(w, problems.InternalError())
4141
return
4242
}
43-
4443
if proofsLinks == nil {
4544
Log(r).WithField("user_did", req.UserDid).Warn("proofs not found")
4645
ape.RenderErr(w, problems.NotFound())
4746
return
4847
}
4948

50-
var response resources.ProofLinkListResponse
51-
49+
var response resources.LinkListResponse
5250
for _, link := range proofsLinks {
53-
linkResponse := resources.ProofLinkResponse{
54-
Data: resources.ProofLink{
51+
linkResponse := resources.LinkResponse{
52+
Data: resources.Link{
5553
Key: resources.Key{
5654
ID: link.ID.String(),
57-
Type: resources.PROOFS,
55+
Type: resources.LINKS,
5856
},
59-
Attributes: resources.ProofLinkAttributes{
57+
Attributes: resources.LinkAttributes{
6058
CreatedAt: strconv.FormatInt(link.CreatedAt.Unix(), 10),
6159
Link: link.ID.String(),
6260
},
6361
},
6462
}
65-
6663
response.Data = append(response.Data, linkResponse.Data)
6764
}
6865

0 commit comments

Comments
 (0)