From 8cd1e3654d685cdfe6e3fc74f5bce654a7a5a784 Mon Sep 17 00:00:00 2001 From: Siggi Date: Tue, 10 May 2022 19:20:43 +0200 Subject: [PATCH] Added missing count actions in http endpoints --- actions/access_keys/count.go | 39 ++++++++++++++++++++++++++++++++++ actions/access_keys/routes.go | 1 + actions/destinations/count.go | 39 ++++++++++++++++++++++++++++++++++ actions/destinations/routes.go | 1 + actions/transactions/count.go | 39 ++++++++++++++++++++++++++++++++++ actions/transactions/routes.go | 1 + 6 files changed, 120 insertions(+) create mode 100644 actions/access_keys/count.go create mode 100644 actions/destinations/count.go create mode 100644 actions/transactions/count.go diff --git a/actions/access_keys/count.go b/actions/access_keys/count.go new file mode 100644 index 000000000..bc9fdef7b --- /dev/null +++ b/actions/access_keys/count.go @@ -0,0 +1,39 @@ +package accessKeys + +import ( + "net/http" + + "github.com/BuxOrg/bux" + "github.com/BuxOrg/bux-server/actions" + "github.com/julienschmidt/httprouter" + apirouter "github.com/mrz1836/go-api-router" +) + +// count will fetch a count of access keys filtered by metadata +func (a *Action) count(w http.ResponseWriter, req *http.Request, _ httprouter.Params) { + + reqXPubID, _ := bux.GetXpubIDFromRequest(req) + + // Parse the params + params := apirouter.GetParams(req) + _, metadata, conditions, err := actions.GetQueryParameters(params) + if err != nil { + apirouter.ReturnResponse(w, req, http.StatusExpectationFailed, err.Error()) + return + } + + // Record a new transaction (get the hex from parameters)a + var count int64 + if count, err = a.Services.Bux.GetAccessKeysByXPubIDCount( + req.Context(), + reqXPubID, + metadata, + conditions, + ); err != nil { + apirouter.ReturnResponse(w, req, http.StatusExpectationFailed, err.Error()) + return + } + + // Return response + apirouter.ReturnResponse(w, req, http.StatusOK, count) +} diff --git a/actions/access_keys/routes.go b/actions/access_keys/routes.go index 785a534d1..f8a89e47c 100644 --- a/actions/access_keys/routes.go +++ b/actions/access_keys/routes.go @@ -23,6 +23,7 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi // V1 Requests router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/access-key", action.Request(router, require.Wrap(action.get))) + router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/access-key/count", action.Request(router, require.Wrap(action.count))) router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/access-key/search", action.Request(router, require.Wrap(action.search))) router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/access-key/search", action.Request(router, require.Wrap(action.search))) router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/access-key", action.Request(router, require.Wrap(action.create))) diff --git a/actions/destinations/count.go b/actions/destinations/count.go new file mode 100644 index 000000000..be09945e0 --- /dev/null +++ b/actions/destinations/count.go @@ -0,0 +1,39 @@ +package destinations + +import ( + "net/http" + + "github.com/BuxOrg/bux" + "github.com/BuxOrg/bux-server/actions" + "github.com/julienschmidt/httprouter" + apirouter "github.com/mrz1836/go-api-router" +) + +// count will fetch a count of destinations filtered by metadata +func (a *Action) count(w http.ResponseWriter, req *http.Request, _ httprouter.Params) { + + reqXPubID, _ := bux.GetXpubIDFromRequest(req) + + // Parse the params + params := apirouter.GetParams(req) + _, metadata, conditions, err := actions.GetQueryParameters(params) + if err != nil { + apirouter.ReturnResponse(w, req, http.StatusExpectationFailed, err.Error()) + return + } + + // Record a new transaction (get the hex from parameters)a + var count int64 + if count, err = a.Services.Bux.GetDestinationsByXpubIDCount( + req.Context(), + reqXPubID, + metadata, + conditions, + ); err != nil { + apirouter.ReturnResponse(w, req, http.StatusExpectationFailed, err.Error()) + return + } + + // Return response + apirouter.ReturnResponse(w, req, http.StatusOK, count) +} diff --git a/actions/destinations/routes.go b/actions/destinations/routes.go index 8b04cc9c8..fcc98fc53 100644 --- a/actions/destinations/routes.go +++ b/actions/destinations/routes.go @@ -27,6 +27,7 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi // V1 Requests router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/destination", action.Request(router, requireBasic.Wrap(action.get))) + router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/destination/count", action.Request(router, requireBasic.Wrap(action.count))) router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/destination/search", action.Request(router, requireBasic.Wrap(action.search))) router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/destination/search", action.Request(router, requireBasic.Wrap(action.search))) router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/destination", action.Request(router, require.Wrap(action.create))) diff --git a/actions/transactions/count.go b/actions/transactions/count.go new file mode 100644 index 000000000..dc5565012 --- /dev/null +++ b/actions/transactions/count.go @@ -0,0 +1,39 @@ +package transactions + +import ( + "net/http" + + "github.com/BuxOrg/bux" + "github.com/BuxOrg/bux-server/actions" + "github.com/julienschmidt/httprouter" + apirouter "github.com/mrz1836/go-api-router" +) + +// count will fetch a count of transactions filtered on conditions and metadata +func (a *Action) count(w http.ResponseWriter, req *http.Request, _ httprouter.Params) { + + reqXPubID, _ := bux.GetXpubIDFromRequest(req) + + // Parse the params + params := apirouter.GetParams(req) + _, metadata, conditions, err := actions.GetQueryParameters(params) + if err != nil { + apirouter.ReturnResponse(w, req, http.StatusExpectationFailed, err.Error()) + return + } + + // Record a new transaction (get the hex from parameters)a + var count int64 + if count, err = a.Services.Bux.GetTransactionsByXpubIDCount( + req.Context(), + reqXPubID, + metadata, + conditions, + ); err != nil { + apirouter.ReturnResponse(w, req, http.StatusExpectationFailed, err.Error()) + return + } + + // Return response + apirouter.ReturnResponse(w, req, http.StatusOK, count) +} diff --git a/actions/transactions/routes.go b/actions/transactions/routes.go index 270f4d751..8e990dee1 100644 --- a/actions/transactions/routes.go +++ b/actions/transactions/routes.go @@ -27,6 +27,7 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi // V1 Requests router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/transaction", action.Request(router, requireBasic.Wrap(action.get))) + router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/transaction/count", action.Request(router, requireBasic.Wrap(action.count))) router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/transaction/search", action.Request(router, requireBasic.Wrap(action.search))) router.HTTPRouter.PATCH("/"+config.CurrentMajorVersion+"/transaction", action.Request(router, requireBasic.Wrap(action.update))) router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/transaction", action.Request(router, require.Wrap(action.newTransaction)))