From fc8668ee8247423daea0b4d47caeccc7d6b57d4a Mon Sep 17 00:00:00 2001 From: violog <51th.apprent1ce.f0rce@gmail.com> Date: Tue, 6 Feb 2024 12:14:38 +0200 Subject: [PATCH] Withdrawal history docs and models --- docs/spec/components/schemas/WithdrawKey.yaml | 4 - docs/spec/components/schemas/Withdrawal.yaml | 25 +++++++ .../components/schemas/WithdrawalKey.yaml | 11 +++ ...rations@rarime-points-svc@v1@balances.yaml | 2 +- ...s@rarime-points-svc@v1@balances@{did}.yaml | 38 ---------- ...nts-svc@v1@balances@{did}@withdrawals.yaml | 74 +++++++++++++++++++ resources/model_resource_type.go | 1 + resources/model_withdrawal.go | 43 +++++++++++ resources/model_withdrawal_attributes.go | 14 ++++ 9 files changed, 169 insertions(+), 43 deletions(-) create mode 100644 docs/spec/components/schemas/Withdrawal.yaml create mode 100644 docs/spec/components/schemas/WithdrawalKey.yaml create mode 100644 docs/spec/paths/integrations@rarime-points-svc@v1@balances@{did}@withdrawals.yaml create mode 100644 resources/model_withdrawal.go create mode 100644 resources/model_withdrawal_attributes.go diff --git a/docs/spec/components/schemas/WithdrawKey.yaml b/docs/spec/components/schemas/WithdrawKey.yaml index 751eeb8..026f033 100644 --- a/docs/spec/components/schemas/WithdrawKey.yaml +++ b/docs/spec/components/schemas/WithdrawKey.yaml @@ -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 ] diff --git a/docs/spec/components/schemas/Withdrawal.yaml b/docs/spec/components/schemas/Withdrawal.yaml new file mode 100644 index 0000000..9079c08 --- /dev/null +++ b/docs/spec/components/schemas/Withdrawal.yaml @@ -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 diff --git a/docs/spec/components/schemas/WithdrawalKey.yaml b/docs/spec/components/schemas/WithdrawalKey.yaml new file mode 100644 index 0000000..f1f2dac --- /dev/null +++ b/docs/spec/components/schemas/WithdrawalKey.yaml @@ -0,0 +1,11 @@ +type: object +required: + - id + - type +properties: + id: + type: string + example: "059c81dd-2a54-44a8-8142-c15ad8f88949" + type: + type: string + enum: [ withdrawal ] diff --git a/docs/spec/paths/integrations@rarime-points-svc@v1@balances.yaml b/docs/spec/paths/integrations@rarime-points-svc@v1@balances.yaml index 9f3345b..3cacf85 100644 --- a/docs/spec/paths/integrations@rarime-points-svc@v1@balances.yaml +++ b/docs/spec/paths/integrations@rarime-points-svc@v1@balances.yaml @@ -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 diff --git a/docs/spec/paths/integrations@rarime-points-svc@v1@balances@{did}.yaml b/docs/spec/paths/integrations@rarime-points-svc@v1@balances@{did}.yaml index 15b99b5..8b5eeae 100644 --- a/docs/spec/paths/integrations@rarime-points-svc@v1@balances@{did}.yaml +++ b/docs/spec/paths/integrations@rarime-points-svc@v1@balances@{did}.yaml @@ -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' diff --git a/docs/spec/paths/integrations@rarime-points-svc@v1@balances@{did}@withdrawals.yaml b/docs/spec/paths/integrations@rarime-points-svc@v1@balances@{did}@withdrawals.yaml new file mode 100644 index 0000000..5d1b27d --- /dev/null +++ b/docs/spec/paths/integrations@rarime-points-svc@v1@balances@{did}@withdrawals.yaml @@ -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' diff --git a/resources/model_resource_type.go b/resources/model_resource_type.go index 0571d68..fc73c4a 100644 --- a/resources/model_resource_type.go +++ b/resources/model_resource_type.go @@ -13,4 +13,5 @@ const ( CREATE_BALANCE ResourceType = "create_balance" EVENT ResourceType = "event" WITHDRAW ResourceType = "withdraw" + WITHDRAWAL ResourceType = "withdrawal" ) diff --git a/resources/model_withdrawal.go b/resources/model_withdrawal.go new file mode 100644 index 0000000..dfc8561 --- /dev/null +++ b/resources/model_withdrawal.go @@ -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 +} diff --git a/resources/model_withdrawal_attributes.go b/resources/model_withdrawal_attributes.go new file mode 100644 index 0000000..60af863 --- /dev/null +++ b/resources/model_withdrawal_attributes.go @@ -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"` +}