diff --git a/api/createroom.go b/api/createroom.go
index cd520a1..3c3b1b9 100644
--- a/api/createroom.go
+++ b/api/createroom.go
@@ -36,7 +36,7 @@ func CreateRoomHandler(c echo.Context) error {
// Start building the HTML content for the updated list of rooms
htmlContent := "
"
for _, room := range rooms {
- htmlContent += fmt.Sprintf("
%s
", room.RoomName)
+ htmlContent += fmt.Sprintf("
%s
", room.RoomName, room.ID)
}
htmlContent += "
"
diff --git a/api/deleteroom.go b/api/deleteroom.go
index 499e9e3..93c1c6e 100644
--- a/api/deleteroom.go
+++ b/api/deleteroom.go
@@ -1,6 +1,7 @@
package api
import (
+ "fmt"
"net/http"
"pollo/lib"
@@ -10,14 +11,35 @@ import (
// DeleteRoomHandler handles the deletion of a room by ID.
func DeleteRoomHandler(c echo.Context) error {
roomID := c.Param("id")
+
+ currentSession, cookieError := lib.GetSessionCookie(c.Request(), "session")
+ if cookieError != nil {
+ return c.JSON(http.StatusUnauthorized, map[string]string{"error": "unauthorized"})
+ }
+
if roomID == "" {
return c.JSON(http.StatusBadRequest, map[string]string{"error": "room ID is required"})
}
- err := lib.DeleteRoom(lib.GetDBPool(), roomID)
- if err != nil {
+ deletionError := lib.DeleteRoom(lib.GetDBPool(), roomID)
+ if deletionError != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "failed to delete room"})
}
- return c.NoContent(http.StatusNoContent)
+ // Retrieve the updated list of rooms for the user
+ rooms, fetchError := lib.GetRoomsByUserID(lib.GetDBPool(), currentSession.UserID)
+ if fetchError != nil {
+ println("Error retrieving rooms: ", fetchError.Error())
+ return c.JSON(http.StatusInternalServerError, map[string]string{"error": "failed to retrieve rooms"})
+ }
+
+ // Start building the HTML content for the updated list of rooms
+ htmlContent := "
"
+ for _, room := range rooms {
+ htmlContent += fmt.Sprintf("
%s
", room.RoomName, room.ID)
+ }
+ htmlContent += "
"
+
+ // Return the dynamically generated HTML content
+ return c.HTML(http.StatusOK, htmlContent)
}
diff --git a/api/getroomlist.go b/api/getroomlist.go
index 11f3189..ee1a6ad 100644
--- a/api/getroomlist.go
+++ b/api/getroomlist.go
@@ -22,12 +22,10 @@ func GetAllRoomsHandler(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "failed to retrieve rooms"})
}
- // Start building the HTML content
+ // Start building the HTML content for the updated list of rooms
htmlContent := "
"
for _, room := range rooms {
- // For each room, append an HTML element to htmlContent
- // Customize this HTML structure as needed to match your desired appearance
- htmlContent += fmt.Sprintf("