diff --git a/actions/access_keys/count.go b/actions/access_keys/count.go new file mode 100644 index 00000000..bc9fdef7 --- /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 785a534d..f8a89e47 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 00000000..be09945e --- /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 8b04cc9c..fcc98fc5 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 00000000..dc556501 --- /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 270f4d75..8e990dee 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)))