[Valentino Heman Budiarto] ff78042fe4 1234
2026-03-06 14:00:50 +07:00

33 lines
838 B
Go

package controllers
import (
"net/http"
"s-class-backend/config"
"s-class-backend/models"
"github.com/gin-gonic/gin"
)
// GET ALL ROOMS
func GetRooms(c *gin.Context) {
var rooms []models.Room
if err := config.DB.Find(&rooms).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Gagal mengambil data ruangan"})
return
}
c.JSON(http.StatusOK, gin.H{"data": rooms})
}
// CREATE ROOM
func CreateRoom(c *gin.Context) {
var input models.Room
if err := c.ShouldBindJSON(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
if err := config.DB.Create(&input).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Gagal membuat ruangan"})
return
}
c.JSON(http.StatusOK, gin.H{"message": "Ruangan berhasil ditambahkan!", "data": input})
}