package handler

import (
	"net/http"

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

func GetUserHandler(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.NewGetUserLogic(r.Context(), svcCtx)
		resp, err := l.GetUser(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.OkJsonCtx(r.Context(), w, resp)
		}
	}
}
