From 10250847d128c600a0e568c670b1ea1e0b691619 Mon Sep 17 00:00:00 2001 From: Omar Abdulaziz Date: Sun, 10 Nov 2024 13:41:05 +0200 Subject: [PATCH 1/3] fix the rent contract missing fields test by fixing the typo --- grid-proxy/tests/queries/mock_client/contracts.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grid-proxy/tests/queries/mock_client/contracts.go b/grid-proxy/tests/queries/mock_client/contracts.go index eedd0f57d..182849994 100644 --- a/grid-proxy/tests/queries/mock_client/contracts.go +++ b/grid-proxy/tests/queries/mock_client/contracts.go @@ -273,8 +273,8 @@ func (g *GridProxyMockClient) Contract(ctx context.Context, contractID uint32) ( Type: "rent", Details: types.RentContractDetails{ NodeID: uint(rentContract.NodeID), - FarmId: g.data.Nodes[nodeContract.NodeID].FarmID, - FarmName: g.data.Farms[g.data.Nodes[nodeContract.NodeID].FarmID].Name, + FarmId: g.data.Nodes[rentContract.NodeID].FarmID, + FarmName: g.data.Farms[g.data.Nodes[rentContract.NodeID].FarmID].Name, }, }, err } From 109d825fa1cbf0ffd605dc2dc5ac89c057044549 Mon Sep 17 00:00:00 2001 From: Omar Abdulaziz Date: Sun, 10 Nov 2024 15:51:16 +0200 Subject: [PATCH 2/3] prioritize the rented node in tests as it is in the client --- grid-proxy/tests/queries/mock_client/nodes.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/grid-proxy/tests/queries/mock_client/nodes.go b/grid-proxy/tests/queries/mock_client/nodes.go index 93f74bf7b..f528c7ebf 100644 --- a/grid-proxy/tests/queries/mock_client/nodes.go +++ b/grid-proxy/tests/queries/mock_client/nodes.go @@ -197,9 +197,8 @@ func (g *GridProxyMockClient) Nodes(ctx context.Context, filter types.NodeFilter return res[i].NodeID < res[j].NodeID }) - if filter.AvailableFor != nil { + if filter.AvailableFor != nil || filter.RentableOrRentedBy != nil { sort.Slice(res, func(i, j int) bool { - return g.data.NodeRentContractID[uint64(res[i].NodeID)] != 0 }) } From 5c909e909dd2cd30caab1e673e4ce755810f00ca Mon Sep 17 00:00:00 2001 From: Omar Abdulaziz Date: Sun, 10 Nov 2024 15:59:30 +0200 Subject: [PATCH 3/3] add twin_id as a param in the consumption endpoint --- grid-proxy/docs/docs.go | 8 ++++++++ grid-proxy/docs/swagger.json | 8 ++++++++ grid-proxy/docs/swagger.yaml | 5 +++++ grid-proxy/internal/explorer/server.go | 1 + 4 files changed, 22 insertions(+) diff --git a/grid-proxy/docs/docs.go b/grid-proxy/docs/docs.go index cbdf04080..94cf4836d 100644 --- a/grid-proxy/docs/docs.go +++ b/grid-proxy/docs/docs.go @@ -1579,6 +1579,14 @@ const docTemplate = `{ "TwinConsumption" ], "summary": "Show a report for user consumption", + "parameters": [ + { + "type": "integer", + "description": "twin id", + "name": "twin_id", + "in": "path" + } + ], "responses": { "200": { "description": "OK", diff --git a/grid-proxy/docs/swagger.json b/grid-proxy/docs/swagger.json index 04b3387fd..14b90dd67 100644 --- a/grid-proxy/docs/swagger.json +++ b/grid-proxy/docs/swagger.json @@ -1571,6 +1571,14 @@ "TwinConsumption" ], "summary": "Show a report for user consumption", + "parameters": [ + { + "type": "integer", + "description": "twin id", + "name": "twin_id", + "in": "path" + } + ], "responses": { "200": { "description": "OK", diff --git a/grid-proxy/docs/swagger.yaml b/grid-proxy/docs/swagger.yaml index ade3f9353..e603cfb36 100644 --- a/grid-proxy/docs/swagger.yaml +++ b/grid-proxy/docs/swagger.yaml @@ -1512,6 +1512,11 @@ paths: consumes: - application/json description: Get a report of user spent for last hour and for lifetime + parameters: + - description: twin id + in: path + name: twin_id + type: integer produces: - application/json responses: diff --git a/grid-proxy/internal/explorer/server.go b/grid-proxy/internal/explorer/server.go index 3c2375071..c7f910acb 100644 --- a/grid-proxy/internal/explorer/server.go +++ b/grid-proxy/internal/explorer/server.go @@ -344,6 +344,7 @@ func (a *App) listTwins(r *http.Request) (interface{}, mw.Response) { // @Summary Show a report for user consumption // @Description Get a report of user spent for last hour and for lifetime // @Tags TwinConsumption +// @Param twin_id path int yes "twin id" // @Accept json // @Produce json // @Success 200 {object} []types.TwinConsumption