]> git.example.dev Git - binbsis50-sm.git/commitdiff
updated: get rooms method
author2weiEmu <saalbach.robert@outlook.de>
Sat, 2 May 2026 16:33:00 +0000 (18:33 +0200)
committer2weiEmu <saalbach.robert@outlook.de>
Sat, 2 May 2026 16:33:00 +0000 (18:33 +0200)
pkg/dbhandling/roomsapi.go

index b4f3a455ce045c0115c8c7bcf51c0c61893e5112..c57c2c92e3ab5336f63dcf3a32f2c61e6be46a47 100644 (file)
@@ -1,6 +1,7 @@
 package dbhandling
 
 import (
+       "encoding/json"
        "net/http"
 )
 
@@ -28,34 +29,52 @@ func (dbw *DBWrapper) RoomsGet(w http.ResponseWriter, r *http.Request) {
                        roomList = append(roomList, k)
                }
        }
+
+       b, err := json.Marshal(roomList)
+       if err != nil {
+               w.WriteHeader(http.StatusInternalServerError)
+               return
+       }
+
+       w.Write(b)
+       w.WriteHeader(http.StatusOK)
 }
 
 /** TODO TEST
- *
+ * Get the id's of the songs present in a room using the name of the room
+ * the sent JSON should just be a string with the name of the room
  **/
 func (dbw *DBWrapper) RoomsGetByName(w http.ResponseWriter, r *http.Request) {
 }
 
 /** TODO TEST
- *
+ * Create a new room with the given name
+ * Just a string value as the name
+ * May be rejected if a room with that name already exists
  **/
 func (dbw *DBWrapper) RoomsCreate(w http.ResponseWriter, r *http.Request) {
 }
 
 /** TODO TEST
- *
+ * Add songs to a room using the ID of the song and the NAME of the room
+ * The values should be given in the following way:
+ * {
+ *     roomName: "NAME OF ROOM",
+ *        songIds: [1, 2, 3, 4, 5],
+ * }
  **/
 func (dbw *DBWrapper) RoomsAddByNameAndId(w http.ResponseWriter, r *http.Request) {
 }
 
 /** TODO TEST
- *
+ * The same as adding, except that the IDs mentioned in the list will be removed from the room
+ * (if they are present)
  **/
 func (dbw *DBWrapper) RoomsRemoveByNameAndId(w http.ResponseWriter, r *http.Request) {
 }
 
 /** TODO TEST
- *
+ * Delete a room by giving the name as a string, this just means the room won't exist anymore
  **/
 func (dbw *DBWrapper) RoomsDeleteByName(w http.ResponseWriter, r *http.Request) {
 }