From: 2weiEmu Date: Mon, 15 Jun 2026 13:26:28 +0000 (+0200) Subject: updated: new room creation seems to work as well X-Git-Url: https://git.saalbach.dev/?a=commitdiff_plain;h=2c8cbf3fab2a74c66e70bb29ee7376f1adab0f59;p=binbsis50-sm.git updated: new room creation seems to work as well --- diff --git a/pkg/dbhandling/roomsapi.go b/pkg/dbhandling/roomsapi.go index 7093ac4..a4a9a52 100644 --- a/pkg/dbhandling/roomsapi.go +++ b/pkg/dbhandling/roomsapi.go @@ -78,7 +78,9 @@ func (dbw *DBWrapper) RoomsAddByNameAndId(w http.ResponseWriter, r *http.Request err := json.NewDecoder(r.Body).Decode(&assignedSongKeys) if err != nil { + // https://stackoverflow.com/questions/67140505/http-superfluous-response-writeheader-call w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte("Failed to parse JSON: " + err.Error())) return } @@ -87,6 +89,7 @@ func (dbw *DBWrapper) RoomsAddByNameAndId(w http.ResponseWriter, r *http.Request c, err := dbw.RedisDb.ZCount(dbw.Ctx, name, "-inf", "+inf").Result() if err != nil { w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte("Failed to count entries on name: " + err.Error())) return } @@ -100,6 +103,7 @@ func (dbw *DBWrapper) RoomsAddByNameAndId(w http.ResponseWriter, r *http.Request if err != nil { w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte("Failed to complete ZAdd command: " + err.Error())) return } } diff --git a/public/index.html b/public/index.html index 5b4185d..b1ec508 100644 --- a/public/index.html +++ b/public/index.html @@ -10,6 +10,7 @@ + Room Management

Song List

diff --git a/public/js/room.js b/public/js/room.js index d083ea0..e32b555 100644 --- a/public/js/room.js +++ b/public/js/room.js @@ -1,3 +1,28 @@ +/** + * ROOM CREATION + **/ + +let createRoomButton = document.getElementById("createRoomButton") + + +async function createRoomWithName() { + let name = prompt("Name the room") + + let response = await fetch("/api/rooms/add/" + name, { + method: "PUT", + body: JSON.stringify(["0"]) + }) + + if (response.status != 200) { + alert(await response.text()) + return + } + + populateRoomSelect() +} + +createRoomButton.addEventListener("click", (_) => { createRoomWithName() } ) + /** * ADD / REMOVE FROM ROOMS **/ diff --git a/public/rooms.html b/public/rooms.html index 1a4ee4a..8191ea7 100644 --- a/public/rooms.html +++ b/public/rooms.html @@ -7,6 +7,8 @@ + Home +