54 lines
2.3 KiB
Go
54 lines
2.3 KiB
Go
package entity
|
|
|
|
import (
|
|
"time"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type DeviceDetails struct {
|
|
ID uuid.UUID `json:"id" gorm:"type:uuid;primaryKey"`
|
|
DeviceCode string `json:"device_code" gorm:"unique"`
|
|
DeviceType DeviceType `json:"device_type"`
|
|
Longitude float64 `json:"longitude"`
|
|
Latitude float64 `json:"latitude"`
|
|
PortAmount int `json:"port_amount"`
|
|
Status DeviceStatus `json:"status"`
|
|
Region *string `json:"region,omitempty" gorm:"type:varchar(255)"`
|
|
Province *string `json:"province,omitempty" gorm:"type:varchar(255)"`
|
|
City *string `json:"city,omitempty" gorm:"type:varchar(255)"`
|
|
District *string `json:"district,omitempty" gorm:"type:varchar(255)"`
|
|
ImageURL *string `json:"image_url,omitempty" gorm:"type:text"`
|
|
AdditionalImages StringSlice `gorm:"type:text[]"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
// Fixed Relationships - Use direct foreign keys
|
|
DevicePort DevicePort `json:"device_port" gorm:"foreignKey:DeviceID;references:ID"`
|
|
BackbonesStart []Backbone `json:"backbones_start" gorm:"foreignKey:DeviceStartID;references:ID"`
|
|
BackbonesEnd []Backbone `json:"backbones_end" gorm:"foreignKey:DeviceEndID;references:ID"`
|
|
FishbonesStart []Fishbone `json:"fishbones_start" gorm:"foreignKey:DeviceStartID;references:ID"`
|
|
FishbonesEnd []Fishbone `json:"fishbones_end" gorm:"foreignKey:DeviceEndID;references:ID"`
|
|
Towers []Tower `json:"towers" gorm:"foreignKey:DeviceID;references:ID"`
|
|
}
|
|
|
|
func (DeviceDetails) TableName() string {
|
|
return "devices" // Use same table as Device entity
|
|
}
|
|
|
|
// Helper method to get all backbones connected to this device
|
|
func (d *DeviceDetails) GetAllBackbones() []Backbone {
|
|
allBackbones := make([]Backbone, 0)
|
|
allBackbones = append(allBackbones, d.BackbonesStart...)
|
|
allBackbones = append(allBackbones, d.BackbonesEnd...)
|
|
return allBackbones
|
|
}
|
|
|
|
// Helper method to get all fishbones connected to this device
|
|
func (d *DeviceDetails) GetAllFishbones() []Fishbone {
|
|
allFishbones := make([]Fishbone, 0)
|
|
allFishbones = append(allFishbones, d.FishbonesStart...)
|
|
allFishbones = append(allFishbones, d.FishbonesEnd...)
|
|
return allFishbones
|
|
}
|
|
|