package room

import (
	"net/http"

	"github.com/zeromicro/go-zero/rest/httpx"
	"microGame/app/usercenter/cmd/api/internal/logic/room"
	"microGame/app/usercenter/cmd/api/internal/svc"
	"microGame/app/usercenter/cmd/api/internal/types"
)

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

		l := room.NewLeaveRoomLogic(r.Context(), svcCtx)
		resp, err := l.LeaveRoom(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.OkJsonCtx(r.Context(), w, resp)
		}
	}
}
