Skip to content

Commit

Permalink
Withdrawal history docs and models
Browse files Browse the repository at this point in the history
  • Loading branch information
violog committed Feb 6, 2024
1 parent e57d65f commit fc8668e
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 43 deletions.
4 changes: 0 additions & 4 deletions docs/spec/components/schemas/WithdrawKey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ required:
- id
- type
properties:
id:
type: string
description: DID of the points owner
example: "did:iden3:readonly:tUDjWxnVJNi7t3FudukqrUcNwF5KVGoWgim5pp2jV"
type:
type: string
enum: [ withdraw ]
25 changes: 25 additions & 0 deletions docs/spec/components/schemas/Withdrawal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
allOf:
- $ref: '#/components/schemas/WithdrawalKey'
- type: object
required:
- attributes
properties:
attributes:
type: object
required:
- amount
- address
- created_at
properties:
amount:
type: integer
description: Amount of points withdrawn
example: 580
address:
type: string
description: Rarimo address which points were withdrawn to. Can be any valid address.
example: rarimo15hcd6tv7pe8hk2re7hu0zg0aphqdm2dtjrs0ds
created_at:
type: integer
description: Unix timestamp of withdrawal creation
example: 1706531218
11 changes: 11 additions & 0 deletions docs/spec/components/schemas/WithdrawalKey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type: object
required:
- id
- type
properties:
id:
type: string
example: "059c81dd-2a54-44a8-8142-c15ad8f88949"
type:
type: string
enum: [ withdrawal ]
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ get:
description: Returns leaders sorted by points in descending order.
operationId: getLeaderboard
parameters:
- $ref: '#/components/parameters/pageCursor'
- $ref: '#/components/parameters/pageLimit'
- $ref: '#/components/parameters/pageNumber'
- $ref: '#/components/parameters/pageOrder'
responses:
200:
description: Success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,3 @@ get:
$ref: '#/components/responses/invalidAuth'
500:
$ref: '#/components/responses/internalError'

patch:
tags:
- Points balance
summary: Withdraw points to RMO
description: Convert points to RMO by exchange rate and withdraw to user wallet
operationId: withdrawPoints
parameters:
- $ref: '#/components/parameters/pathDID'
requestBody:
required: true
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/Withdraw'
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/Balance'
400:
$ref: '#/components/responses/invalidParameter'
401:
$ref: '#/components/responses/invalidAuth'
500:
$ref: '#/components/responses/internalError'
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
get:
tags:
- Points balance
summary: Withdrawal history
description: Points withdrawal history of the user
operationId: getWithdrawalHistory
parameters:
- $ref: '#/components/parameters/pathDID'
- $ref: '#/components/parameters/pageCursor'
- $ref: '#/components/parameters/pageLimit'
- $ref: '#/components/parameters/pageOrder'
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
type: array
items:
$ref: '#/components/schemas/Withdrawal'
400:
$ref: '#/components/responses/invalidParameter'
401:
$ref: '#/components/responses/invalidAuth'
500:
$ref: '#/components/responses/internalError'

post:
tags:
- Points balance
summary: Withdraw points
description: Convert points to RMO by exchange rate and withdraw to user wallet
operationId: withdrawPoints
parameters:
- $ref: '#/components/parameters/pathDID'
requestBody:
required: true
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/Withdraw'
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
- included
properties:
data:
$ref: '#/components/schemas/Withdrawal'
included:
type: array
items:
$ref: '#/components/schemas/Balance'
400:
$ref: '#/components/responses/invalidParameter'
401:
$ref: '#/components/responses/invalidAuth'
500:
$ref: '#/components/responses/internalError'
1 change: 1 addition & 0 deletions resources/model_resource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ const (
CREATE_BALANCE ResourceType = "create_balance"
EVENT ResourceType = "event"
WITHDRAW ResourceType = "withdraw"
WITHDRAWAL ResourceType = "withdrawal"
)
43 changes: 43 additions & 0 deletions resources/model_withdrawal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* GENERATED. Do not modify. Your changes might be overwritten!
*/

package resources

import "encoding/json"

type Withdrawal struct {
Key
Attributes WithdrawalAttributes `json:"attributes"`
}
type WithdrawalResponse struct {
Data Withdrawal `json:"data"`
Included Included `json:"included"`
}

type WithdrawalListResponse struct {
Data []Withdrawal `json:"data"`
Included Included `json:"included"`
Links *Links `json:"links"`
Meta json.RawMessage `json:"meta,omitempty"`
}

func (r *WithdrawalListResponse) PutMeta(v interface{}) (err error) {
r.Meta, err = json.Marshal(v)
return err
}

func (r *WithdrawalListResponse) GetMeta(out interface{}) error {
return json.Unmarshal(r.Meta, out)
}

// MustWithdrawal - returns Withdrawal from include collection.
// if entry with specified key does not exist - returns nil
// if entry with specified key exists but type or ID mismatches - panics
func (c *Included) MustWithdrawal(key Key) *Withdrawal {
var withdrawal Withdrawal
if c.tryFindEntry(key, &withdrawal) {
return &withdrawal
}
return nil
}
14 changes: 14 additions & 0 deletions resources/model_withdrawal_attributes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* GENERATED. Do not modify. Your changes might be overwritten!
*/

package resources

type WithdrawalAttributes struct {
// Rarimo address which points were withdrawn to. Can be any valid address.
Address string `json:"address"`
// Amount of points withdrawn
Amount int32 `json:"amount"`
// Unix timestamp of withdrawal creation
CreatedAt int32 `json:"created_at"`
}

0 comments on commit fc8668e

Please sign in to comment.