package handler

import (
	"net/http"

	"github.com/zeromicro/go-zero/rest/httpx"
	"microGame/app/mq/cmd/kafka/internal/logic"
	"microGame/app/mq/cmd/kafka/internal/svc"
	"microGame/app/mq/cmd/kafka/internal/types"
)

func CreateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.Request
		if err := httpx.Parse(r, &req); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}

		l := logic.NewCreateUserLogic(r.Context(), svcCtx)
		err := l.CreateUser(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.Ok(w)
		}
	}
}
