From 0939df2a9e189c1416e5af2d27ab9e433c663c56 Mon Sep 17 00:00:00 2001 From: Lucas Magnus Date: Mon, 11 Sep 2023 11:00:36 -0300 Subject: [PATCH 01/11] feat: supply chart --- backend/internal/controller/http/v1/assets.go | 39 +++++++++++++------ .../usecase/repo/log_transaction_postgres.go | 6 ++- .../000022_transactions_log_supply.down.sql | 2 + .../000022_transactions_log_supply.up.sql | 2 + 4 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 backend/migrations/000022_transactions_log_supply.down.sql create mode 100644 backend/migrations/000022_transactions_log_supply.up.sql diff --git a/backend/internal/controller/http/v1/assets.go b/backend/internal/controller/http/v1/assets.go index d82cafb1..5ce53ad2 100644 --- a/backend/internal/controller/http/v1/assets.go +++ b/backend/internal/controller/http/v1/assets.go @@ -49,23 +49,29 @@ type CreateAssetRequest struct { } type BurnAssetRequest struct { - Id string `json:"id" binding:"required" example:"001"` - SponsorId int `json:"sponsor_id" example:"2"` - Amount string `json:"amount" binding:"required" example:"1000"` + Id string `json:"id" binding:"required" example:"001"` + SponsorId int `json:"sponsor_id" example:"2"` + Amount string `json:"amount" binding:"required" example:"1000"` + CurrentSupply int `json:"current_supply" example:"1000"` + CurrentMainVault int `json:"current_main_vault" example:"1000"` } type MintAssetRequest struct { - Id string `json:"id" binding:"required" example:"12"` - SponsorId int `json:"sponsor_id" example:"2"` - Code string `json:"code" binding:"required" example:"USDC"` - Amount string `json:"amount" binding:"required" example:"1000"` + Id string `json:"id" binding:"required" example:"12"` + SponsorId int `json:"sponsor_id" example:"2"` + Code string `json:"code" binding:"required" example:"USDC"` + Amount string `json:"amount" binding:"required" example:"1000"` + CurrentSupply int `json:"current_supply" example:"1000"` + CurrentMainVault int `json:"current_main_vault" example:"1000"` } type ClawbackAssetRequest struct { - SponsorId int `json:"sponsor_id" example:"2"` - Code string `json:"code" binding:"required" example:"USDC"` - Amount string `json:"amount" binding:"required" example:"1000"` - From string `json:"from" binding:"required" example:"GDKIJJIKXLOM2NRMPNQZUUYK24ZPVFC6426GZAICZ6E5PQG2MIPIMB2L"` + SponsorId int `json:"sponsor_id" example:"2"` + Code string `json:"code" binding:"required" example:"USDC"` + Amount string `json:"amount" binding:"required" example:"1000"` + From string `json:"from" binding:"required" example:"GDKIJJIKXLOM2NRMPNQZUUYK24ZPVFC6426GZAICZ6E5PQG2MIPIMB2L"` + CurrentSupply int `json:"current_supply" example:"1000"` + CurrentMainVault int `json:"current_main_vault" example:"1000"` } type TransferAssetRequest struct { @@ -74,6 +80,8 @@ type TransferAssetRequest struct { DestinationWalletPK string `json:"destination_wallet_pk" binding:"required" example:"GABCD...."` AssetID string `json:"asset_id" binding:"required" example:"12"` Amount string `json:"amount" binding:"required" example:"12"` + CurrentSupply int `json:"current_supply" example:"1000"` + CurrentMainVault int `json:"current_main_vault" example:"1000"` } type UpdateAuthFlagsRequest struct { @@ -321,12 +329,15 @@ func (r *assetsRoutes) mintAsset(c *gin.Context) { if err != nil { amount = 0 } + err = r.l.CreateLogTransaction(entity.LogTransaction{ Asset: asset, Amount: amount, TransactionTypeID: entity.MintAsset, UserID: userID, Description: createLogDescription(entity.MintAsset, asset.Code, nil, nil), + CurrentSupply: &request.CurrentSupply, + CurrentMainVault: &request.CurrentMainVault, }) if err != nil { errorResponse(c, http.StatusNotFound, "error to create log transaction", err) @@ -415,6 +426,8 @@ func (r *assetsRoutes) burnAsset(c *gin.Context) { Amount: amount, UserID: userID, Description: createLogDescription(entity.BurnAsset, asset.Code, nil, nil), + CurrentSupply: &request.CurrentSupply, + CurrentMainVault: &request.CurrentMainVault, }) if err != nil { errorResponse(c, http.StatusNotFound, "error to create log transaction", err) @@ -511,6 +524,8 @@ func (r *assetsRoutes) transferAsset(c *gin.Context) { Description: createLogDescription(entity.TransferAsset, asset.Code, nil, nil), OriginPK: &sourceWallet.Key.PublicKey, DestinationPK: &request.DestinationWalletPK, + CurrentSupply: &request.CurrentSupply, + CurrentMainVault: &request.CurrentMainVault, }) if err != nil { errorResponse(c, http.StatusNotFound, "error to create log transaction", err) @@ -599,6 +614,8 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) { Amount: amount, UserID: userID, Description: createLogDescription(entity.ClawbackAsset, asset.Code, nil, nil), + CurrentSupply: &request.CurrentSupply, + CurrentMainVault: &request.CurrentMainVault, }) if err != nil { errorResponse(c, http.StatusNotFound, "error to create log transaction", err) diff --git a/backend/internal/usecase/repo/log_transaction_postgres.go b/backend/internal/usecase/repo/log_transaction_postgres.go index 294b2105..fd1264f8 100644 --- a/backend/internal/usecase/repo/log_transaction_postgres.go +++ b/backend/internal/usecase/repo/log_transaction_postgres.go @@ -18,8 +18,10 @@ func NewLogTransactionRepo(postgres *postgres.Postgres) *LogTransactionRepo { } func (repo *LogTransactionRepo) StoreLogTransaction(log entity.LogTransaction) error { - stmp := `INSERT INTO logtransactions (user_id, transaction_type_id, asset_id, amount, description, origin_pk, destination_pk) VALUES ($1, $2, $3, $4, $5, $6, $7)` - _, err := repo.Db.Exec(stmp, log.UserID, log.TransactionTypeID, log.Asset.Id, log.Amount, log.Description, log.OriginPK, log.DestinationPK) + stmp := `INSERT INTO logtransactions (user_id, transaction_type_id, asset_id, amount, description, origin_pk, destination_pk, current_supply, current_main_vault) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)` + _, err := repo.Db.Exec(stmp, log.UserID, log.TransactionTypeID, log.Asset.Id, log.Amount, log.Description, log.OriginPK, log.DestinationPK, + log.CurrentSupply, log.CurrentMainVault) if err != nil { fmt.Println(err) return err diff --git a/backend/migrations/000022_transactions_log_supply.down.sql b/backend/migrations/000022_transactions_log_supply.down.sql new file mode 100644 index 00000000..90265c6f --- /dev/null +++ b/backend/migrations/000022_transactions_log_supply.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE LogTransactions DROP COLUMN current_supply; +ALTER TABLE LogTransactions DROP COLUMN COLUMN current_main_vault; \ No newline at end of file diff --git a/backend/migrations/000022_transactions_log_supply.up.sql b/backend/migrations/000022_transactions_log_supply.up.sql new file mode 100644 index 00000000..1257729e --- /dev/null +++ b/backend/migrations/000022_transactions_log_supply.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE LogTransactions ADD COLUMN current_supply FLOAT; +ALTER TABLE LogTransactions ADD COLUMN current_main_vault FLOAT; \ No newline at end of file From 531cd088c3a41da5e9f6831c374a67b8fca1b190 Mon Sep 17 00:00:00 2001 From: Wellington Junior Date: Wed, 13 Sep 2023 09:58:32 -0300 Subject: [PATCH 02/11] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20Add=20the=20log?= =?UTF-8?q?=5Ftranscation=20supply?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/docs/docs.go | 798 +++++++++++++++++- backend/docs/swagger.json | 798 +++++++++++++++++- backend/docs/swagger.yaml | 512 ++++++++++- .../controller/http/v1/log_transaction.go | 73 ++ backend/internal/controller/http/v1/role.go | 8 +- .../controller/http/v1/role_permissions.go | 5 +- backend/internal/controller/http/v1/users.go | 6 +- backend/internal/controller/http/v1/vault.go | 6 +- .../controller/http/v1/vault_category.go | 2 +- backend/internal/entity/transaction_log.go | 7 + backend/internal/usecase/interfaces.go | 2 + backend/internal/usecase/log_transaction.go | 16 + .../usecase/repo/log_transaction_postgres.go | 109 ++- 13 files changed, 2226 insertions(+), 116 deletions(-) diff --git a/backend/docs/docs.go b/backend/docs/docs.go index 0408b2ce..4cbc531f 100644 --- a/backend/docs/docs.go +++ b/backend/docs/docs.go @@ -18,7 +18,7 @@ const docTemplate = `{ "paths": { "/": { "get": { - "description": "Get all vault categories", + "description": "Get contract", "consumes": [ "application/json" ], @@ -26,17 +26,14 @@ const docTemplate = `{ "application/json" ], "tags": [ - "Vault category" + "Contract" ], - "summary": "Get all vault categories", + "summary": "Get contract", "responses": { "200": { "description": "OK", "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/entity.VaultCategory" - } + "$ref": "#/definitions/entity.Contract" } }, "500": { @@ -673,6 +670,165 @@ const docTemplate = `{ } } }, + "/log_transactions/last_transactions/{transaction_type_id}": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get last transactions logs for a specific transaction type", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Log Transactions" + ], + "summary": "Get last transactions", + "parameters": [ + { + "type": "integer", + "description": "Transaction Type ID", + "name": "transaction_type_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/entity.LogTransaction" + } + } + } + } + }, + "/log_transactions/supply/{asset_id}/{time_range}/{time_frame}": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get sum of supply for a specific asset, grouped by a specified time frame (e.g., '1h' for 1 hour)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Log Transactions" + ], + "summary": "Get sum of supply by Asset ID within a specific time frame", + "parameters": [ + { + "type": "integer", + "description": "Asset ID", + "name": "asset_id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Time range for the query (e.g., '24h' or '1d' '7d' '30d')", + "name": "time_range", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Time frame for the query (e.g., '1h' '2h' '24h' '36h')", + "name": "time_frame", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/entity.SumLogTransaction" + } + }, + "400": { + "description": "Invalid time_frame format", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "string" + } + } + } + } + }, + "/log_transactions/supply/{time_range}/{time_frame}": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get sum of supply for all assets, grouped by a specified time frame (e.g., '1h' for 1 hour)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Log Transactions" + ], + "summary": "Get sum of supply for all assets within a specific time frame", + "parameters": [ + { + "type": "string", + "description": "Time range for the query (e.g., '24h' or '1d' '7d' '30d')", + "name": "time_range", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Time frame for the query (e.g., '1h' '2h' '24h' '36h')", + "name": "time_frame", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.SumLogTransaction" + } + } + }, + "400": { + "description": "Invalid time_frame format", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "string" + } + } + } + } + }, "/log_transactions/transaction_type/{transaction_type_id}": { "get": { "security": [ @@ -780,11 +936,133 @@ const docTemplate = `{ } } } + }, + "post": { + "description": "Create a new role", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Role" + ], + "summary": "Create a new role", + "parameters": [ + { + "description": "Role info", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.RoleRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/entity.RoleRequest" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/v1.response" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/v1.response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } + } + }, + "/role-permission": { + "put": { + "description": "Update roles permissions", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "RolesPermissions" + ], + "summary": "Update roles permissions", + "parameters": [ + { + "description": "Roles permissions information", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.RolePermissionRequest" + } + } + ], + "responses": { + "200": { + "description": "Updated roles permissions information", + "schema": { + "$ref": "#/definitions/v1.RolePermissionRequest" + } + }, + "400": { + "description": "Bad Request: Invalid input data", + "schema": { + "$ref": "#/definitions/v1.response" + } + }, + "500": { + "description": "Internal Server Error: Failed to update roles permissions", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } } }, "/role-permission/permissions": { "get": { - "description": "Role permissions", + "description": "permissions", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Permissions" + ], + "summary": "Permissions", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Permission" + } + } + } + } + } + }, + "/role-permission/role-permissions": { + "get": { + "description": "Roles permissions", "consumes": [ "application/json" ], @@ -794,23 +1072,227 @@ const docTemplate = `{ "tags": [ "RolePermissions" ], - "summary": "Role permissions", + "summary": "Roles permissions", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.RolePermissionResponse" + } + } + } + } + } + }, + "/role-permission/user-permissions": { + "get": { + "description": "User permissions", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "RolePermissions" + ], + "summary": "User permissions", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.UserPermissionResponse" + } + } + } + } + } + }, + "/role/{id}": { + "put": { + "description": "Update a role by providing the Role ID and the updated information.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Role" + ], + "summary": "Update a role", + "parameters": [ + { + "type": "string", + "format": "uuid", + "description": "Role ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Role info", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.RoleRequest" + } + } + ], + "responses": { + "200": { + "description": "Updated role information", + "schema": { + "$ref": "#/definitions/entity.Role" + } + }, + "400": { + "description": "Bad Request: Invalid input data", + "schema": { + "$ref": "#/definitions/v1.response" + } + }, + "404": { + "description": "Not Found: Role not found", + "schema": { + "$ref": "#/definitions/v1.response" + } + }, + "500": { + "description": "Internal Server Error: Failed to update role", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } + }, + "delete": { + "description": "Delete a role by providing the Role ID and the updated information.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Role" + ], + "summary": "Delete a role", + "parameters": [ + { + "type": "string", + "format": "uuid", + "description": "Role ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Role info", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.RoleRequest" + } + } + ], + "responses": { + "200": { + "description": "Updated role information", + "schema": { + "$ref": "#/definitions/entity.RoleDelete" + } + }, + "400": { + "description": "Bad Request: Invalid input data", + "schema": { + "$ref": "#/definitions/v1.response" + } + }, + "404": { + "description": "Not Found: Role not found", + "schema": { + "$ref": "#/definitions/v1.response" + } + }, + "500": { + "description": "Internal Server Error: Failed to delete role", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } + } + }, + "/user/create": { + "post": { + "description": "Create user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Create user", + "operationId": "create", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.userResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } + } + }, + "/user/login": { + "post": { + "description": "Autentication User", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Autentication User", + "operationId": "autentication", "responses": { "200": { "description": "OK", "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/entity.RolePermissionResponse" - } + "$ref": "#/definitions/v1.userResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/v1.response" } } } } }, - "/user/create": { + "/user/logout": { "post": { - "description": "Edit users role", + "description": "Logout User", "consumes": [ "application/json" ], @@ -820,13 +1302,13 @@ const docTemplate = `{ "tags": [ "user" ], - "summary": "Edit users role", - "operationId": "editUsersRole", + "summary": "Logout User", + "operationId": "logout", "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/entity.UserRole" + "$ref": "#/definitions/v1.userResponse" } }, "500": { @@ -838,9 +1320,9 @@ const docTemplate = `{ } } }, - "/user/login": { + "/users/edit-users-role": { "post": { - "description": "Autentication User", + "description": "Edit users role", "consumes": [ "application/json" ], @@ -850,13 +1332,13 @@ const docTemplate = `{ "tags": [ "user" ], - "summary": "Autentication User", - "operationId": "autentication", + "summary": "Edit users role", + "operationId": "editUsersRole", "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/v1.userResponse" + "$ref": "#/definitions/entity.UserRole" } }, "500": { @@ -868,9 +1350,9 @@ const docTemplate = `{ } } }, - "/user/logout": { - "post": { - "description": "Logout User", + "/users/list-users": { + "get": { + "description": "List users", "consumes": [ "application/json" ], @@ -880,25 +1362,21 @@ const docTemplate = `{ "tags": [ "user" ], - "summary": "Logout User", - "operationId": "logout", + "summary": "GET All Users", "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/v1.userResponse" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/v1.response" + "type": "array", + "items": { + "$ref": "#/definitions/entity.UserResponse" + } } } } } }, - "/users": { + "/users/profile": { "get": { "description": "Get PRofile", "consumes": [ @@ -1034,6 +1512,36 @@ const docTemplate = `{ } }, "/vault-category": { + "get": { + "description": "Get all vault categories", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Vault category" + ], + "summary": "Get all vault categories", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.VaultCategory" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } + }, "post": { "description": "Create and issue a new asset on Stellar", "consumes": [ @@ -1196,6 +1704,67 @@ const docTemplate = `{ } } }, + "/vault/list": { + "get": { + "description": "Get all vault", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Vault" + ], + "summary": "Get all vault", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Vault" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } + } + }, + "/vault/{id}": { + "get": { + "description": "Get vault", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Vault" + ], + "summary": "Get vault", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/entity.Vault" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } + } + }, "/wallets": { "get": { "description": "List wallets by type", @@ -1427,6 +1996,14 @@ const docTemplate = `{ "asset": { "$ref": "#/definitions/entity.Asset" }, + "current_main_vault": { + "type": "integer", + "example": 1000 + }, + "current_supply": { + "type": "integer", + "example": 1000 + }, "date": { "type": "string", "example": "2023-08-10T14:30:00Z" @@ -1435,10 +2012,18 @@ const docTemplate = `{ "type": "string", "example": "Mint Asset" }, + "destination_pk": { + "type": "string", + "example": "GSDC..." + }, "log_id": { "type": "integer", "example": 1 }, + "origin_pk": { + "type": "string", + "example": "GSDC..." + }, "transaction_type_id": { "type": "integer", "example": 1 @@ -1449,6 +2034,23 @@ const docTemplate = `{ } } }, + "entity.Permission": { + "type": "object", + "properties": { + "description": { + "type": "string", + "example": "description" + }, + "id": { + "type": "integer", + "example": 1 + }, + "name": { + "type": "string", + "example": "name" + } + } + }, "entity.Role": { "type": "object", "properties": { @@ -1462,16 +2064,38 @@ const docTemplate = `{ } } }, + "entity.RoleDelete": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "example": 1 + }, + "new_users_role_id": { + "type": "integer", + "example": 1 + } + } + }, "entity.RolePermissionResponse": { "type": "object", "properties": { - "action": { - "type": "string", - "example": "Edit action" + "permission_id": { + "type": "integer", + "example": 1 }, + "role_id": { + "type": "string", + "example": "1" + } + } + }, + "entity.RoleRequest": { + "type": "object", + "properties": { "name": { "type": "string", - "example": "Edit" + "example": "Admin" } } }, @@ -1498,6 +2122,15 @@ const docTemplate = `{ "example": [ "2023-08-10T14:30:00Z" ] + }, + "quantity": { + "type": "array", + "items": { + "type": "integer" + }, + "example": [ + 1 + ] } } }, @@ -1530,6 +2163,19 @@ const docTemplate = `{ } } }, + "entity.UserPermissionResponse": { + "type": "object", + "properties": { + "action": { + "type": "string", + "example": "Edit action" + }, + "name": { + "type": "string", + "example": "Edit" + } + } + }, "entity.UserResponse": { "type": "object", "properties": { @@ -1633,6 +2279,14 @@ const docTemplate = `{ "type": "string", "example": "1000" }, + "current_main_vault": { + "type": "integer", + "example": 1000 + }, + "current_supply": { + "type": "integer", + "example": 1000 + }, "id": { "type": "string", "example": "001" @@ -1659,6 +2313,14 @@ const docTemplate = `{ "type": "string", "example": "USDC" }, + "current_main_vault": { + "type": "integer", + "example": 1000 + }, + "current_supply": { + "type": "integer", + "example": 1000 + }, "from": { "type": "string", "example": "GDKIJJIKXLOM2NRMPNQZUUYK24ZPVFC6426GZAICZ6E5PQG2MIPIMB2L" @@ -1778,7 +2440,28 @@ const docTemplate = `{ } }, "v1.CreateVaultRequest": { - "type": "object" + "type": "object", + "required": [ + "assets_id", + "name", + "vault_category_id" + ], + "properties": { + "assets_id": { + "type": "array", + "items": { + "type": "integer" + } + }, + "name": { + "type": "string", + "example": "Treasury" + }, + "vault_category_id": { + "type": "integer", + "example": 1 + } + } }, "v1.CreateWalletRequest": { "type": "object", @@ -1820,6 +2503,14 @@ const docTemplate = `{ "type": "string", "example": "USDC" }, + "current_main_vault": { + "type": "integer", + "example": 1000 + }, + "current_supply": { + "type": "integer", + "example": 1000 + }, "id": { "type": "string", "example": "12" @@ -1830,6 +2521,23 @@ const docTemplate = `{ } } }, + "v1.RolePermissionRequest": { + "type": "object", + "properties": { + "is_add": { + "type": "boolean", + "example": false + }, + "permission_id": { + "type": "integer", + "example": 1 + }, + "role_id": { + "type": "integer", + "example": 1 + } + } + }, "v1.TransferAssetRequest": { "type": "object", "required": [ @@ -1847,6 +2555,14 @@ const docTemplate = `{ "type": "string", "example": "12" }, + "current_main_vault": { + "type": "integer", + "example": 1000 + }, + "current_supply": { + "type": "integer", + "example": 1000 + }, "destination_wallet_pk": { "type": "string", "example": "GABCD...." diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json index c907af2e..e9286e9d 100644 --- a/backend/docs/swagger.json +++ b/backend/docs/swagger.json @@ -6,7 +6,7 @@ "paths": { "/": { "get": { - "description": "Get all vault categories", + "description": "Get contract", "consumes": [ "application/json" ], @@ -14,17 +14,14 @@ "application/json" ], "tags": [ - "Vault category" + "Contract" ], - "summary": "Get all vault categories", + "summary": "Get contract", "responses": { "200": { "description": "OK", "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/entity.VaultCategory" - } + "$ref": "#/definitions/entity.Contract" } }, "500": { @@ -661,6 +658,165 @@ } } }, + "/log_transactions/last_transactions/{transaction_type_id}": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get last transactions logs for a specific transaction type", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Log Transactions" + ], + "summary": "Get last transactions", + "parameters": [ + { + "type": "integer", + "description": "Transaction Type ID", + "name": "transaction_type_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/entity.LogTransaction" + } + } + } + } + }, + "/log_transactions/supply/{asset_id}/{time_range}/{time_frame}": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get sum of supply for a specific asset, grouped by a specified time frame (e.g., '1h' for 1 hour)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Log Transactions" + ], + "summary": "Get sum of supply by Asset ID within a specific time frame", + "parameters": [ + { + "type": "integer", + "description": "Asset ID", + "name": "asset_id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Time range for the query (e.g., '24h' or '1d' '7d' '30d')", + "name": "time_range", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Time frame for the query (e.g., '1h' '2h' '24h' '36h')", + "name": "time_frame", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/entity.SumLogTransaction" + } + }, + "400": { + "description": "Invalid time_frame format", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "string" + } + } + } + } + }, + "/log_transactions/supply/{time_range}/{time_frame}": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get sum of supply for all assets, grouped by a specified time frame (e.g., '1h' for 1 hour)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Log Transactions" + ], + "summary": "Get sum of supply for all assets within a specific time frame", + "parameters": [ + { + "type": "string", + "description": "Time range for the query (e.g., '24h' or '1d' '7d' '30d')", + "name": "time_range", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Time frame for the query (e.g., '1h' '2h' '24h' '36h')", + "name": "time_frame", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.SumLogTransaction" + } + } + }, + "400": { + "description": "Invalid time_frame format", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "string" + } + } + } + } + }, "/log_transactions/transaction_type/{transaction_type_id}": { "get": { "security": [ @@ -768,11 +924,133 @@ } } } + }, + "post": { + "description": "Create a new role", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Role" + ], + "summary": "Create a new role", + "parameters": [ + { + "description": "Role info", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.RoleRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/entity.RoleRequest" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/v1.response" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/v1.response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } + } + }, + "/role-permission": { + "put": { + "description": "Update roles permissions", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "RolesPermissions" + ], + "summary": "Update roles permissions", + "parameters": [ + { + "description": "Roles permissions information", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.RolePermissionRequest" + } + } + ], + "responses": { + "200": { + "description": "Updated roles permissions information", + "schema": { + "$ref": "#/definitions/v1.RolePermissionRequest" + } + }, + "400": { + "description": "Bad Request: Invalid input data", + "schema": { + "$ref": "#/definitions/v1.response" + } + }, + "500": { + "description": "Internal Server Error: Failed to update roles permissions", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } } }, "/role-permission/permissions": { "get": { - "description": "Role permissions", + "description": "permissions", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Permissions" + ], + "summary": "Permissions", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Permission" + } + } + } + } + } + }, + "/role-permission/role-permissions": { + "get": { + "description": "Roles permissions", "consumes": [ "application/json" ], @@ -782,23 +1060,227 @@ "tags": [ "RolePermissions" ], - "summary": "Role permissions", + "summary": "Roles permissions", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.RolePermissionResponse" + } + } + } + } + } + }, + "/role-permission/user-permissions": { + "get": { + "description": "User permissions", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "RolePermissions" + ], + "summary": "User permissions", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.UserPermissionResponse" + } + } + } + } + } + }, + "/role/{id}": { + "put": { + "description": "Update a role by providing the Role ID and the updated information.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Role" + ], + "summary": "Update a role", + "parameters": [ + { + "type": "string", + "format": "uuid", + "description": "Role ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Role info", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.RoleRequest" + } + } + ], + "responses": { + "200": { + "description": "Updated role information", + "schema": { + "$ref": "#/definitions/entity.Role" + } + }, + "400": { + "description": "Bad Request: Invalid input data", + "schema": { + "$ref": "#/definitions/v1.response" + } + }, + "404": { + "description": "Not Found: Role not found", + "schema": { + "$ref": "#/definitions/v1.response" + } + }, + "500": { + "description": "Internal Server Error: Failed to update role", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } + }, + "delete": { + "description": "Delete a role by providing the Role ID and the updated information.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Role" + ], + "summary": "Delete a role", + "parameters": [ + { + "type": "string", + "format": "uuid", + "description": "Role ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Role info", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.RoleRequest" + } + } + ], + "responses": { + "200": { + "description": "Updated role information", + "schema": { + "$ref": "#/definitions/entity.RoleDelete" + } + }, + "400": { + "description": "Bad Request: Invalid input data", + "schema": { + "$ref": "#/definitions/v1.response" + } + }, + "404": { + "description": "Not Found: Role not found", + "schema": { + "$ref": "#/definitions/v1.response" + } + }, + "500": { + "description": "Internal Server Error: Failed to delete role", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } + } + }, + "/user/create": { + "post": { + "description": "Create user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Create user", + "operationId": "create", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.userResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } + } + }, + "/user/login": { + "post": { + "description": "Autentication User", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Autentication User", + "operationId": "autentication", "responses": { "200": { "description": "OK", "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/entity.RolePermissionResponse" - } + "$ref": "#/definitions/v1.userResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/v1.response" } } } } }, - "/user/create": { + "/user/logout": { "post": { - "description": "Edit users role", + "description": "Logout User", "consumes": [ "application/json" ], @@ -808,13 +1290,13 @@ "tags": [ "user" ], - "summary": "Edit users role", - "operationId": "editUsersRole", + "summary": "Logout User", + "operationId": "logout", "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/entity.UserRole" + "$ref": "#/definitions/v1.userResponse" } }, "500": { @@ -826,9 +1308,9 @@ } } }, - "/user/login": { + "/users/edit-users-role": { "post": { - "description": "Autentication User", + "description": "Edit users role", "consumes": [ "application/json" ], @@ -838,13 +1320,13 @@ "tags": [ "user" ], - "summary": "Autentication User", - "operationId": "autentication", + "summary": "Edit users role", + "operationId": "editUsersRole", "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/v1.userResponse" + "$ref": "#/definitions/entity.UserRole" } }, "500": { @@ -856,9 +1338,9 @@ } } }, - "/user/logout": { - "post": { - "description": "Logout User", + "/users/list-users": { + "get": { + "description": "List users", "consumes": [ "application/json" ], @@ -868,25 +1350,21 @@ "tags": [ "user" ], - "summary": "Logout User", - "operationId": "logout", + "summary": "GET All Users", "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/v1.userResponse" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/v1.response" + "type": "array", + "items": { + "$ref": "#/definitions/entity.UserResponse" + } } } } } }, - "/users": { + "/users/profile": { "get": { "description": "Get PRofile", "consumes": [ @@ -1022,6 +1500,36 @@ } }, "/vault-category": { + "get": { + "description": "Get all vault categories", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Vault category" + ], + "summary": "Get all vault categories", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.VaultCategory" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } + }, "post": { "description": "Create and issue a new asset on Stellar", "consumes": [ @@ -1184,6 +1692,67 @@ } } }, + "/vault/list": { + "get": { + "description": "Get all vault", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Vault" + ], + "summary": "Get all vault", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Vault" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } + } + }, + "/vault/{id}": { + "get": { + "description": "Get vault", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Vault" + ], + "summary": "Get vault", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/entity.Vault" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/v1.response" + } + } + } + } + }, "/wallets": { "get": { "description": "List wallets by type", @@ -1415,6 +1984,14 @@ "asset": { "$ref": "#/definitions/entity.Asset" }, + "current_main_vault": { + "type": "integer", + "example": 1000 + }, + "current_supply": { + "type": "integer", + "example": 1000 + }, "date": { "type": "string", "example": "2023-08-10T14:30:00Z" @@ -1423,10 +2000,18 @@ "type": "string", "example": "Mint Asset" }, + "destination_pk": { + "type": "string", + "example": "GSDC..." + }, "log_id": { "type": "integer", "example": 1 }, + "origin_pk": { + "type": "string", + "example": "GSDC..." + }, "transaction_type_id": { "type": "integer", "example": 1 @@ -1437,6 +2022,23 @@ } } }, + "entity.Permission": { + "type": "object", + "properties": { + "description": { + "type": "string", + "example": "description" + }, + "id": { + "type": "integer", + "example": 1 + }, + "name": { + "type": "string", + "example": "name" + } + } + }, "entity.Role": { "type": "object", "properties": { @@ -1450,16 +2052,38 @@ } } }, + "entity.RoleDelete": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "example": 1 + }, + "new_users_role_id": { + "type": "integer", + "example": 1 + } + } + }, "entity.RolePermissionResponse": { "type": "object", "properties": { - "action": { - "type": "string", - "example": "Edit action" + "permission_id": { + "type": "integer", + "example": 1 }, + "role_id": { + "type": "string", + "example": "1" + } + } + }, + "entity.RoleRequest": { + "type": "object", + "properties": { "name": { "type": "string", - "example": "Edit" + "example": "Admin" } } }, @@ -1486,6 +2110,15 @@ "example": [ "2023-08-10T14:30:00Z" ] + }, + "quantity": { + "type": "array", + "items": { + "type": "integer" + }, + "example": [ + 1 + ] } } }, @@ -1518,6 +2151,19 @@ } } }, + "entity.UserPermissionResponse": { + "type": "object", + "properties": { + "action": { + "type": "string", + "example": "Edit action" + }, + "name": { + "type": "string", + "example": "Edit" + } + } + }, "entity.UserResponse": { "type": "object", "properties": { @@ -1621,6 +2267,14 @@ "type": "string", "example": "1000" }, + "current_main_vault": { + "type": "integer", + "example": 1000 + }, + "current_supply": { + "type": "integer", + "example": 1000 + }, "id": { "type": "string", "example": "001" @@ -1647,6 +2301,14 @@ "type": "string", "example": "USDC" }, + "current_main_vault": { + "type": "integer", + "example": 1000 + }, + "current_supply": { + "type": "integer", + "example": 1000 + }, "from": { "type": "string", "example": "GDKIJJIKXLOM2NRMPNQZUUYK24ZPVFC6426GZAICZ6E5PQG2MIPIMB2L" @@ -1766,7 +2428,28 @@ } }, "v1.CreateVaultRequest": { - "type": "object" + "type": "object", + "required": [ + "assets_id", + "name", + "vault_category_id" + ], + "properties": { + "assets_id": { + "type": "array", + "items": { + "type": "integer" + } + }, + "name": { + "type": "string", + "example": "Treasury" + }, + "vault_category_id": { + "type": "integer", + "example": 1 + } + } }, "v1.CreateWalletRequest": { "type": "object", @@ -1808,6 +2491,14 @@ "type": "string", "example": "USDC" }, + "current_main_vault": { + "type": "integer", + "example": 1000 + }, + "current_supply": { + "type": "integer", + "example": 1000 + }, "id": { "type": "string", "example": "12" @@ -1818,6 +2509,23 @@ } } }, + "v1.RolePermissionRequest": { + "type": "object", + "properties": { + "is_add": { + "type": "boolean", + "example": false + }, + "permission_id": { + "type": "integer", + "example": 1 + }, + "role_id": { + "type": "integer", + "example": 1 + } + } + }, "v1.TransferAssetRequest": { "type": "object", "required": [ @@ -1835,6 +2543,14 @@ "type": "string", "example": "12" }, + "current_main_vault": { + "type": "integer", + "example": 1000 + }, + "current_supply": { + "type": "integer", + "example": 1000 + }, "destination_wallet_pk": { "type": "string", "example": "GABCD...." diff --git a/backend/docs/swagger.yaml b/backend/docs/swagger.yaml index 5cf810a8..be9ea3bf 100644 --- a/backend/docs/swagger.yaml +++ b/backend/docs/swagger.yaml @@ -67,15 +67,27 @@ definitions: type: number asset: $ref: '#/definitions/entity.Asset' + current_main_vault: + example: 1000 + type: integer + current_supply: + example: 1000 + type: integer date: example: "2023-08-10T14:30:00Z" type: string description: example: Mint Asset type: string + destination_pk: + example: GSDC... + type: string log_id: example: 1 type: integer + origin_pk: + example: GSDC... + type: string transaction_type_id: example: 1 type: integer @@ -83,6 +95,18 @@ definitions: example: 42 type: integer type: object + entity.Permission: + properties: + description: + example: description + type: string + id: + example: 1 + type: integer + name: + example: name + type: string + type: object entity.Role: properties: id: @@ -92,13 +116,28 @@ definitions: example: Admin type: string type: object + entity.RoleDelete: + properties: + id: + example: 1 + type: integer + new_users_role_id: + example: 1 + type: integer + type: object entity.RolePermissionResponse: properties: - action: - example: Edit action + permission_id: + example: 1 + type: integer + role_id: + example: "1" type: string + type: object + entity.RoleRequest: + properties: name: - example: Edit + example: Admin type: string type: object entity.SumLogTransaction: @@ -117,6 +156,12 @@ definitions: items: type: string type: array + quantity: + example: + - 1 + items: + type: integer + type: array type: object entity.User: properties: @@ -137,6 +182,15 @@ definitions: updated_at: type: string type: object + entity.UserPermissionResponse: + properties: + action: + example: Edit action + type: string + name: + example: Edit + type: string + type: object entity.UserResponse: properties: email: @@ -204,6 +258,12 @@ definitions: amount: example: "1000" type: string + current_main_vault: + example: 1000 + type: integer + current_supply: + example: 1000 + type: integer id: example: "001" type: string @@ -222,6 +282,12 @@ definitions: code: example: USDC type: string + current_main_vault: + example: 1000 + type: integer + current_supply: + example: 1000 + type: integer from: example: GDKIJJIKXLOM2NRMPNQZUUYK24ZPVFC6426GZAICZ6E5PQG2MIPIMB2L type: string @@ -314,6 +380,21 @@ definitions: - name type: object v1.CreateVaultRequest: + properties: + assets_id: + items: + type: integer + type: array + name: + example: Treasury + type: string + vault_category_id: + example: 1 + type: integer + required: + - assets_id + - name + - vault_category_id type: object v1.CreateWalletRequest: properties: @@ -339,6 +420,12 @@ definitions: code: example: USDC type: string + current_main_vault: + example: 1000 + type: integer + current_supply: + example: 1000 + type: integer id: example: "12" type: string @@ -350,6 +437,18 @@ definitions: - code - id type: object + v1.RolePermissionRequest: + properties: + is_add: + example: false + type: boolean + permission_id: + example: 1 + type: integer + role_id: + example: 1 + type: integer + type: object v1.TransferAssetRequest: properties: amount: @@ -358,6 +457,12 @@ definitions: asset_id: example: "12" type: string + current_main_vault: + example: 1000 + type: integer + current_supply: + example: 1000 + type: integer destination_wallet_pk: example: GABCD.... type: string @@ -453,23 +558,21 @@ paths: get: consumes: - application/json - description: Get all vault categories + description: Get contract produces: - application/json responses: "200": description: OK schema: - items: - $ref: '#/definitions/entity.VaultCategory' - type: array + $ref: '#/definitions/entity.Contract' "500": description: Internal Server Error schema: $ref: '#/definitions/v1.response' - summary: Get all vault categories + summary: Get contract tags: - - Vault category + - Contract /asset: get: consumes: @@ -879,6 +982,110 @@ paths: summary: Get sum of amounts for all assets within a specific time frame tags: - Log Transactions + /log_transactions/last_transactions/{transaction_type_id}: + get: + consumes: + - application/json + description: Get last transactions logs for a specific transaction type + parameters: + - description: Transaction Type ID + in: path + name: transaction_type_id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/entity.LogTransaction' + security: + - ApiKeyAuth: [] + summary: Get last transactions + tags: + - Log Transactions + /log_transactions/supply/{asset_id}/{time_range}/{time_frame}: + get: + consumes: + - application/json + description: Get sum of supply for a specific asset, grouped by a specified + time frame (e.g., '1h' for 1 hour) + parameters: + - description: Asset ID + in: path + name: asset_id + required: true + type: integer + - description: Time range for the query (e.g., '24h' or '1d' '7d' '30d') + in: path + name: time_range + required: true + type: string + - description: Time frame for the query (e.g., '1h' '2h' '24h' '36h') + in: path + name: time_frame + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/entity.SumLogTransaction' + "400": + description: Invalid time_frame format + schema: + type: string + "500": + description: Internal server error + schema: + type: string + security: + - ApiKeyAuth: [] + summary: Get sum of supply by Asset ID within a specific time frame + tags: + - Log Transactions + /log_transactions/supply/{time_range}/{time_frame}: + get: + consumes: + - application/json + description: Get sum of supply for all assets, grouped by a specified time frame + (e.g., '1h' for 1 hour) + parameters: + - description: Time range for the query (e.g., '24h' or '1d' '7d' '30d') + in: path + name: time_range + required: true + type: string + - description: Time frame for the query (e.g., '1h' '2h' '24h' '36h') + in: path + name: time_frame + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.SumLogTransaction' + type: array + "400": + description: Invalid time_frame format + schema: + type: string + "500": + description: Internal server error + schema: + type: string + security: + - ApiKeyAuth: [] + summary: Get sum of supply for all assets within a specific time frame + tags: + - Log Transactions /log_transactions/transaction_type/{transaction_type_id}: get: consumes: @@ -948,11 +1155,91 @@ paths: summary: List tags: - Role + post: + consumes: + - application/json + description: Create a new role + parameters: + - description: Role info + in: body + name: request + required: true + schema: + $ref: '#/definitions/entity.RoleRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/entity.RoleRequest' + "400": + description: Bad Request + schema: + $ref: '#/definitions/v1.response' + "404": + description: Not Found + schema: + $ref: '#/definitions/v1.response' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/v1.response' + summary: Create a new role + tags: + - Role + /role-permission: + put: + consumes: + - application/json + description: Update roles permissions + parameters: + - description: Roles permissions information + in: body + name: request + required: true + schema: + $ref: '#/definitions/v1.RolePermissionRequest' + produces: + - application/json + responses: + "200": + description: Updated roles permissions information + schema: + $ref: '#/definitions/v1.RolePermissionRequest' + "400": + description: 'Bad Request: Invalid input data' + schema: + $ref: '#/definitions/v1.response' + "500": + description: 'Internal Server Error: Failed to update roles permissions' + schema: + $ref: '#/definitions/v1.response' + summary: Update roles permissions + tags: + - RolesPermissions /role-permission/permissions: get: consumes: - application/json - description: Role permissions + description: permissions + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Permission' + type: array + summary: Permissions + tags: + - Permissions + /role-permission/role-permissions: + get: + consumes: + - application/json + description: Roles permissions produces: - application/json responses: @@ -962,27 +1249,123 @@ paths: items: $ref: '#/definitions/entity.RolePermissionResponse' type: array - summary: Role permissions + summary: Roles permissions tags: - RolePermissions + /role-permission/user-permissions: + get: + consumes: + - application/json + description: User permissions + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.UserPermissionResponse' + type: array + summary: User permissions + tags: + - RolePermissions + /role/{id}: + delete: + consumes: + - application/json + description: Delete a role by providing the Role ID and the updated information. + parameters: + - description: Role ID + format: uuid + in: path + name: id + required: true + type: string + - description: Role info + in: body + name: request + required: true + schema: + $ref: '#/definitions/entity.RoleRequest' + produces: + - application/json + responses: + "200": + description: Updated role information + schema: + $ref: '#/definitions/entity.RoleDelete' + "400": + description: 'Bad Request: Invalid input data' + schema: + $ref: '#/definitions/v1.response' + "404": + description: 'Not Found: Role not found' + schema: + $ref: '#/definitions/v1.response' + "500": + description: 'Internal Server Error: Failed to delete role' + schema: + $ref: '#/definitions/v1.response' + summary: Delete a role + tags: + - Role + put: + consumes: + - application/json + description: Update a role by providing the Role ID and the updated information. + parameters: + - description: Role ID + format: uuid + in: path + name: id + required: true + type: string + - description: Role info + in: body + name: request + required: true + schema: + $ref: '#/definitions/entity.RoleRequest' + produces: + - application/json + responses: + "200": + description: Updated role information + schema: + $ref: '#/definitions/entity.Role' + "400": + description: 'Bad Request: Invalid input data' + schema: + $ref: '#/definitions/v1.response' + "404": + description: 'Not Found: Role not found' + schema: + $ref: '#/definitions/v1.response' + "500": + description: 'Internal Server Error: Failed to update role' + schema: + $ref: '#/definitions/v1.response' + summary: Update a role + tags: + - Role /user/create: post: consumes: - application/json - description: Edit users role - operationId: editUsersRole + description: Create user + operationId: create produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/entity.UserRole' + $ref: '#/definitions/v1.userResponse' "500": description: Internal Server Error schema: $ref: '#/definitions/v1.response' - summary: Edit users role + summary: Create user tags: - user /user/login: @@ -1025,7 +1408,44 @@ paths: summary: Logout User tags: - user - /users: + /users/edit-users-role: + post: + consumes: + - application/json + description: Edit users role + operationId: editUsersRole + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/entity.UserRole' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/v1.response' + summary: Edit users role + tags: + - user + /users/list-users: + get: + consumes: + - application/json + description: List users + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.UserResponse' + type: array + summary: GET All Users + tags: + - user + /users/profile: get: consumes: - application/json @@ -1115,6 +1535,26 @@ paths: tags: - Vault /vault-category: + get: + consumes: + - application/json + description: Get all vault categories + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.VaultCategory' + type: array + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/v1.response' + summary: Get all vault categories + tags: + - Vault category post: consumes: - application/json @@ -1223,6 +1663,46 @@ paths: summary: Update a vault status tags: - Vault + /vault/{id}: + get: + consumes: + - application/json + description: Get vault + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/entity.Vault' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/v1.response' + summary: Get vault + tags: + - Vault + /vault/list: + get: + consumes: + - application/json + description: Get all vault + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Vault' + type: array + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/v1.response' + summary: Get all vault + tags: + - Vault /wallets: get: consumes: diff --git a/backend/internal/controller/http/v1/log_transaction.go b/backend/internal/controller/http/v1/log_transaction.go index e4231713..065874e7 100644 --- a/backend/internal/controller/http/v1/log_transaction.go +++ b/backend/internal/controller/http/v1/log_transaction.go @@ -29,6 +29,9 @@ func newLogTransactionsRoutes(handler *gin.RouterGroup, w usecase.WalletUseCase, h.GET("/assets/:asset_id/type/:transaction_type_id/sum/:time_range/:time_frame", r.sumAmountsByAssetID) h.GET("/assets/sum/:time_range/:time_frame", r.sumAmountsForAllAssets) h.GET("/last-transactions/:transaction_type_id", r.getLastLogTransactions) + h.GET("/supply/:asset_id/sum/:time_range/:time_frame", r.sumSupplyByAssetID) + h.GET("/supply/sum/:time_range/:time_frame", r.sumSupplyForAllAssets) + } } @@ -244,3 +247,73 @@ func (r *logTransactionsRoutes) getLastLogTransactions(c *gin.Context) { c.JSON(http.StatusOK, logTransactions) } + +// @Summary Get sum of supply by Asset ID within a specific time frame +// @Description Get sum of supply for a specific asset, grouped by a specified time frame (e.g., '1h' for 1 hour) +// @Tags Log Transactions +// @Accept json +// @Produce json +// @Param asset_id path int true "Asset ID" +// @Param time_range path string true "Time range for the query (e.g., '24h' or '1d' '7d' '30d')" +// @Param time_frame path string true "Time frame for the query (e.g., '1h' '2h' '24h' '36h')" +// @Security ApiKeyAuth +// @Success 200 {object} entity.SumLogTransaction +// @Failure 400 {string} string "Invalid time_frame format" +// @Failure 500 {string} string "Internal server error" +// @Router /log_transactions/supply/{asset_id}/{time_range}/{time_frame} [get] +func (r *logTransactionsRoutes) sumSupplyByAssetID(c *gin.Context) { + assetIDStr := c.Param("asset_id") + timeRange := c.Param("time_range") + timeFrame := c.Param("time_frame") + + duration, err := time.ParseDuration(timeFrame) + if err != nil { + errorResponse(c, http.StatusBadRequest, "Invalid time_frame format", err) + return + } + + assetID, err := strconv.Atoi(assetIDStr) + if err != nil { + errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid asset ID: %s", err.Error()), err) + return + } + + sum, err := r.l.SumLogTransactionsSupplyByAssetID(assetID, timeRange, duration) + if err != nil { + errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()), err) + return + } + + c.JSON(http.StatusOK, sum) +} + +// @Summary Get sum of supply for all assets within a specific time frame +// @Description Get sum of supply for all assets, grouped by a specified time frame (e.g., '1h' for 1 hour) +// @Tags Log Transactions +// @Accept json +// @Produce json +// @Param time_range path string true "Time range for the query (e.g., '24h' or '1d' '7d' '30d')" +// @Param time_frame path string true "Time frame for the query (e.g., '1h' '2h' '24h' '36h')" +// @Security ApiKeyAuth +// @Success 200 {array} entity.SumLogTransaction +// @Failure 400 {string} string "Invalid time_frame format" +// @Failure 500 {string} string "Internal server error" +// @Router /log_transactions/supply/{time_range}/{time_frame} [get] +func (r *logTransactionsRoutes) sumSupplyForAllAssets(c *gin.Context) { + timeRange := c.Param("time_range") + timeFrame := c.Param("time_frame") + + duration, err := time.ParseDuration(timeFrame) + if err != nil { + errorResponse(c, http.StatusBadRequest, "Invalid time_frame format", err) + return + } + + sum, err := r.l.SumLogTransactionsSupply(timeRange, duration) + if err != nil { + errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()), err) + return + } + + c.JSON(http.StatusOK, sum) +} diff --git a/backend/internal/controller/http/v1/role.go b/backend/internal/controller/http/v1/role.go index f5f350f0..72409484 100644 --- a/backend/internal/controller/http/v1/role.go +++ b/backend/internal/controller/http/v1/role.go @@ -33,7 +33,7 @@ func newRoleRoutes(handler *gin.RouterGroup, roleUseCase usecase.RoleUseCase, me // @Tags Role // @Accept json // @Produce json -// @Param type query string true "Type" +// @Param type query string true "Type" // @Success 200 {object} []entity.Role // @Router /role [get] func (r *role) list(c *gin.Context) { @@ -49,7 +49,7 @@ func (r *role) list(c *gin.Context) { // @Tags Role // @Accept json // @Produce json -// @Param request body RoleRequest true "Role info" +// @Param request body entity.RoleRequest true "Role info" // @Success 200 {object} entity.RoleRequest // @Failure 400 {object} response // @Failure 404 {object} response @@ -80,7 +80,7 @@ func (r *role) createRole(c *gin.Context) { // @Accept json // @Produce json // @Param id path string true "Role ID" Format(uuid) -// @Param request body RoleRequest true "Role info" +// @Param request body entity.RoleRequest true "Role info" // @Success 200 {object} entity.Role "Updated role information" // @Failure 400 {object} response "Bad Request: Invalid input data" // @Failure 404 {object} response "Not Found: Role not found" @@ -130,7 +130,7 @@ func (r *role) updateRole(c *gin.Context) { // @Accept json // @Produce json // @Param id path string true "Role ID" Format(uuid) -// @Param request body RoleRequest true "Role info" +// @Param request body entity.RoleRequest true "Role info" // @Success 200 {object} entity.RoleDelete "Updated role information" // @Failure 400 {object} response "Bad Request: Invalid input data" // @Failure 404 {object} response "Not Found: Role not found" diff --git a/backend/internal/controller/http/v1/role_permissions.go b/backend/internal/controller/http/v1/role_permissions.go index f0ca2697..1bcbad97 100644 --- a/backend/internal/controller/http/v1/role_permissions.go +++ b/backend/internal/controller/http/v1/role_permissions.go @@ -86,13 +86,12 @@ func (r *rolePermissions) permissions(c *gin.Context) { // @Tags RolesPermissions // @Accept json // @Produce json -// @Param request body RolePermissionRequest -// @Success 200 {object} entity.RolePermissionRequest "Updated roles permissions information" +// @Param request body RolePermissionRequest true "Roles permissions information" +// @Success 200 {object} RolePermissionRequest "Updated roles permissions information" // @Failure 400 {object} response "Bad Request: Invalid input data" // @Failure 500 {object} response "Internal Server Error: Failed to update roles permissions" // @Router /role-permission [put] func (r *rolePermissions) updateRolesPermissions(c *gin.Context) { - var request []RolePermissionRequest if err := c.ShouldBindJSON(&request); err != nil { errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err) diff --git a/backend/internal/controller/http/v1/users.go b/backend/internal/controller/http/v1/users.go index 9e99aaca..fb4540f8 100644 --- a/backend/internal/controller/http/v1/users.go +++ b/backend/internal/controller/http/v1/users.go @@ -168,7 +168,7 @@ func (r *usersRoutes) logout(c *gin.Context) { // @Accept json // @Produce json // @Success 200 {object} []entity.UserResponse -// @Router /users [get] +// @Router /users/list-users [get] func (r *usersRoutes) getAllUsers(c *gin.Context) { users, err := r.t.GetAllUsers() fmt.Println(users) @@ -190,7 +190,7 @@ func (r *usersRoutes) getAllUsers(c *gin.Context) { // @Produce json // @Success 200 {object} entity.UserRole // @Failure 500 {object} response -// @Router /user/create [post] +// @Router /users/edit-users-role [post] func (r *usersRoutes) editUsersRole(c *gin.Context) { var userRole entity.UserRole if err := c.ShouldBindJSON(&userRole); err != nil { @@ -217,7 +217,7 @@ func (r *usersRoutes) editUsersRole(c *gin.Context) { // @Accept json // @Produce json // @Success 200 {object} entity.UserResponse -// @Router /users [get] +// @Router /users/profile [get] func (r *usersRoutes) getProfile(c *gin.Context) { token := c.GetHeader("Authorization") profile, err := r.t.GetProfile(token) diff --git a/backend/internal/controller/http/v1/vault.go b/backend/internal/controller/http/v1/vault.go index 46df7cd1..4e1b9b4e 100644 --- a/backend/internal/controller/http/v1/vault.go +++ b/backend/internal/controller/http/v1/vault.go @@ -37,7 +37,7 @@ func newVaultRoutes(handler *gin.RouterGroup, m HTTPControllerMessenger, a useca type CreateVaultRequest struct { Name string `json:"name" binding:"required" example:"Treasury"` VaultCategoryId int `json:"vault_category_id" binding:"required" example:"1"` - AssetsId []int `json:"assets_id" binding:"required" example:"[1,2]"` + AssetsId []int `json:"assets_id" binding:"required"` } type UpdateVaultCategoryRequest struct { @@ -173,7 +173,7 @@ func (r *vaultRoutes) createVault(c *gin.Context) { // @Produce json // @Success 200 {object} []entity.Vault // @Failure 500 {object} response -// @Router / [get] +// @Router /vault/list [get] func (r *vaultRoutes) getAllVaults(c *gin.Context) { vault, err := r.v.GetAll() if err != nil { @@ -191,7 +191,7 @@ func (r *vaultRoutes) getAllVaults(c *gin.Context) { // @Produce json // @Success 200 {object} entity.Vault // @Failure 500 {object} response -// @Router / [get] +// @Router /vault/{id} [get] func (r *vaultRoutes) getVaultById(c *gin.Context) { idStr := c.Param("id") id, err := strconv.Atoi(idStr) diff --git a/backend/internal/controller/http/v1/vault_category.go b/backend/internal/controller/http/v1/vault_category.go index 9cc51491..9c12454f 100644 --- a/backend/internal/controller/http/v1/vault_category.go +++ b/backend/internal/controller/http/v1/vault_category.go @@ -70,7 +70,7 @@ func (r *vaultCategoryRoutes) createVaultCategory(c *gin.Context) { // @Produce json // @Success 200 {object} []entity.VaultCategory // @Failure 500 {object} response -// @Router / [get] +// @Router /vault-category [get] func (r *vaultCategoryRoutes) getAllVaultCategories(c *gin.Context) { vaultCategories, err := r.vc.GetAll() if err != nil { diff --git a/backend/internal/entity/transaction_log.go b/backend/internal/entity/transaction_log.go index 8e899445..17df7b41 100644 --- a/backend/internal/entity/transaction_log.go +++ b/backend/internal/entity/transaction_log.go @@ -21,6 +21,13 @@ type SumLogTransaction struct { Quantity []int `json:"quantity" example:"1"` } +type SumLogTransactionSupply struct { + Asset Asset `json:"asset"` + CurrentSupply []int `json:"current_supply" example:"1000"` + CurrentyMainVault []int `json:"current_main_vault" example:"1000"` + Date []string `json:"date" example:"2023-08-10T14:30:00Z"` +} + const ( CreateAsset int = iota + 1 // CreateAsset = 1 MintAsset // MintAsset = 2 diff --git a/backend/internal/usecase/interfaces.go b/backend/internal/usecase/interfaces.go index 0de5d9ef..02486f03 100644 --- a/backend/internal/usecase/interfaces.go +++ b/backend/internal/usecase/interfaces.go @@ -96,5 +96,7 @@ type ( SumLogTransactionsByAssetID(assetID int, timeRange string, timeFrame time.Duration, transactionType int) (entity.SumLogTransaction, error) SumLogTransactions(timeRange string, timeFrame time.Duration) ([]entity.SumLogTransaction, error) GetLastLogTransactions(transactionTypeID int) ([]entity.LogTransaction, error) + SumLogTransactionSupply(timeRange string, timeFrame time.Duration) ([]entity.SumLogTransactionSupply, error) + SumLogTransactionSupplyByAssetID(assetID int, timeRange string, timeFrame time.Duration) (entity.SumLogTransactionSupply, error) } ) diff --git a/backend/internal/usecase/log_transaction.go b/backend/internal/usecase/log_transaction.go index 4116062c..cc9e191b 100644 --- a/backend/internal/usecase/log_transaction.go +++ b/backend/internal/usecase/log_transaction.go @@ -77,3 +77,19 @@ func (l *LogTransactionUseCase) GetLastLogTransactions(transactionTypeID int) ([ } return logTransactions, nil } + +func (l *LogTransactionUseCase) SumLogTransactionsSupply(timeRange string, timeFrame time.Duration) ([]entity.SumLogTransactionSupply, error) { + sum, err := l.lRepo.SumLogTransactionSupply(timeRange, timeFrame) + if err != nil { + return []entity.SumLogTransactionSupply{}, err + } + return sum, nil +} + +func (l *LogTransactionUseCase) SumLogTransactionsSupplyByAssetID(assetID int, timeRange string, duration time.Duration) (entity.SumLogTransactionSupply, error) { + sum, err := l.lRepo.SumLogTransactionSupplyByAssetID(assetID, timeRange, duration) + if err != nil { + return entity.SumLogTransactionSupply{}, err + } + return sum, nil +} diff --git a/backend/internal/usecase/repo/log_transaction_postgres.go b/backend/internal/usecase/repo/log_transaction_postgres.go index fd1264f8..e10a3fff 100644 --- a/backend/internal/usecase/repo/log_transaction_postgres.go +++ b/backend/internal/usecase/repo/log_transaction_postgres.go @@ -172,7 +172,8 @@ func getLogTransactions(repo *LogTransactionRepo, timeRange string, whereClause return nil, err } query := ` - SELECT lt.log_id, lt.user_id, lt.transaction_type_id, a.id, a.name, a.code, a.distributor_id, a.issuer_id, a.asset_type, lt.amount, lt.date, lt.description + SELECT lt.log_id, lt.user_id, lt.transaction_type_id, a.id, a.name, a.code, a.distributor_id, a.issuer_id, a.asset_type, lt.amount, lt.date, + lt.description ,lt.current_supply, lt.current_main_vault FROM logtransactions AS lt JOIN Asset AS a ON lt.asset_id = a.id WHERE lt.date >= $1 ` + whereClause + ` @@ -189,7 +190,7 @@ func getLogTransactions(repo *LogTransactionRepo, timeRange string, whereClause for rows.Next() { var log entity.LogTransaction var distributorID, issuerID int - err := rows.Scan(&log.LogID, &log.UserID, &log.TransactionTypeID, &log.Asset.Id, &log.Asset.Name, &log.Asset.Code, &distributorID, &issuerID, &log.Asset.AssetType, &log.Amount, &log.Date, &log.Description) + err := rows.Scan(&log.LogID, &log.UserID, &log.TransactionTypeID, &log.Asset.Id, &log.Asset.Name, &log.Asset.Code, &distributorID, &issuerID, &log.Asset.AssetType, &log.Amount, &log.Date, &log.Description, &log.CurrentSupply, &log.CurrentMainVault) if err != nil { return nil, err } @@ -229,7 +230,7 @@ func getDateFilter(timeRange string) (time.Time, error) { func (repo *LogTransactionRepo) GetLastLogTransactions(transactionTypeID int) ([]entity.LogTransaction, error) { query := ` SELECT lt.log_id, lt.user_id, lt.transaction_type_id, a.id, a.name, a.code, a.distributor_id, a.issuer_id, a.asset_type, lt.amount, lt.date, lt.description, - lt.origin_pk, lt.destination_pk + lt.origin_pk, lt.destination_pk, lt.current_supply, lt.current_main_vault FROM logtransactions AS lt JOIN Asset AS a ON lt.asset_id = a.id WHERE lt.transaction_type_id = $1 @@ -248,7 +249,7 @@ func (repo *LogTransactionRepo) GetLastLogTransactions(transactionTypeID int) ([ var log entity.LogTransaction var distributorID, issuerID int err := rows.Scan(&log.LogID, &log.UserID, &log.TransactionTypeID, &log.Asset.Id, &log.Asset.Name, &log.Asset.Code, &distributorID, &issuerID, &log.Asset.AssetType, &log.Amount, &log.Date, - &log.Description, &log.OriginPK, &log.DestinationPK) + &log.Description, &log.OriginPK, &log.DestinationPK, &log.CurrentSupply, &log.CurrentMainVault) if err != nil { return nil, err } @@ -271,3 +272,103 @@ func getTimeFrame(timeFrame time.Duration) string { } return timeFrameUnit } + +func (repo *LogTransactionRepo) SumLogTransactionSupply(timeRange string, timeFrame time.Duration) ([]entity.SumLogTransactionSupply, error) { + dateFilter, err := getDateFilter(timeRange) + if err != nil { + return []entity.SumLogTransactionSupply{}, err + } + + timeFrameUnit := getTimeFrame(timeFrame) + timeFrameSeconds := timeFrame.Seconds() + + query := ` + SELECT a.id, a.name, a.code, a.asset_type, SUM(lt.current_supply), SUM(lt.current_main_vault), + DATE_TRUNC($2, TIMESTAMP 'epoch' + INTERVAL '1 second' * floor(EXTRACT(EPOCH FROM lt.date)/$3) * $3) as dateFrame + FROM logtransactions AS lt + JOIN asset AS a ON lt.asset_id = a.id + WHERE lt.date >= $1 + GROUP BY a.id, dateFrame + ORDER BY a.id, dateFrame; + ` + + rows, err := repo.Db.Query(query, dateFilter, timeFrameUnit, timeFrameSeconds) + if err != nil { + return nil, err + } + defer rows.Close() + + var sums []entity.SumLogTransactionSupply + var currentAsset entity.Asset + var sumLogTransactionSupply entity.SumLogTransactionSupply + for rows.Next() { + var asset entity.Asset + var currentSupply, currentMainVault int + var date string + err := rows.Scan(&asset.Id, &asset.Name, &asset.Code, &asset.AssetType, ¤tSupply, ¤tMainVault, &date) + if err != nil { + return nil, err + } + + if asset.Id != currentAsset.Id && currentAsset.Id != 0 { + sums = append(sums, sumLogTransactionSupply) + sumLogTransactionSupply = entity.SumLogTransactionSupply{} + } + + sumLogTransactionSupply.Asset = asset + sumLogTransactionSupply.CurrentSupply = append(sumLogTransactionSupply.CurrentSupply, currentSupply) + sumLogTransactionSupply.CurrentyMainVault = append(sumLogTransactionSupply.CurrentyMainVault, currentMainVault) + sumLogTransactionSupply.Date = append(sumLogTransactionSupply.Date, date) + currentAsset = asset + } + + if currentAsset.Id != 0 { + sums = append(sums, sumLogTransactionSupply) + } + + return sums, nil +} + +func (repo *LogTransactionRepo) SumLogTransactionSupplyByAssetID(assetID int, timeRange string, timeFrame time.Duration) (entity.SumLogTransactionSupply, error) { + dateFilter, err := getDateFilter(timeRange) + if err != nil { + return entity.SumLogTransactionSupply{}, err + } + + timeFrameUnit := getTimeFrame(timeFrame) + timeFrameSeconds := timeFrame.Seconds() + + query := ` + SELECT a.id, a.name, a.code, a.asset_type, SUM(lt.current_supply), SUM(lt.current_main_vault), + DATE_TRUNC($3, TIMESTAMP 'epoch' + INTERVAL '1 second' * floor(EXTRACT(EPOCH FROM lt.date)/$4) * $4) as dateFrame + FROM logtransactions AS lt + JOIN asset AS a ON lt.asset_id = a.id + WHERE lt.date >= $1 AND lt.asset_id = $2 + GROUP BY a.id, dateFrame + ORDER BY a.id, dateFrame; + ` + + rows, err := repo.Db.Query(query, dateFilter, assetID, timeFrameUnit, timeFrameSeconds) + if err != nil { + return entity.SumLogTransactionSupply{}, err + } + defer rows.Close() + + var sumLogTransactionSupply entity.SumLogTransactionSupply + for rows.Next() { + var asset entity.Asset + var currentSupply, currentMainVault int + var date string + err := rows.Scan(&asset.Id, &asset.Name, &asset.Code, &asset.AssetType, ¤tSupply, ¤tMainVault, &date) + if err != nil { + return entity.SumLogTransactionSupply{}, err + } + + sumLogTransactionSupply.Asset = asset + sumLogTransactionSupply.CurrentSupply = append(sumLogTransactionSupply.CurrentSupply, currentSupply) + sumLogTransactionSupply.CurrentyMainVault = append(sumLogTransactionSupply.CurrentyMainVault, currentMainVault) + sumLogTransactionSupply.Date = append(sumLogTransactionSupply.Date, date) + } + + return sumLogTransactionSupply, nil +} From b329aa50401bd6023396d76704c84ec023838756 Mon Sep 17 00:00:00 2001 From: Lucas Magnus Date: Thu, 14 Sep 2023 14:46:19 -0300 Subject: [PATCH 03/11] fix supply float --- backend/internal/controller/http/v1/assets.go | 48 +++++++++---------- backend/internal/entity/transaction_log.go | 30 ++++++------ .../usecase/repo/log_transaction_postgres.go | 4 +- .../migrations/000023_testnet_reset.up.sql | 11 +++++ 4 files changed, 52 insertions(+), 41 deletions(-) create mode 100644 backend/migrations/000023_testnet_reset.up.sql diff --git a/backend/internal/controller/http/v1/assets.go b/backend/internal/controller/http/v1/assets.go index 5ce53ad2..f3169441 100644 --- a/backend/internal/controller/http/v1/assets.go +++ b/backend/internal/controller/http/v1/assets.go @@ -49,39 +49,39 @@ type CreateAssetRequest struct { } type BurnAssetRequest struct { - Id string `json:"id" binding:"required" example:"001"` - SponsorId int `json:"sponsor_id" example:"2"` - Amount string `json:"amount" binding:"required" example:"1000"` - CurrentSupply int `json:"current_supply" example:"1000"` - CurrentMainVault int `json:"current_main_vault" example:"1000"` + Id string `json:"id" binding:"required" example:"001"` + SponsorId int `json:"sponsor_id" example:"2"` + Amount string `json:"amount" binding:"required" example:"1000"` + CurrentSupply float64 `json:"current_supply" example:"1000"` + CurrentMainVault float64 `json:"current_main_vault" example:"1000"` } type MintAssetRequest struct { - Id string `json:"id" binding:"required" example:"12"` - SponsorId int `json:"sponsor_id" example:"2"` - Code string `json:"code" binding:"required" example:"USDC"` - Amount string `json:"amount" binding:"required" example:"1000"` - CurrentSupply int `json:"current_supply" example:"1000"` - CurrentMainVault int `json:"current_main_vault" example:"1000"` + Id string `json:"id" binding:"required" example:"12"` + SponsorId int `json:"sponsor_id" example:"2"` + Code string `json:"code" binding:"required" example:"USDC"` + Amount string `json:"amount" binding:"required" example:"1000"` + CurrentSupply float64 `json:"current_supply" example:"1000"` + CurrentMainVault float64 `json:"current_main_vault" example:"1000"` } type ClawbackAssetRequest struct { - SponsorId int `json:"sponsor_id" example:"2"` - Code string `json:"code" binding:"required" example:"USDC"` - Amount string `json:"amount" binding:"required" example:"1000"` - From string `json:"from" binding:"required" example:"GDKIJJIKXLOM2NRMPNQZUUYK24ZPVFC6426GZAICZ6E5PQG2MIPIMB2L"` - CurrentSupply int `json:"current_supply" example:"1000"` - CurrentMainVault int `json:"current_main_vault" example:"1000"` + SponsorId int `json:"sponsor_id" example:"2"` + Code string `json:"code" binding:"required" example:"USDC"` + Amount string `json:"amount" binding:"required" example:"1000"` + From string `json:"from" binding:"required" example:"GDKIJJIKXLOM2NRMPNQZUUYK24ZPVFC6426GZAICZ6E5PQG2MIPIMB2L"` + CurrentSupply float64 `json:"current_supply" example:"1000"` + CurrentMainVault float64 `json:"current_main_vault" example:"1000"` } type TransferAssetRequest struct { - SourceWalletID int `json:"source_wallet_id" binding:"required" example:"1"` - SponsorId int `json:"sponsor_id" example:"2"` - DestinationWalletPK string `json:"destination_wallet_pk" binding:"required" example:"GABCD...."` - AssetID string `json:"asset_id" binding:"required" example:"12"` - Amount string `json:"amount" binding:"required" example:"12"` - CurrentSupply int `json:"current_supply" example:"1000"` - CurrentMainVault int `json:"current_main_vault" example:"1000"` + SourceWalletID int `json:"source_wallet_id" binding:"required" example:"1"` + SponsorId int `json:"sponsor_id" example:"2"` + DestinationWalletPK string `json:"destination_wallet_pk" binding:"required" example:"GABCD...."` + AssetID string `json:"asset_id" binding:"required" example:"12"` + Amount string `json:"amount" binding:"required" example:"12"` + CurrentSupply float64 `json:"current_supply" example:"1000"` + CurrentMainVault float64 `json:"current_main_vault" example:"1000"` } type UpdateAuthFlagsRequest struct { diff --git a/backend/internal/entity/transaction_log.go b/backend/internal/entity/transaction_log.go index 17df7b41..d60deaaf 100644 --- a/backend/internal/entity/transaction_log.go +++ b/backend/internal/entity/transaction_log.go @@ -1,17 +1,17 @@ package entity type LogTransaction struct { - LogID int `json:"log_id" example:"1"` - UserID int `json:"user_id" example:"42"` - TransactionTypeID int `json:"transaction_type_id" example:"1"` - Asset Asset `json:"asset"` - Date string `json:"date" example:"2023-08-10T14:30:00Z"` - Amount float64 `json:"amount" example:"100000"` - Description string `json:"description" example:"Mint Asset"` - OriginPK *string `json:"origin_pk" example:"GSDC..."` - DestinationPK *string `json:"destination_pk" example:"GSDC..."` - CurrentSupply *int `json:"current_supply" example:"1000"` - CurrentMainVault *int `json:"current_main_vault" example:"1000"` + LogID int `json:"log_id" example:"1"` + UserID int `json:"user_id" example:"42"` + TransactionTypeID int `json:"transaction_type_id" example:"1"` + Asset Asset `json:"asset"` + Date string `json:"date" example:"2023-08-10T14:30:00Z"` + Amount float64 `json:"amount" example:"100000"` + Description string `json:"description" example:"Mint Asset"` + OriginPK *string `json:"origin_pk" example:"GSDC..."` + DestinationPK *string `json:"destination_pk" example:"GSDC..."` + CurrentSupply *float64 `json:"current_supply" example:"1000"` + CurrentMainVault *float64 `json:"current_main_vault" example:"1000"` } type SumLogTransaction struct { @@ -22,10 +22,10 @@ type SumLogTransaction struct { } type SumLogTransactionSupply struct { - Asset Asset `json:"asset"` - CurrentSupply []int `json:"current_supply" example:"1000"` - CurrentyMainVault []int `json:"current_main_vault" example:"1000"` - Date []string `json:"date" example:"2023-08-10T14:30:00Z"` + Asset Asset `json:"asset"` + CurrentSupply []float64 `json:"current_supply" example:"1000"` + CurrentyMainVault []float64 `json:"current_main_vault" example:"1000"` + Date []string `json:"date" example:"2023-08-10T14:30:00Z"` } const ( diff --git a/backend/internal/usecase/repo/log_transaction_postgres.go b/backend/internal/usecase/repo/log_transaction_postgres.go index e10a3fff..a97de10a 100644 --- a/backend/internal/usecase/repo/log_transaction_postgres.go +++ b/backend/internal/usecase/repo/log_transaction_postgres.go @@ -303,7 +303,7 @@ func (repo *LogTransactionRepo) SumLogTransactionSupply(timeRange string, timeFr var sumLogTransactionSupply entity.SumLogTransactionSupply for rows.Next() { var asset entity.Asset - var currentSupply, currentMainVault int + var currentSupply, currentMainVault float64 var date string err := rows.Scan(&asset.Id, &asset.Name, &asset.Code, &asset.AssetType, ¤tSupply, ¤tMainVault, &date) if err != nil { @@ -357,7 +357,7 @@ func (repo *LogTransactionRepo) SumLogTransactionSupplyByAssetID(assetID int, ti var sumLogTransactionSupply entity.SumLogTransactionSupply for rows.Next() { var asset entity.Asset - var currentSupply, currentMainVault int + var currentSupply, currentMainVault float64 var date string err := rows.Scan(&asset.Id, &asset.Name, &asset.Code, &asset.AssetType, ¤tSupply, ¤tMainVault, &date) if err != nil { diff --git a/backend/migrations/000023_testnet_reset.up.sql b/backend/migrations/000023_testnet_reset.up.sql new file mode 100644 index 00000000..fb9ff366 --- /dev/null +++ b/backend/migrations/000023_testnet_reset.up.sql @@ -0,0 +1,11 @@ +TRUNCATE TABLE logtransactions CASCADE; +TRUNCATE TABLE contracts CASCADE; +TRUNCATE TABLE vault CASCADE; +TRUNCATE TABLE vaultcategory CASCADE; +TRUNCATE TABLE asset CASCADE; +TRUNCATE TABLE key CASCADE; +TRUNCATE TABLE wallet CASCADE; +TRUNCATE TABLE useraccount CASCADE; + +ALTER SEQUENCE public.key_id_seq RESTART 1; +ALTER SEQUENCE public.wallet_id_seq RESTART 1; From 38ba734262fb5126a994556d77d89b1d777b238b Mon Sep 17 00:00:00 2001 From: Lucas Magnus Date: Thu, 14 Sep 2023 15:42:08 -0300 Subject: [PATCH 04/11] feat: refact permissions --- backend/migrations/000024_refact_permissions.up.sql | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 backend/migrations/000024_refact_permissions.up.sql diff --git a/backend/migrations/000024_refact_permissions.up.sql b/backend/migrations/000024_refact_permissions.up.sql new file mode 100644 index 00000000..2d3176d7 --- /dev/null +++ b/backend/migrations/000024_refact_permissions.up.sql @@ -0,0 +1,5 @@ +DELETE FROM permission WHERE ID = 2; +DELETE FROM permission WHERE ID = 6; +UPDATE permission SET name = 'Token management' WHERE ID = 3; +UPDATE permission SET name = 'Transfer internally' WHERE ID = 4; +UPDATE permission SET name = 'Transfer externally' WHERE ID = 5; From 73c48367cf07cc23229cbfa6d814080ff085275b Mon Sep 17 00:00:00 2001 From: Lucas Magnus Date: Fri, 15 Sep 2023 11:32:26 -0300 Subject: [PATCH 05/11] feat: supply chart --- .../controller/http/v1/log_transaction.go | 52 ++++----------- backend/internal/entity/transaction_log.go | 14 ++-- backend/internal/usecase/interfaces.go | 2 +- backend/internal/usecase/log_transaction.go | 6 +- .../usecase/repo/log_transaction_postgres.go | 64 ++++++++++--------- 5 files changed, 60 insertions(+), 78 deletions(-) diff --git a/backend/internal/controller/http/v1/log_transaction.go b/backend/internal/controller/http/v1/log_transaction.go index 065874e7..6316ea44 100644 --- a/backend/internal/controller/http/v1/log_transaction.go +++ b/backend/internal/controller/http/v1/log_transaction.go @@ -29,12 +29,17 @@ func newLogTransactionsRoutes(handler *gin.RouterGroup, w usecase.WalletUseCase, h.GET("/assets/:asset_id/type/:transaction_type_id/sum/:time_range/:time_frame", r.sumAmountsByAssetID) h.GET("/assets/sum/:time_range/:time_frame", r.sumAmountsForAllAssets) h.GET("/last-transactions/:transaction_type_id", r.getLastLogTransactions) - h.GET("/supply/:asset_id/sum/:time_range/:time_frame", r.sumSupplyByAssetID) - h.GET("/supply/sum/:time_range/:time_frame", r.sumSupplyForAllAssets) + h.POST("/supply/:asset_id", r.supplyByAssetID) } } +type FiltersRequest struct { + TimeRange string `json:"time_range" example:"hour"` + PeriodInitial string `json:"period_initial" example:"24 hours"` + Interval string `json:"interval" example:"1 hour"` +} + // @Summary Get all transactions logs // @Description Get all transactions logs within a specific time range // @Tags Log Transactions @@ -261,14 +266,12 @@ func (r *logTransactionsRoutes) getLastLogTransactions(c *gin.Context) { // @Failure 400 {string} string "Invalid time_frame format" // @Failure 500 {string} string "Internal server error" // @Router /log_transactions/supply/{asset_id}/{time_range}/{time_frame} [get] -func (r *logTransactionsRoutes) sumSupplyByAssetID(c *gin.Context) { +func (r *logTransactionsRoutes) supplyByAssetID(c *gin.Context) { assetIDStr := c.Param("asset_id") - timeRange := c.Param("time_range") - timeFrame := c.Param("time_frame") - duration, err := time.ParseDuration(timeFrame) - if err != nil { - errorResponse(c, http.StatusBadRequest, "Invalid time_frame format", err) + var request FiltersRequest + if err := c.ShouldBindJSON(&request); err != nil { + errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err) return } @@ -278,38 +281,7 @@ func (r *logTransactionsRoutes) sumSupplyByAssetID(c *gin.Context) { return } - sum, err := r.l.SumLogTransactionsSupplyByAssetID(assetID, timeRange, duration) - if err != nil { - errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()), err) - return - } - - c.JSON(http.StatusOK, sum) -} - -// @Summary Get sum of supply for all assets within a specific time frame -// @Description Get sum of supply for all assets, grouped by a specified time frame (e.g., '1h' for 1 hour) -// @Tags Log Transactions -// @Accept json -// @Produce json -// @Param time_range path string true "Time range for the query (e.g., '24h' or '1d' '7d' '30d')" -// @Param time_frame path string true "Time frame for the query (e.g., '1h' '2h' '24h' '36h')" -// @Security ApiKeyAuth -// @Success 200 {array} entity.SumLogTransaction -// @Failure 400 {string} string "Invalid time_frame format" -// @Failure 500 {string} string "Internal server error" -// @Router /log_transactions/supply/{time_range}/{time_frame} [get] -func (r *logTransactionsRoutes) sumSupplyForAllAssets(c *gin.Context) { - timeRange := c.Param("time_range") - timeFrame := c.Param("time_frame") - - duration, err := time.ParseDuration(timeFrame) - if err != nil { - errorResponse(c, http.StatusBadRequest, "Invalid time_frame format", err) - return - } - - sum, err := r.l.SumLogTransactionsSupply(timeRange, duration) + sum, err := r.l.LogTransactionsSupplyByAssetID(assetID, request.TimeRange, request.PeriodInitial, request.Interval) if err != nil { errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()), err) return diff --git a/backend/internal/entity/transaction_log.go b/backend/internal/entity/transaction_log.go index d60deaaf..2567ef2d 100644 --- a/backend/internal/entity/transaction_log.go +++ b/backend/internal/entity/transaction_log.go @@ -22,10 +22,16 @@ type SumLogTransaction struct { } type SumLogTransactionSupply struct { - Asset Asset `json:"asset"` - CurrentSupply []float64 `json:"current_supply" example:"1000"` - CurrentyMainVault []float64 `json:"current_main_vault" example:"1000"` - Date []string `json:"date" example:"2023-08-10T14:30:00Z"` + Asset Asset `json:"asset"` + CurrentSupply []*float64 `json:"current_supply" example:"1000"` + CurrentyMainVault []*float64 `json:"current_main_vault" example:"1000"` + Date []string `json:"date" example:"2023-08-10T14:30:00Z"` +} + +type LogTransactionSupply struct { + CurrentSupply []*float64 `json:"current_supply" example:"1000"` + CurrentyMainVault []*float64 `json:"current_main_vault" example:"1000"` + Date []string `json:"date" example:"2023-08-10T14:30:00Z"` } const ( diff --git a/backend/internal/usecase/interfaces.go b/backend/internal/usecase/interfaces.go index 02486f03..94000ddc 100644 --- a/backend/internal/usecase/interfaces.go +++ b/backend/internal/usecase/interfaces.go @@ -97,6 +97,6 @@ type ( SumLogTransactions(timeRange string, timeFrame time.Duration) ([]entity.SumLogTransaction, error) GetLastLogTransactions(transactionTypeID int) ([]entity.LogTransaction, error) SumLogTransactionSupply(timeRange string, timeFrame time.Duration) ([]entity.SumLogTransactionSupply, error) - SumLogTransactionSupplyByAssetID(assetID int, timeRange string, timeFrame time.Duration) (entity.SumLogTransactionSupply, error) + LogTransactionSupplyByAssetID(assetID int, timeRange string, periodInitial string, interval string) (entity.LogTransactionSupply, error) } ) diff --git a/backend/internal/usecase/log_transaction.go b/backend/internal/usecase/log_transaction.go index cc9e191b..87a8f687 100644 --- a/backend/internal/usecase/log_transaction.go +++ b/backend/internal/usecase/log_transaction.go @@ -86,10 +86,10 @@ func (l *LogTransactionUseCase) SumLogTransactionsSupply(timeRange string, timeF return sum, nil } -func (l *LogTransactionUseCase) SumLogTransactionsSupplyByAssetID(assetID int, timeRange string, duration time.Duration) (entity.SumLogTransactionSupply, error) { - sum, err := l.lRepo.SumLogTransactionSupplyByAssetID(assetID, timeRange, duration) +func (l *LogTransactionUseCase) LogTransactionsSupplyByAssetID(assetID int, timeRange string, periodInitial string, interval string) (entity.LogTransactionSupply, error) { + sum, err := l.lRepo.LogTransactionSupplyByAssetID(assetID, timeRange, periodInitial, interval) if err != nil { - return entity.SumLogTransactionSupply{}, err + return entity.LogTransactionSupply{}, err } return sum, nil } diff --git a/backend/internal/usecase/repo/log_transaction_postgres.go b/backend/internal/usecase/repo/log_transaction_postgres.go index a97de10a..a3e33fb3 100644 --- a/backend/internal/usecase/repo/log_transaction_postgres.go +++ b/backend/internal/usecase/repo/log_transaction_postgres.go @@ -303,7 +303,7 @@ func (repo *LogTransactionRepo) SumLogTransactionSupply(timeRange string, timeFr var sumLogTransactionSupply entity.SumLogTransactionSupply for rows.Next() { var asset entity.Asset - var currentSupply, currentMainVault float64 + var currentSupply, currentMainVault *float64 var date string err := rows.Scan(&asset.Id, &asset.Name, &asset.Code, &asset.AssetType, ¤tSupply, ¤tMainVault, &date) if err != nil { @@ -329,46 +329,50 @@ func (repo *LogTransactionRepo) SumLogTransactionSupply(timeRange string, timeFr return sums, nil } -func (repo *LogTransactionRepo) SumLogTransactionSupplyByAssetID(assetID int, timeRange string, timeFrame time.Duration) (entity.SumLogTransactionSupply, error) { - dateFilter, err := getDateFilter(timeRange) - if err != nil { - return entity.SumLogTransactionSupply{}, err - } - - timeFrameUnit := getTimeFrame(timeFrame) - timeFrameSeconds := timeFrame.Seconds() - +func (repo *LogTransactionRepo) LogTransactionSupplyByAssetID(assetID int, timeRange string, periodInitial string, interval string) (entity.LogTransactionSupply, error) { query := ` - SELECT a.id, a.name, a.code, a.asset_type, SUM(lt.current_supply), SUM(lt.current_main_vault), - DATE_TRUNC($3, TIMESTAMP 'epoch' + INTERVAL '1 second' * floor(EXTRACT(EPOCH FROM lt.date)/$4) * $4) as dateFrame - FROM logtransactions AS lt - JOIN asset AS a ON lt.asset_id = a.id - WHERE lt.date >= $1 AND lt.asset_id = $2 - GROUP BY a.id, dateFrame - ORDER BY a.id, dateFrame; + WITH period_range AS ( + SELECT generate_series( + date_trunc($1, current_timestamp - $2::interval), + date_trunc($1, current_timestamp), + $3::interval + ) AS period + ) + + SELECT + hr.period, + MAX(lt.current_supply) AS current_supply, + MAX(lt.current_main_vault) AS current_main_vault + FROM + period_range hr + LEFT JOIN + public.logtransactions lt + ON + date_trunc($1, hr.period) = date_trunc($1, lt.date) and lt.asset_id = $4 + GROUP BY + hr.period + ORDER BY + hr.period; ` - rows, err := repo.Db.Query(query, dateFilter, assetID, timeFrameUnit, timeFrameSeconds) + rows, err := repo.Db.Query(query, timeRange, periodInitial, interval, assetID) if err != nil { - return entity.SumLogTransactionSupply{}, err + return entity.LogTransactionSupply{}, err } defer rows.Close() - - var sumLogTransactionSupply entity.SumLogTransactionSupply + var logTransactionSupply entity.LogTransactionSupply for rows.Next() { - var asset entity.Asset - var currentSupply, currentMainVault float64 + var currentSupply, currentMainVault *float64 var date string - err := rows.Scan(&asset.Id, &asset.Name, &asset.Code, &asset.AssetType, ¤tSupply, ¤tMainVault, &date) + err := rows.Scan(&date, ¤tSupply, ¤tMainVault) if err != nil { - return entity.SumLogTransactionSupply{}, err + return entity.LogTransactionSupply{}, err } - sumLogTransactionSupply.Asset = asset - sumLogTransactionSupply.CurrentSupply = append(sumLogTransactionSupply.CurrentSupply, currentSupply) - sumLogTransactionSupply.CurrentyMainVault = append(sumLogTransactionSupply.CurrentyMainVault, currentMainVault) - sumLogTransactionSupply.Date = append(sumLogTransactionSupply.Date, date) + logTransactionSupply.CurrentSupply = append(logTransactionSupply.CurrentSupply, currentSupply) + logTransactionSupply.CurrentyMainVault = append(logTransactionSupply.CurrentyMainVault, currentMainVault) + logTransactionSupply.Date = append(logTransactionSupply.Date, date) } - return sumLogTransactionSupply, nil + return logTransactionSupply, nil } From c34d53b775f5ca200e80033b3fcf3534e9652077 Mon Sep 17 00:00:00 2001 From: Lucas Magnus Date: Fri, 15 Sep 2023 11:33:19 -0300 Subject: [PATCH 06/11] feat: change limit latest transactions --- backend/internal/usecase/repo/log_transaction_postgres.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/internal/usecase/repo/log_transaction_postgres.go b/backend/internal/usecase/repo/log_transaction_postgres.go index a3e33fb3..ef76017d 100644 --- a/backend/internal/usecase/repo/log_transaction_postgres.go +++ b/backend/internal/usecase/repo/log_transaction_postgres.go @@ -233,9 +233,7 @@ func (repo *LogTransactionRepo) GetLastLogTransactions(transactionTypeID int) ([ lt.origin_pk, lt.destination_pk, lt.current_supply, lt.current_main_vault FROM logtransactions AS lt JOIN Asset AS a ON lt.asset_id = a.id - WHERE lt.transaction_type_id = $1 ORDER BY lt.date DESC - LIMIT 5 ` rows, err := repo.Db.Query(query, transactionTypeID) From 4c4e5635f53ffa4c3e2a18b5ef3871caabe2d477 Mon Sep 17 00:00:00 2001 From: Lucas Magnus Date: Fri, 15 Sep 2023 11:42:30 -0300 Subject: [PATCH 07/11] feat: remove limit last transactions --- backend/internal/usecase/repo/log_transaction_postgres.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/internal/usecase/repo/log_transaction_postgres.go b/backend/internal/usecase/repo/log_transaction_postgres.go index ef76017d..3c512d5f 100644 --- a/backend/internal/usecase/repo/log_transaction_postgres.go +++ b/backend/internal/usecase/repo/log_transaction_postgres.go @@ -236,7 +236,7 @@ func (repo *LogTransactionRepo) GetLastLogTransactions(transactionTypeID int) ([ ORDER BY lt.date DESC ` - rows, err := repo.Db.Query(query, transactionTypeID) + rows, err := repo.Db.Query(query) if err != nil { return nil, err } From e4777f25ffb209cc10e9e32582ee0d35c8d9488e Mon Sep 17 00:00:00 2001 From: Lucas Magnus Date: Fri, 15 Sep 2023 12:00:23 -0300 Subject: [PATCH 08/11] feat: delete log transaction wrong --- backend/internal/usecase/repo/log_transaction_postgres.go | 4 +++- backend/migrations/000025_delete_log_transaction.sql | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 backend/migrations/000025_delete_log_transaction.sql diff --git a/backend/internal/usecase/repo/log_transaction_postgres.go b/backend/internal/usecase/repo/log_transaction_postgres.go index 3c512d5f..a3e33fb3 100644 --- a/backend/internal/usecase/repo/log_transaction_postgres.go +++ b/backend/internal/usecase/repo/log_transaction_postgres.go @@ -233,10 +233,12 @@ func (repo *LogTransactionRepo) GetLastLogTransactions(transactionTypeID int) ([ lt.origin_pk, lt.destination_pk, lt.current_supply, lt.current_main_vault FROM logtransactions AS lt JOIN Asset AS a ON lt.asset_id = a.id + WHERE lt.transaction_type_id = $1 ORDER BY lt.date DESC + LIMIT 5 ` - rows, err := repo.Db.Query(query) + rows, err := repo.Db.Query(query, transactionTypeID) if err != nil { return nil, err } diff --git a/backend/migrations/000025_delete_log_transaction.sql b/backend/migrations/000025_delete_log_transaction.sql new file mode 100644 index 00000000..aba37a5c --- /dev/null +++ b/backend/migrations/000025_delete_log_transaction.sql @@ -0,0 +1 @@ +DELETE FROM LogTransactions WHERE ID = 181; From 6bacbf55af37deb3d0a06e91ec38e0667cf9e038 Mon Sep 17 00:00:00 2001 From: Lucas Magnus Date: Fri, 15 Sep 2023 12:13:42 -0300 Subject: [PATCH 09/11] fix: save log transaction with error --- backend/internal/controller/http/v1/assets.go | 3 +++ backend/migrations/000026_delete_log_transaction_wrong.sql | 1 + 2 files changed, 4 insertions(+) create mode 100644 backend/migrations/000026_delete_log_transaction_wrong.sql diff --git a/backend/internal/controller/http/v1/assets.go b/backend/internal/controller/http/v1/assets.go index f3169441..54472100 100644 --- a/backend/internal/controller/http/v1/assets.go +++ b/backend/internal/controller/http/v1/assets.go @@ -498,6 +498,7 @@ func (r *assetsRoutes) transferAsset(c *gin.Context) { }) if err != nil { errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err) + return } token := c.Request.Header.Get("Authorization") @@ -590,6 +591,7 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) { }) if err != nil { errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err) + return } token := c.Request.Header.Get("Authorization") @@ -602,6 +604,7 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) { userID, err := strconv.Atoi(user.ID) if err != nil { errorResponse(c, http.StatusNotFound, "error to parse user id", err) + return } amount, err := strconv.ParseFloat(request.Amount, 64) diff --git a/backend/migrations/000026_delete_log_transaction_wrong.sql b/backend/migrations/000026_delete_log_transaction_wrong.sql new file mode 100644 index 00000000..6101b9df --- /dev/null +++ b/backend/migrations/000026_delete_log_transaction_wrong.sql @@ -0,0 +1 @@ +DELETE FROM LogTransactions WHERE LOG_ID = 181; From 80109e47564951efe78e26a36fb653810dc3e6dd Mon Sep 17 00:00:00 2001 From: Lucas Magnus Date: Fri, 15 Sep 2023 12:23:17 -0300 Subject: [PATCH 10/11] fix: remove log transaction 181 --- backend/migrations/000025_delete_log_transaction.sql | 1 - ...tion_wrong.sql => 000025_delete_log_transaction_wrong.up.sql} | 0 2 files changed, 1 deletion(-) delete mode 100644 backend/migrations/000025_delete_log_transaction.sql rename backend/migrations/{000026_delete_log_transaction_wrong.sql => 000025_delete_log_transaction_wrong.up.sql} (100%) diff --git a/backend/migrations/000025_delete_log_transaction.sql b/backend/migrations/000025_delete_log_transaction.sql deleted file mode 100644 index aba37a5c..00000000 --- a/backend/migrations/000025_delete_log_transaction.sql +++ /dev/null @@ -1 +0,0 @@ -DELETE FROM LogTransactions WHERE ID = 181; diff --git a/backend/migrations/000026_delete_log_transaction_wrong.sql b/backend/migrations/000025_delete_log_transaction_wrong.up.sql similarity index 100% rename from backend/migrations/000026_delete_log_transaction_wrong.sql rename to backend/migrations/000025_delete_log_transaction_wrong.up.sql From 9bc7be79962a88b022d90706e42f469eff87f4f5 Mon Sep 17 00:00:00 2001 From: Lucas Magnus Date: Fri, 22 Sep 2023 13:06:12 -0300 Subject: [PATCH 11/11] feat: admin role --- backend/internal/entity/role.go | 5 +++-- backend/internal/usecase/repo/role_postgres.go | 4 ++-- backend/migrations/000026_role_superuser.down.sql | 1 + backend/migrations/000026_role_superuser.up.sql | 2 ++ 4 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 backend/migrations/000026_role_superuser.down.sql create mode 100644 backend/migrations/000026_role_superuser.up.sql diff --git a/backend/internal/entity/role.go b/backend/internal/entity/role.go index a23de7b9..03f82520 100644 --- a/backend/internal/entity/role.go +++ b/backend/internal/entity/role.go @@ -1,8 +1,9 @@ package entity type Role struct { - Id int `json:"id" example:"1"` - Name string `json:"name" example:"Admin"` + Id int `json:"id" example:"1"` + Name string `json:"name" example:"Admin"` + Admin int `json:"admin" example:"1"` } type RoleRequest struct { diff --git a/backend/internal/usecase/repo/role_postgres.go b/backend/internal/usecase/repo/role_postgres.go index 76ca6a4e..22e65bed 100644 --- a/backend/internal/usecase/repo/role_postgres.go +++ b/backend/internal/usecase/repo/role_postgres.go @@ -17,7 +17,7 @@ func NewRoleRepo(pg *postgres.Postgres) RoleRepo { } func (r RoleRepo) GetRoles() ([]entity.Role, error) { - stmt := `SELECT * FROM Role ORDER BY name ASC` + stmt := `SELECT id, name, admin FROM Role ORDER BY name ASC` rows, err := r.Db.Query(stmt) if err != nil { @@ -31,7 +31,7 @@ func (r RoleRepo) GetRoles() ([]entity.Role, error) { for rows.Next() { var role entity.Role - err = rows.Scan(&role.Id, &role.Name) + err = rows.Scan(&role.Id, &role.Name, &role.Admin) if err != nil { return nil, fmt.Errorf("RoleRepo - GetRoles - rows.Scan: %w", err) } diff --git a/backend/migrations/000026_role_superuser.down.sql b/backend/migrations/000026_role_superuser.down.sql new file mode 100644 index 00000000..91a8ecf2 --- /dev/null +++ b/backend/migrations/000026_role_superuser.down.sql @@ -0,0 +1 @@ +ALTER TABLE Role DROP COLUMN admin; \ No newline at end of file diff --git a/backend/migrations/000026_role_superuser.up.sql b/backend/migrations/000026_role_superuser.up.sql new file mode 100644 index 00000000..9f278972 --- /dev/null +++ b/backend/migrations/000026_role_superuser.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE Role ADD COLUMN admin INT DEFAULT 0; +UPDATE Role SET admin = 1 WHERE id = 1; \ No newline at end of file