Skip to content
Snippets Groups Projects
Commit 74075616 authored by Michal Zander's avatar Michal Zander
Browse files

Rename balance history type

parent 9210ff40
No related branches found
No related tags found
1 merge request!171Unify API returns to sql composite types, add pattern tests for REST API
......@@ -201,7 +201,7 @@ CREATE OR REPLACE FUNCTION btracker_backend.balance_history(
_from_op BIGINT,
_to_op BIGINT
)
RETURNS SETOF btracker_backend.balance_history_type
RETURNS SETOF btracker_backend.balance_history
LANGUAGE 'plpgsql' STABLE
AS
$$
......
......@@ -157,7 +157,7 @@ DECLARE
_block_range hive.blocks_range := hive.convert_to_blocks_range("from-block","to-block");
_account_id INT = (SELECT av.id FROM hive.accounts_view av WHERE av.name = "account-name");
_coin_type INT := (CASE WHEN "coin-type" = 'HBD' THEN 13 WHEN "coin-type" = 'HIVE' THEN 21 ELSE 37 END);
_result btracker_backend.balance_history_type[];
_result btracker_backend.balance_history[];
_ops_count INT;
_from_op BIGINT;
......@@ -224,7 +224,7 @@ BEGIN
RETURN (
COALESCE(_ops_count, 0),
COALESCE(__total_pages, 0),
COALESCE(_result, '{}'::btracker_backend.balance_history_type[])
COALESCE(_result, '{}'::btracker_backend.balance_history[])
)::btracker_backend.operation_history;
END
......
SET ROLE btracker_owner;
DO $$
DECLARE
__schema_name VARCHAR;
BEGIN
SHOW SEARCH_PATH INTO __schema_name;
EXECUTE format(
$BODY$
/** openapi:paths
/last-synced-block:
get:
tags:
- Other
summary: Get last block number synced by balance tracker
description: |
Get the block number of the last block synced by balance tracker.
SQL example
* `SELECT * FROM btracker_endpoints.get_btracker_last_synced_block();`
REST call example
* `GET ''https://%1$s/balance-api/last-synced-block''`
operationId: btracker_endpoints.get_btracker_last_synced_block
responses:
'200':
description: |
Last synced block by balance tracker
* Returns `INT`
content:
application/json:
schema:
type: integer
example: 5000000
'404':
description: No blocks synced
*/
-- openapi-generated-code-begin
DROP FUNCTION IF EXISTS btracker_endpoints.get_btracker_last_synced_block;
CREATE OR REPLACE FUNCTION btracker_endpoints.get_btracker_last_synced_block()
RETURNS INT
-- openapi-generated-code-end
LANGUAGE 'plpgsql' STABLE
AS
$pb$
BEGIN
PERFORM set_config('response.headers', '[{"Cache-Control": "public, max-age=0"}]', true);
RETURN current_block_num FROM hafd.contexts WHERE name = '%s';
END
$pb$;
$BODY$,
__schema_name, __schema_name);
END
$$;
RESET ROLE;
SET ROLE btracker_owner;
/** openapi:paths
/version:
get:
tags:
- Other
summary: Get Balance tracker''s version
description: |
Get Balance tracker''s last commit hash (versions set by by hash value).
SQL example
* `SELECT * FROM btracker_endpoints.get_btracker_version();`
REST call example
* `GET ''https://%1$s/balance-api/version''`
operationId: btracker_endpoints.get_btracker_version
responses:
'200':
description: |
Balance tracker version
* Returns `TEXT`
content:
application/json:
schema:
type: string
example: c2fed8958584511ef1a66dab3dbac8c40f3518f0
'404':
description: App not installed
*/
-- openapi-generated-code-begin
DROP FUNCTION IF EXISTS btracker_endpoints.get_btracker_version;
CREATE OR REPLACE FUNCTION btracker_endpoints.get_btracker_version()
RETURNS TEXT
-- openapi-generated-code-end
LANGUAGE 'plpgsql' STABLE
AS
$$
BEGIN
--100000s because version of hafbe doesn't change as often, but it may change
PERFORM set_config('response.headers', '[{"Cache-Control": "public, max-age=100000"}]', true);
RETURN git_hash FROM version;
END
$$;
RESET ROLE;
......@@ -157,7 +157,7 @@ CREATE TYPE btracker_backend.aggregated_history AS (
/** openapi:components:schemas
btracker_backend.balance_history_type:
btracker_backend.balance_history:
type: object
properties:
block_num:
......@@ -186,8 +186,8 @@ btracker_backend.balance_history_type:
description: Creation date
*/
-- openapi-generated-code-begin
DROP TYPE IF EXISTS btracker_backend.balance_history_type CASCADE;
CREATE TYPE btracker_backend.balance_history_type AS (
DROP TYPE IF EXISTS btracker_backend.balance_history CASCADE;
CREATE TYPE btracker_backend.balance_history AS (
"block_num" INT,
"operation_id" TEXT,
"op_type_id" INT,
......@@ -211,7 +211,7 @@ btracker_backend.operation_history:
operations_result:
type: array
items:
$ref: '#/components/schemas/btracker_backend.balance_history_type'
$ref: '#/components/schemas/btracker_backend.balance_history'
description: List of operation results
*/
-- openapi-generated-code-begin
......@@ -219,7 +219,7 @@ DROP TYPE IF EXISTS btracker_backend.operation_history CASCADE;
CREATE TYPE btracker_backend.operation_history AS (
"total_operations" INT,
"total_pages" INT,
"operations_result" btracker_backend.balance_history_type[]
"operations_result" btracker_backend.balance_history[]
);
-- openapi-generated-code-end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment