mingyang-admin-iot-app/api/internal/handler/user_public/login_handler.go

46 lines
944 B
Go

package user_public
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"mingyang-admin-app-api/internal/logic/user_public"
"mingyang-admin-app-api/internal/svc"
"mingyang-admin-app-api/internal/types"
)
// swagger:route post /login user_public Login
//
// Login | 登录
//
// Login | 登录
//
// Parameters:
// + name: body
// require: true
// in: body
// type: LoginReq
//
// Responses:
// 200: LoginResp
func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.LoginReq
if err := httpx.Parse(r, &req, true); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user_public.NewLoginLogic(r.Context(), svcCtx)
resp, err := l.Login(&req)
if err != nil {
err = svcCtx.Trans.TransError(r.Context(), err)
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}