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("
%s
", room.RoomName) + htmlContent += fmt.Sprintf("
%s
", room.RoomName, room.ID) } htmlContent += "
" diff --git a/main.go b/main.go index 73137de..fadea0b 100755 --- a/main.go +++ b/main.go @@ -90,9 +90,9 @@ func main() { apiGroup.POST("/signin", api.SignInUserHandler) apiGroup.POST("/signout", api.SignOutUserHandler) // Rooms routes - apiGroup.POST("/room/create", api.CreateRoomHandler) - apiGroup.GET("/room/list", api.GetAllRoomsHandler) - apiGroup.POST("/room/delete", api.DeleteRoomHandler) + apiGroup.POST("/room", api.CreateRoomHandler) + apiGroup.GET("/room", api.GetAllRoomsHandler) + apiGroup.DELETE("/room/:id", api.DeleteRoomHandler) // Webhook Routes: webhookGroup := e.Group("/webhook") diff --git a/pages/templates/dashboard.html b/pages/templates/dashboard.html index c269714..87301cc 100644 --- a/pages/templates/dashboard.html +++ b/pages/templates/dashboard.html @@ -16,16 +16,12 @@ Pollo // Dashboard Hi, {{.Name}}! -
- + +
-
- - - +
{{end}}