Files
lndhub.go/controllers/create.ctrl.go
kiwiidb 1ae5df6b8c Feature: integration testing
Add integration tests with testify/suite. Moved some structs
outside of controller funcs so we can re-use them in the testing
package. Add CI workflow for running tests on every push.
2022-02-01 11:47:11 +01:00

48 lines
1.1 KiB
Go

package controllers
import (
"net/http"
"github.com/getAlby/lndhub.go/lib/service"
"github.com/labstack/echo/v4"
)
// CreateUserController : Create user controller struct
type CreateUserController struct {
svc *service.LndhubService
}
func NewCreateUserController(svc *service.LndhubService) *CreateUserController {
return &CreateUserController{svc: svc}
}
type CreateUserResponseBody struct {
Login string `json:"login"`
Password string `json:"password"`
}
// CreateUser : Create user Controller
func (controller *CreateUserController) CreateUser(c echo.Context) error {
// optional parameters that we currently do not use
type RequestBody struct {
PartnerID string `json:"partnerid"`
AccountType string `json:"accounttype"`
}
var body RequestBody
if err := c.Bind(&body); err != nil {
return err
}
user, err := controller.svc.CreateUser()
//todo json response
if err != nil {
return err
}
var ResponseBody CreateUserResponseBody
ResponseBody.Login = user.Login
ResponseBody.Password = user.Password
return c.JSON(http.StatusOK, &ResponseBody)
}