init
This commit is contained in:
14
models/booking.go
Normal file
14
models/booking.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Booking struct {
|
||||
gorm.Model
|
||||
RoomID uint `gorm:"not null"`
|
||||
UserID uint `gorm:"not null"`
|
||||
StartTime time.Time `gorm:"not null"`
|
||||
EndTime time.Time `gorm:"not null"`
|
||||
}
|
||||
27
models/room.go
Normal file
27
models/room.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Room struct {
|
||||
gorm.Model
|
||||
Name string `json:"name" binding:"required" gorm:"unique;not null"`
|
||||
Address string `json:"address"`
|
||||
Website string `json:"website"`
|
||||
Capacity int `json:"capacity"`
|
||||
IsPublic bool `json:"isPublic" gorm:"default:false"`
|
||||
Admins []User `gorm:"many2many:room_admins;"`
|
||||
}
|
||||
|
||||
func NewRoom(ctx *gin.Context) (Room, error) {
|
||||
var room Room
|
||||
err := ctx.ShouldBindJSON(&room)
|
||||
|
||||
if err != nil {
|
||||
return Room{}, err
|
||||
}
|
||||
|
||||
return room, nil
|
||||
}
|
||||
12
models/user.go
Normal file
12
models/user.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
gorm.Model
|
||||
Name string `json:"name" binding:"required" gorm:"unique;not null"`
|
||||
Password string `json:"password" binding:"required" gorm:"not null"`
|
||||
Email string `json:"email" binding:"required,email" gorm:"unique;not null"`
|
||||
}
|
||||
Reference in New Issue
Block a user