// Update model/entity/tower.go package entity import ( "time" "github.com/google/uuid" ) type Tower struct { ID uuid.UUID `json:"id" gorm:"type:uuid;primaryKey"` DeviceID *uuid.UUID `json:"dev_id,omitempty" gorm:"type:uuid;column:dev_id;null"` // Make nullable TowerCode string `json:"tower_code" gorm:"unique"` Longitude float64 `json:"longitude"` Latitude float64 `json:"latitude"` ImageURL string `json:"image_url"` // Keep for backward compatibility ImageURLs StringSlice `json:"image_urls" gorm:"type:jsonb"` // Multiple images ExternalTower *bool `json:"external_tower,omitempty"` BackboneCode *string `json:"backbone_code,omitempty" gorm:"column:backbone_code"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` // Relationships Device Device `json:"device,omitempty" gorm:"foreignKey:DeviceID"` } type TowerWithDistance struct { ID uuid.UUID `json:"id"` TowerCode string `json:"tower_code"` Longitude float64 `json:"longitude"` Latitude float64 `json:"latitude"` ImageURL *string `json:"image_url"` ExternalTower *bool `json:"external_tower"` DevID *uuid.UUID `json:"dev_id"` DeviceCode *string `json:"device_code"` Province *string `json:"province"` City *string `json:"city"` District *string `json:"district"` Distance float64 `json:"distance"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } // Helper method to get all image URLs func (t *Tower) GetAllImageURLs() []string { var allImages []string // Add main image URL if exists if t.ImageURL != "" { allImages = append(allImages, t.ImageURL) } // Add additional images for _, img := range t.ImageURLs { if img != "" && img != t.ImageURL { // Avoid duplicates allImages = append(allImages, img) } } return allImages } // Set multiple images (first one becomes primary) func (t *Tower) SetMultipleImages(imageURLs []string) { if len(imageURLs) == 0 { return } // Set primary image t.ImageURL = imageURLs[0] // Set all images t.ImageURLs = StringSlice(imageURLs) } func (Tower) TableName() string { return "towers" }