51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"hightube/internal/db"
|
|
"hightube/internal/model"
|
|
)
|
|
|
|
// GetMyRoom returns the room details for the currently authenticated user
|
|
func GetMyRoom(c *gin.Context) {
|
|
userID, _ := c.Get("user_id")
|
|
|
|
var room model.Room
|
|
if err := db.DB.Where("user_id = ?", userID).First(&room).Error; err != nil {
|
|
c.JSON(http.StatusNotFound, gin.H{"error": "Room not found"})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"room_id": room.ID,
|
|
"title": room.Title,
|
|
"stream_key": room.StreamKey,
|
|
"is_active": room.IsActive,
|
|
})
|
|
}
|
|
|
|
// GetActiveRooms returns a list of all currently active live rooms
|
|
func GetActiveRooms(c *gin.Context) {
|
|
var rooms []model.Room
|
|
// Fetch rooms where is_active is true
|
|
if err := db.DB.Where("is_active = ?", true).Find(&rooms).Error; err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch active rooms"})
|
|
return
|
|
}
|
|
|
|
// Return safe information (do not leak stream keys)
|
|
var result []map[string]interface{}
|
|
for _, r := range rooms {
|
|
result = append(result, map[string]interface{}{
|
|
"room_id": r.ID,
|
|
"title": r.Title,
|
|
"user_id": r.UserID,
|
|
})
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{"active_rooms": result})
|
|
}
|