Add payinvoice endpoint

This commit is contained in:
Viktor Patchev
2022-01-12 18:16:31 +01:00
parent 8b9038a037
commit 477d524cc3
2 changed files with 33 additions and 0 deletions

View File

@@ -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() {

View File

@@ -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
}