diff --git a/cmd/main.go b/cmd/main.go index 4b671f5..e09da84 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -48,6 +48,7 @@ func main() { e.POST("/auth", controllers.AuthController{}.Auth) e.POST("/create", controllers.CreateUserController{}.CreateUser) e.POST("/addinvoice", controllers.AddInvoiceController{}.AddInvoice, middleware.JWT([]byte("secret"))) + e.POST("/payinvoice", controllers.PayInvoiceController{}.PayInvoice, middleware.JWT([]byte("secret"))) // Start server go func() { diff --git a/pkg/controllers/payinvoice.ctrl.go b/pkg/controllers/payinvoice.ctrl.go new file mode 100644 index 0000000..169c881 --- /dev/null +++ b/pkg/controllers/payinvoice.ctrl.go @@ -0,0 +1,32 @@ +package controllers + +import ( + "github.com/labstack/echo/v4" + "net/http" +) + +// PayInvoiceController : Pay invoice controller struct +type PayInvoiceController struct{} + +// PayInvoice : Pay invoice Controller +func (PayInvoiceController) PayInvoice(c echo.Context) error { + var body struct { + ID uint `json:"id"` + Invoice string `json:"invoice" validate:"required"` + Amount int `json:"amount" validate:"gt=0"` + } + + if err := c.Bind(&body); err != nil { + return c.JSON(http.StatusBadRequest, echo.Map{ + "message": "failed to bind json", + }) + } + + if err := c.Validate(&body); err != nil { + return c.JSON(http.StatusBadRequest, echo.Map{ + "message": "invalid request", + }) + } + + return nil +}