Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add delete user, get proof by userID endpoints #3

Merged
merged 8 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/spec/components/parameters/eventIdParam.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
in: query
name: 'event_id'
required: false
description: "Event ID"
example: "2234556494903931186902189494613533900917417361106374681011849132651019822199"
schema:
type: string
format: string

2 changes: 1 addition & 1 deletion docs/spec/components/parameters/pathIDHash.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
in: path
name: 'user_id_hash'
required: true
example: "[email protected]"
example: "0x384734934386483457309437583757364283"
schema:
type: string
fomat: string
16 changes: 16 additions & 0 deletions docs/spec/components/schemas/GetProof.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
allOf:
- $ref: '#/components/schemas/GetProofKey'
- type: object
x-go-is-request: true
required:
- attributes
properties:
attributes:
required:
- proof
properties:
proof:
type: object
format: types.ZKProof
description: |
Query ZK passport verification proof.
12 changes: 12 additions & 0 deletions docs/spec/components/schemas/GetProofKey.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: "18493889724322d9aba2d93238ae60c2638946737bbe8eaecd6e5efdc0b6f4ff"
type:
type: string
enum:
- get_proof
18 changes: 18 additions & 0 deletions docs/spec/components/schemas/Links.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
allOf:
- $ref: '#/components/schemas/LinksKey'
- type: object
x-go-is-request: true
required:
- attributes
properties:
attributes:
required:
- callbackUrl
- getProofParams
properties:
callbackUrl:
type: string
example: "https://example.com/integrations/verificator-svc/v2/private/proof-params/c15ad8f88949"
getProofParams:
type: string
example: "https://example.com/integrations/verificator-svc/v1/public/callback/c15ad8f88949"
12 changes: 12 additions & 0 deletions docs/spec/components/schemas/LinksKey.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: "18493889724322d9aba2d93238ae60c2638946737bbe8eaecd6e5efdc0b6f4ff"
type:
type: string
enum:
- verification_link
49 changes: 49 additions & 0 deletions docs/spec/components/schemas/ProofParams.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
allOf:
- $ref: '#/components/schemas/ProofParamsKey'
- type: object
required:
- attributes
properties:
attributes:
type: object
required:
- eventID
- eventData
- selector
- identityCounter
- timestampLowerBound
- timestampUpperBound
- identityCounterLowerBound
- identityCounterUpperBound
- expirationDateLowerBound
- expirationDateUpperBound
- birthDateLowerBound
- birthDateUpperBound
- citizenshipMask
properties:
eventId:
type: string
eventData:
type: string
selector:
type: string
identityCounter:
type: integer
timestampLowerBound:
type: string
timestampUpperBound:
type: string
identityCounterLowerBound:
type: integer
identityCounterUpperBound:
type: integer
expirationDateLowerBound:
type: string
expirationDateUpperBound:
type: string
birthDateLowerBound:
type: string
birthDateUpperBound:
type: string
citizenshipMask:
type: string
12 changes: 12 additions & 0 deletions docs/spec/components/schemas/ProofParamsKey.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: "[email protected]"
type:
type: string
enum:
- get_proof_params
25 changes: 25 additions & 0 deletions docs/spec/components/schemas/User.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
allOf:
- $ref: '#/components/schemas/UserKey'
- type: object
x-go-is-request: true
required:
- attributes
properties:
attributes:
required:
- ageLowerBound
- uniqueness
- nationality
properties:
ageLowerBound:
type: integer
example: 18
uniqueness:
type: boolean
example: true
nationality:
type: string
example: "UKR"
event_id:
type: string
example: "2234556494903931186902189494613533900917417361106374681011849132651019822199"
12 changes: 12 additions & 0 deletions docs/spec/components/schemas/UserKey.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: "[email protected]"
type:
type: string
enum:
- user
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
get:
tags:
- Get proof by userID
summary: Get proof by userID
description: |
Get proof for user
operationId: getProof
parameters:
- $ref: '#/components/parameters/idParam'
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/GetProof'
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 @@ -10,6 +10,7 @@ get:
- $ref: '#/components/parameters/typeOfVerificationAgeParam'
- $ref: '#/components/parameters/typeOfVerificationUniquenessParam'
- $ref: '#/components/parameters/nationalityParam'
- $ref: '#/components/parameters/eventIdParam'
responses:
200:
description: Success
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
delete:
tags:
- Delete user
summary: Delete user
description: |
Delete user by UserID.
operationId: deleteUser
parameters:
- $ref: '#/components/parameters/pathID'
responses:
'204':
description: User deleted
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
@@ -0,0 +1,27 @@
get:
tags:
- Get Proof Parameters
summary: Get Proof Parameters
description: |
Get Proof Parameters by userID.
operationId: getProofParameters
parameters:
- $ref: '#/components/parameters/pathIDHash'
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/ProofParams'
400:
$ref: '#/components/responses/invalidParameter'
404:
$ref: '#/components/responses/notFound'
500:
$ref: '#/components/responses/internalError'
36 changes: 36 additions & 0 deletions docs/spec/paths/integrations@verificator-svc@v2@[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
post:
tags:
- Verifications Links
summary: Request verifications links
description: |
Request verification links for user.
operationId: getVerificationLink
requestBody:
required: true
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/User'
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/Links'
400:
$ref: '#/components/responses/invalidParameter'
404:
$ref: '#/components/responses/notFound'
500:
$ref: '#/components/responses/internalError'
4 changes: 2 additions & 2 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
GENERATOR_IMAGE=tokend/openapi-generator:v0.1.0


GENERATED="~/go/src/verificator-svc/resources"
OPENAPI_DIR="~/go/src/verificator-svc/docs/web_deploy"
GENERATED="./resources"
OPENAPI_DIR="./docs/web_deploy"
PACKAGE_NAME=resources

function printHelp {
Expand Down
3 changes: 2 additions & 1 deletion internal/assets/migrations/001_initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ CREATE TABLE verify_users
nationality TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT (NOW() AT TIME ZONE 'utc'),
uniqueness BOOLEAN NOT NULL,
status TEXT NOT NULL
status TEXT NOT NULL,
proof JSON NOT NULL
);

-- +migrate Down
Expand Down
23 changes: 21 additions & 2 deletions internal/data/pg/verify_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pg

import (
"database/sql"
"encoding/json"
"fmt"
"time"

Expand Down Expand Up @@ -62,17 +63,23 @@ func (q *VerifyUsersQ) Get() (*data.VerifyUsers, error) {
}

func (q *VerifyUsersQ) Insert(VerifyUsers *data.VerifyUsers) error {
proofJSON, err := json.Marshal(VerifyUsers.Proof)
if err != nil {
return fmt.Errorf("failed to marshal proof for user %s: %w", VerifyUsers.UserID, err)
}

stmt := sq.Insert(verifyUsersTableName).SetMap(map[string]interface{}{
"user_id": VerifyUsers.UserID,
"user_id_hash": VerifyUsers.UserIDHash,
"age_lower_bound": VerifyUsers.AgeLowerBound,
"nationality": VerifyUsers.Nationality,
"uniqueness": VerifyUsers.Uniqueness,
"status": VerifyUsers.Status,
"proof": proofJSON,
})

if err := q.db.Exec(stmt); err != nil {
return fmt.Errorf("insert balance %+v: %w", VerifyUsers, err)
if err = q.db.Exec(stmt); err != nil {
return fmt.Errorf("insert user %+v: %w", VerifyUsers, err)
}

return nil
Expand All @@ -83,6 +90,7 @@ func (q *VerifyUsersQ) Update(VerifyUsers *data.VerifyUsers) error {
sq.Update(verifyUsersTableName).
SetMap(map[string]interface{}{
"status": VerifyUsers.Status,
"proof": VerifyUsers.Proof,
}).
Where(sq.Eq{userIdColumnName: VerifyUsers.UserID}),
)
Expand All @@ -102,6 +110,17 @@ func (q *VerifyUsersQ) Delete() error {
return nil
}

func (q *VerifyUsersQ) DeleteByID(VerifyUsers *data.VerifyUsers) error {
err := q.db.Exec(
sq.Delete(verifyUsersTableName).Where(sq.Eq{userIdColumnName: VerifyUsers.UserID}),
)
if err != nil {
return errors.Wrap(err, "failed to delete user by userID")
}
return nil

}

func (q *VerifyUsersQ) WhereID(userId string) data.VerifyUsersQ {
q.sel = q.sel.Where(sq.Eq{userIdColumnName: userId})
q.del = q.del.Where(sq.Eq{userIdColumnName: userId})
Expand Down
Loading
Loading