1234
This commit is contained in:
parent
54088abf22
commit
ff78042fe4
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"s-class-backend/models" // Import package models
|
||||
"s-class-backend/models"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"gorm.io/driver/postgres"
|
||||
@ -14,7 +14,7 @@ import (
|
||||
var DB *gorm.DB
|
||||
|
||||
func ConnectDatabase() {
|
||||
// Load .env
|
||||
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
@ -40,9 +40,9 @@ func ConnectDatabase() {
|
||||
if err != nil {
|
||||
fmt.Println("Gagal migrasi:", err)
|
||||
} else {
|
||||
fmt.Println("✅ Database Migrated!")
|
||||
fmt.Println("Database Migrated!")
|
||||
}
|
||||
|
||||
fmt.Println("🚀 Sukses terkoneksi ke Database PostgreSQL!")
|
||||
fmt.Println("Sukses terkoneksi ke Database PostgreSQL!")
|
||||
DB = database
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// --- GET ALL ROOMS ---
|
||||
// GET ALL ROOMS
|
||||
func GetRooms(c *gin.Context) {
|
||||
var rooms []models.Room
|
||||
if err := config.DB.Find(&rooms).Error; err != nil {
|
||||
@ -18,7 +18,7 @@ func GetRooms(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"data": rooms})
|
||||
}
|
||||
|
||||
// --- CREATE ROOM ---
|
||||
// CREATE ROOM
|
||||
func CreateRoom(c *gin.Context) {
|
||||
var input models.Room
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user