From 628abe06fd3380c3bdf7185c8b56cd4d086d8c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Wed, 18 Nov 2020 23:05:38 +0100 Subject: [PATCH] rest control edit. --- internal/api/room/control.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/internal/api/room/control.go b/internal/api/room/control.go index d5cc4017..94217aa2 100644 --- a/internal/api/room/control.go +++ b/internal/api/room/control.go @@ -9,23 +9,18 @@ import ( "demodesk/neko/internal/http/auth" ) -type ControlGivePayload struct { +type ControlTargetPayload struct { ID string `json:"id"` } func (h *RoomHandler) controlRequest(w http.ResponseWriter, r *http.Request) { - session := auth.GetSession(r) - if session.IsHost() { - utils.HttpBadRequest(w, "User is already host.") - return - } - host := h.sessions.GetHost() if host != nil { - utils.HttpBadRequest(w, "There is already a host.") + utils.HttpUnprocessableEntity(w, "There is already a host.") return } + session := auth.GetSession(r) h.sessions.SetHost(session) h.sessions.Broadcast( @@ -40,7 +35,7 @@ func (h *RoomHandler) controlRequest(w http.ResponseWriter, r *http.Request) { func (h *RoomHandler) controlRelease(w http.ResponseWriter, r *http.Request) { session := auth.GetSession(r) if !session.IsHost() { - utils.HttpBadRequest(w, "User is not the host.") + utils.HttpUnprocessableEntity(w, "User is not the host.") return } @@ -70,7 +65,7 @@ func (h *RoomHandler) controlTake(w http.ResponseWriter, r *http.Request) { } func (h *RoomHandler) controlGive(w http.ResponseWriter, r *http.Request) { - data := &ControlGivePayload{} + data := &ControlTargetPayload{} if !utils.HttpJsonRequest(w, r, data) { return }