File tree 8 files changed +41
-18
lines changed
8 files changed +41
-18
lines changed Original file line number Diff line number Diff line change 1
1
run :
2
2
CompileDaemon -command=" ./homelab-backend"
3
3
4
- run linux :
4
+ run- linux :
5
5
/home/kaizer/go/bin/CompileDaemon -command=" ./homelab-backend"
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import (
11
11
func GetAllDevices (c * gin.Context ) {
12
12
13
13
// Get all devices from database
14
- var devices []models.Devices
14
+ var devices []models.Device
15
15
initializers .DB .Find (& devices )
16
16
17
17
c .IndentedJSON (http .StatusOK , devices )
@@ -22,7 +22,7 @@ func GetDeviceById(c *gin.Context) {
22
22
23
23
id := c .Param ("id" )
24
24
25
- var device models.Devices
25
+ var device models.Device
26
26
result := initializers .DB .First (& device , id )
27
27
28
28
if result .Error != nil {
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import (
11
11
func GetAllRooms (c * gin.Context ) {
12
12
13
13
// >> Get all rooms from database
14
- var rooms []models.Rooms
14
+ var rooms []models.Room
15
15
initializers .DB .Find (rooms )
16
16
17
17
c .IndentedJSON (http .StatusOK , rooms )
@@ -20,7 +20,7 @@ func GetAllRooms(c *gin.Context) {
20
20
func GetAllRoomsByID (c * gin.Context ) {
21
21
22
22
// >> Get all rooms from database
23
- var room models.Rooms
23
+ var room models.Room
24
24
result := initializers .DB .Find (room )
25
25
26
26
if result .Error != nil {
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ func init() {
12
12
13
13
func main () {
14
14
initializers .DB .AutoMigrate (& models.User {})
15
- initializers .DB .AutoMigrate (& models.Rooms {})
16
- initializers .DB .AutoMigrate (& models.Devices {})
15
+ initializers .DB .AutoMigrate (& models.House {})
16
+ initializers .DB .AutoMigrate (& models.Room {})
17
+ initializers .DB .AutoMigrate (& models.Device {})
17
18
}
Original file line number Diff line number Diff line change @@ -2,11 +2,12 @@ package models
2
2
3
3
import "gorm.io/gorm"
4
4
5
- type Devices struct {
5
+ type Device struct {
6
6
gorm.Model
7
7
ID int `gorm:"primaryKey;autoIncrement"`
8
8
Name string `gorm:"size:64;index"`
9
9
Category string `gorm:"size:64;"`
10
- Room int
10
+ RoomID int
11
+ Room Room `gorm:"foreignKey:RoomID;"`
11
12
Status int8
12
13
}
Original file line number Diff line number Diff line change
1
+ package models
2
+
3
+ import "gorm.io/gorm"
4
+
5
+ type House struct {
6
+ gorm.Model
7
+ ID int `gorm:"primaryKey;autoIncrement"`
8
+ Address string `gorm:"size:128;index"`
9
+ City string `gorm:"size:128;index"`
10
+ Country string `gorm:"size:128;index"`
11
+ ZipCode string `gorm:"size:128;index"`
12
+ Floors int8
13
+ Garage bool
14
+ Parking bool
15
+ SquareMeters float32
16
+ Latitude float32
17
+ Longitude float32
18
+ }
Original file line number Diff line number Diff line change
1
+ package models
2
+
3
+ import "gorm.io/gorm"
4
+
5
+ type Room struct {
6
+ gorm.Model
7
+ ID int `gorm:"primaryKey;autoIncrement"`
8
+ Name string `gorm:"size:64;index"`
9
+ SquareMeters float64
10
+ HouseID int
11
+ House House `gorm:"foreignKey:HouseID"`
12
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments