app-cloudep-portal-api-gateway/internal/handler/member/create_account_handler.go

37 lines
936 B
Go
Raw Normal View History

2024-08-25 07:08:49 +00:00
package member
import (
"app-cloudep-portal-api-gateway/internal/logic/member"
"app-cloudep-portal-api-gateway/internal/svc"
"app-cloudep-portal-api-gateway/internal/types"
2024-08-26 06:36:58 +00:00
"net/http"
ers "code.30cm.net/digimon/library-go/errors"
2024-08-25 07:08:49 +00:00
"github.com/zeromicro/go-zero/rest/httpx"
)
func CreateAccountHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CreateAccountRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := member.NewCreateAccountLogic(r.Context(), svcCtx)
resp, err := l.CreateAccount(&req)
if err != nil {
2024-08-26 06:36:58 +00:00
e := ers.FromGRPCError(err)
httpx.WriteJsonCtx(r.Context(), w, e.HTTPStatus(), types.BaseResponse{
Status: types.Status{
Code: int64(e.FullCode()),
Message: e.Error(),
},
})
return
2024-08-25 07:08:49 +00:00
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}