[#33] Add route to get NeoFS balance

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-07-28 19:57:40 +03:00 committed by Alex Vanin
parent aaf7433c7b
commit 6e01a0ead7
9 changed files with 530 additions and 0 deletions

View file

@ -0,0 +1,58 @@
// Code generated by go-swagger; DO NOT EDIT.
package operations
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"net/http"
"github.com/go-openapi/runtime/middleware"
)
// GetBalanceHandlerFunc turns a function with the right signature into a get balance handler
type GetBalanceHandlerFunc func(GetBalanceParams) middleware.Responder
// Handle executing the request and returning a response
func (fn GetBalanceHandlerFunc) Handle(params GetBalanceParams) middleware.Responder {
return fn(params)
}
// GetBalanceHandler interface for that can handle valid get balance params
type GetBalanceHandler interface {
Handle(GetBalanceParams) middleware.Responder
}
// NewGetBalance creates a new http.Handler for the get balance operation
func NewGetBalance(ctx *middleware.Context, handler GetBalanceHandler) *GetBalance {
return &GetBalance{Context: ctx, Handler: handler}
}
/* GetBalance swagger:route GET /accounting/balance/{address} getBalance
Get balance in NeoFS
Getting balance of provided wallet address in NeoFS.
*/
type GetBalance struct {
Context *middleware.Context
Handler GetBalanceHandler
}
func (o *GetBalance) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
*r = *rCtx
}
var Params = NewGetBalanceParams()
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
o.Context.Respond(rw, r, route.Produces, route, err)
return
}
res := o.Handler.Handle(Params) // actually handle the request
o.Context.Respond(rw, r, route.Produces, route, res)
}

View file

@ -0,0 +1,71 @@
// Code generated by go-swagger; DO NOT EDIT.
package operations
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/http"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/strfmt"
)
// NewGetBalanceParams creates a new GetBalanceParams object
//
// There are no default values defined in the spec.
func NewGetBalanceParams() GetBalanceParams {
return GetBalanceParams{}
}
// GetBalanceParams contains all the bound params for the get balance operation
// typically these are obtained from a http.Request
//
// swagger:parameters getBalance
type GetBalanceParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*Base58 encoded wallet address.
Required: true
In: path
*/
Address string
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
// for simple values it will use straight method calls.
//
// To ensure default values, the struct must have been initialized with NewGetBalanceParams() beforehand.
func (o *GetBalanceParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
rAddress, rhkAddress, _ := route.Params.GetOK("address")
if err := o.bindAddress(rAddress, rhkAddress, route.Formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// bindAddress binds and validates parameter Address from path.
func (o *GetBalanceParams) bindAddress(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: true
// Parameter is provided by construction from the route
o.Address = raw
return nil
}

View file

@ -0,0 +1,102 @@
// Code generated by go-swagger; DO NOT EDIT.
package operations
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/http"
"github.com/go-openapi/runtime"
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
)
// GetBalanceOKCode is the HTTP code returned for type GetBalanceOK
const GetBalanceOKCode int = 200
/*GetBalanceOK Balance of address in NeoFS
swagger:response getBalanceOK
*/
type GetBalanceOK struct {
/*
In: Body
*/
Payload *models.Balance `json:"body,omitempty"`
}
// NewGetBalanceOK creates GetBalanceOK with default headers values
func NewGetBalanceOK() *GetBalanceOK {
return &GetBalanceOK{}
}
// WithPayload adds the payload to the get balance o k response
func (o *GetBalanceOK) WithPayload(payload *models.Balance) *GetBalanceOK {
o.Payload = payload
return o
}
// SetPayload sets the payload to the get balance o k response
func (o *GetBalanceOK) SetPayload(payload *models.Balance) {
o.Payload = payload
}
// WriteResponse to the client
func (o *GetBalanceOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(200)
if o.Payload != nil {
payload := o.Payload
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
}
// GetBalanceBadRequestCode is the HTTP code returned for type GetBalanceBadRequest
const GetBalanceBadRequestCode int = 400
/*GetBalanceBadRequest Bad request
swagger:response getBalanceBadRequest
*/
type GetBalanceBadRequest struct {
/*
In: Body
*/
Payload *models.ErrorResponse `json:"body,omitempty"`
}
// NewGetBalanceBadRequest creates GetBalanceBadRequest with default headers values
func NewGetBalanceBadRequest() *GetBalanceBadRequest {
return &GetBalanceBadRequest{}
}
// WithPayload adds the payload to the get balance bad request response
func (o *GetBalanceBadRequest) WithPayload(payload *models.ErrorResponse) *GetBalanceBadRequest {
o.Payload = payload
return o
}
// SetPayload sets the payload to the get balance bad request response
func (o *GetBalanceBadRequest) SetPayload(payload *models.ErrorResponse) {
o.Payload = payload
}
// WriteResponse to the client
func (o *GetBalanceBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(400)
if o.Payload != nil {
payload := o.Payload
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
}

View file

@ -53,6 +53,9 @@ func NewNeofsRestGwAPI(spec *loads.Document) *NeofsRestGwAPI {
DeleteObjectHandler: DeleteObjectHandlerFunc(func(params DeleteObjectParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation DeleteObject has not yet been implemented")
}),
GetBalanceHandler: GetBalanceHandlerFunc(func(params GetBalanceParams) middleware.Responder {
return middleware.NotImplemented("operation GetBalance has not yet been implemented")
}),
GetContainerHandler: GetContainerHandlerFunc(func(params GetContainerParams) middleware.Responder {
return middleware.NotImplemented("operation GetContainer has not yet been implemented")
}),
@ -133,6 +136,8 @@ type NeofsRestGwAPI struct {
DeleteContainerHandler DeleteContainerHandler
// DeleteObjectHandler sets the operation handler for the delete object operation
DeleteObjectHandler DeleteObjectHandler
// GetBalanceHandler sets the operation handler for the get balance operation
GetBalanceHandler GetBalanceHandler
// GetContainerHandler sets the operation handler for the get container operation
GetContainerHandler GetContainerHandler
// GetContainerEACLHandler sets the operation handler for the get container e ACL operation
@ -239,6 +244,9 @@ func (o *NeofsRestGwAPI) Validate() error {
if o.DeleteObjectHandler == nil {
unregistered = append(unregistered, "DeleteObjectHandler")
}
if o.GetBalanceHandler == nil {
unregistered = append(unregistered, "GetBalanceHandler")
}
if o.GetContainerHandler == nil {
unregistered = append(unregistered, "GetContainerHandler")
}
@ -377,6 +385,10 @@ func (o *NeofsRestGwAPI) initHandlerCache() {
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/accounting/balance/{address}"] = NewGetBalance(o.context, o.GetBalanceHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/containers/{containerId}"] = NewGetContainer(o.context, o.GetContainerHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)