|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"git.diulo.com/mogfee/kit/middleware"
|
|
|
|
"git.diulo.com/mogfee/kit/errors"
|
|
|
|
"git.diulo.com/mogfee/kit/response"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RegisterUserHandler(app *gin.Engine, srv UserServer, m ...middleware.Middleware) {
|
|
|
|
app.GET("/api/v1/user/list", httpListHandler(srv, m...))
|
|
|
|
app.GET("/api/v1/user/login", httpLoginHandler(srv, m...))
|
|
|
|
app.GET("/api/v1/user/delete2", httpDelete2Handler(srv, m...))
|
|
|
|
app.GET("/api/v1/user/delete3", httpDelete3Handler(srv, m...))
|
|
|
|
app.GET("/api/v1/user/delete", httpDeleteHandler(srv, m...))
|
|
|
|
app.GET("/api/v1/user/delete1", httpDelete1Handler(srv, m...))
|
|
|
|
}
|
|
|
|
func httpListHandler(srv UserServer, m ...middleware.Middleware) func(c *gin.Context) {
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
var post LoginRequest
|
|
|
|
resp := response.New(c)
|
|
|
|
if err := resp.BindQuery(&post); err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
h := func(ctx context.Context, a any) (any, error) {
|
|
|
|
return srv.List(ctx, a.(*LoginRequest))
|
|
|
|
}
|
|
|
|
out, err := middleware.HttpMiddleware(c, h, m...)(c, &post)
|
|
|
|
if err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
} else {
|
|
|
|
if v, ok := out.(*LoginResponse); ok {
|
|
|
|
resp.Success(v)
|
|
|
|
} else {
|
|
|
|
resp.Error(errors.InternalServer("RESULT_TYPE_ERROR", "LoginResponse"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func httpLoginHandler(srv UserServer, m ...middleware.Middleware) func(c *gin.Context) {
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
var post LoginRequest
|
|
|
|
resp := response.New(c)
|
|
|
|
if err := resp.BindQuery(&post); err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
h := func(ctx context.Context, a any) (any, error) {
|
|
|
|
return srv.Login(ctx, a.(*LoginRequest))
|
|
|
|
}
|
|
|
|
out, err := middleware.HttpMiddleware(c, h, m...)(c, &post)
|
|
|
|
if err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
} else {
|
|
|
|
if v, ok := out.(*LoginResponse); ok {
|
|
|
|
resp.Success(v)
|
|
|
|
} else {
|
|
|
|
resp.Error(errors.InternalServer("RESULT_TYPE_ERROR", "LoginResponse"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func httpDelete2Handler(srv UserServer, m ...middleware.Middleware) func(c *gin.Context) {
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
var post LoginRequest
|
|
|
|
resp := response.New(c)
|
|
|
|
if err := resp.BindQuery(&post); err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
h := func(ctx context.Context, a any) (any, error) {
|
|
|
|
return srv.Delete2(ctx, a.(*LoginRequest))
|
|
|
|
}
|
|
|
|
out, err := middleware.HttpMiddleware(c, h, m...)(c, &post)
|
|
|
|
if err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
} else {
|
|
|
|
if v, ok := out.(*LoginResponse); ok {
|
|
|
|
resp.Success(v)
|
|
|
|
} else {
|
|
|
|
resp.Error(errors.InternalServer("RESULT_TYPE_ERROR", "LoginResponse"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func httpDelete3Handler(srv UserServer, m ...middleware.Middleware) func(c *gin.Context) {
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
var post LoginRequest
|
|
|
|
resp := response.New(c)
|
|
|
|
if err := resp.BindQuery(&post); err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
h := func(ctx context.Context, a any) (any, error) {
|
|
|
|
return srv.Delete3(ctx, a.(*LoginRequest))
|
|
|
|
}
|
|
|
|
out, err := middleware.HttpMiddleware(c, h, m...)(c, &post)
|
|
|
|
if err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
} else {
|
|
|
|
if v, ok := out.(*LoginResponse); ok {
|
|
|
|
resp.Success(v)
|
|
|
|
} else {
|
|
|
|
resp.Error(errors.InternalServer("RESULT_TYPE_ERROR", "LoginResponse"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func httpDeleteHandler(srv UserServer, m ...middleware.Middleware) func(c *gin.Context) {
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
var post LoginRequest
|
|
|
|
resp := response.New(c)
|
|
|
|
if err := resp.BindQuery(&post); err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
h := func(ctx context.Context, a any) (any, error) {
|
|
|
|
return srv.Delete(ctx, a.(*LoginRequest))
|
|
|
|
}
|
|
|
|
out, err := middleware.HttpMiddleware(c, h, m...)(c, &post)
|
|
|
|
if err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
} else {
|
|
|
|
if v, ok := out.(*LoginResponse); ok {
|
|
|
|
resp.Success(v)
|
|
|
|
} else {
|
|
|
|
resp.Error(errors.InternalServer("RESULT_TYPE_ERROR", "LoginResponse"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func httpDelete1Handler(srv UserServer, m ...middleware.Middleware) func(c *gin.Context) {
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
var post LoginRequest
|
|
|
|
resp := response.New(c)
|
|
|
|
if err := resp.BindQuery(&post); err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
h := func(ctx context.Context, a any) (any, error) {
|
|
|
|
return srv.Delete1(ctx, a.(*LoginRequest))
|
|
|
|
}
|
|
|
|
out, err := middleware.HttpMiddleware(c, h, m...)(c, &post)
|
|
|
|
if err != nil {
|
|
|
|
resp.Error(err)
|
|
|
|
} else {
|
|
|
|
if v, ok := out.(*LoginResponse); ok {
|
|
|
|
resp.Success(v)
|
|
|
|
} else {
|
|
|
|
resp.Error(errors.InternalServer("RESULT_TYPE_ERROR", "LoginResponse"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|