Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing count actions in http endpoints #68

Merged
merged 1 commit into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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