Skip to content

Commit

Permalink
Added missing count actions in http endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
icellan committed May 10, 2022
1 parent 3559c42 commit 8cd1e36
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
39 changes: 39 additions & 0 deletions actions/access_keys/count.go
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions actions/access_keys/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
39 changes: 39 additions & 0 deletions actions/destinations/count.go
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions actions/destinations/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
39 changes: 39 additions & 0 deletions actions/transactions/count.go
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions actions/transactions/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit 8cd1e36

Please sign in to comment.