successfully run facade
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package facade
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
"github.com/suyiiyii/hertz101/app/facade/biz/service"
|
||||
"github.com/suyiiyii/hertz101/app/facade/biz/utils"
|
||||
facade "github.com/suyiiyii/hertz101/app/facade/hertz_gen/facade"
|
||||
)
|
||||
|
||||
// Register .
|
||||
// @router /register [POST]
|
||||
func Register(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req facade.RegisterReq
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
utils.SendErrResponse(ctx, c, consts.StatusOK, err)
|
||||
return
|
||||
}
|
||||
|
||||
resp := &facade.RegisterResp{}
|
||||
resp, err = service.NewRegisterService(ctx, c).Run(&req)
|
||||
if err != nil {
|
||||
utils.SendErrResponse(ctx, c, consts.StatusOK, err)
|
||||
return
|
||||
}
|
||||
|
||||
utils.SendSuccessResponse(ctx, c, consts.StatusOK, resp)
|
||||
}
|
||||
|
||||
// Login .
|
||||
// @router /login [POST]
|
||||
func Login(ctx context.Context, c *app.RequestContext) {
|
||||
var err error
|
||||
var req facade.LoginReq
|
||||
err = c.BindAndValidate(&req)
|
||||
if err != nil {
|
||||
utils.SendErrResponse(ctx, c, consts.StatusOK, err)
|
||||
return
|
||||
}
|
||||
|
||||
resp := &facade.LoginResp{}
|
||||
resp, err = service.NewLoginService(ctx, c).Run(&req)
|
||||
if err != nil {
|
||||
utils.SendErrResponse(ctx, c, consts.StatusOK, err)
|
||||
return
|
||||
}
|
||||
|
||||
utils.SendSuccessResponse(ctx, c, consts.StatusOK, resp)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package facade
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app/server"
|
||||
//"github.com/cloudwego/hertz/pkg/common/test/assert"
|
||||
"github.com/cloudwego/hertz/pkg/common/ut"
|
||||
)
|
||||
|
||||
func TestRegister(t *testing.T) {
|
||||
h := server.Default()
|
||||
h.POST("/register", Register)
|
||||
path := "/register" // todo: you can customize query
|
||||
body := &ut.Body{Body: bytes.NewBufferString(""), Len: 1} // todo: you can customize body
|
||||
header := ut.Header{} // todo: you can customize header
|
||||
w := ut.PerformRequest(h.Engine, "POST", path, body, header)
|
||||
resp := w.Result()
|
||||
t.Log(string(resp.Body()))
|
||||
|
||||
// todo edit your unit test.
|
||||
// assert.DeepEqual(t, 200, resp.StatusCode())
|
||||
// assert.DeepEqual(t, "null", string(resp.Body()))
|
||||
}
|
||||
|
||||
func TestLogin(t *testing.T) {
|
||||
h := server.Default()
|
||||
h.POST("/login", Login)
|
||||
path := "/login" // todo: you can customize query
|
||||
body := &ut.Body{Body: bytes.NewBufferString(""), Len: 1} // todo: you can customize body
|
||||
header := ut.Header{} // todo: you can customize header
|
||||
w := ut.PerformRequest(h.Engine, "POST", path, body, header)
|
||||
resp := w.Result()
|
||||
t.Log(string(resp.Body()))
|
||||
|
||||
// todo edit your unit test.
|
||||
// assert.DeepEqual(t, 200, resp.StatusCode())
|
||||
// assert.DeepEqual(t, "null", string(resp.Body()))
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package facade
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
||||
"github.com/suyiiyii/hertz101/app/facade/biz/utils"
|
||||
)
|
||||
@@ -1,10 +0,0 @@
|
||||
package facade
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app/server"
|
||||
//"github.com/cloudwego/hertz/pkg/common/test/assert"
|
||||
"github.com/cloudwego/hertz/pkg/common/ut"
|
||||
)
|
||||
Reference in New Issue
Block a user