Files
honeyDueAPI/internal/models/contractor.go
Trey t 4e9b31377b Make contractor residence optional with visibility rules
- Make residence_id nullable in contractor model
- Add created_by_id field to track contractor creator
- Update access control: personal contractors visible only to creator,
  residence contractors visible to all residence users
- Add database migration for schema changes
- Update admin panel DTOs and handlers for optional residence
- Fix test utilities for new model structure

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 18:42:11 -06:00

54 lines
2.5 KiB
Go

package models
// ContractorSpecialty represents the task_contractorspecialty table
type ContractorSpecialty struct {
BaseModel
Name string `gorm:"column:name;size:50;not null" json:"name"`
Description string `gorm:"column:description;type:text" json:"description"`
Icon string `gorm:"column:icon;size:50" json:"icon"`
DisplayOrder int `gorm:"column:display_order;default:0" json:"display_order"`
}
// TableName returns the table name for GORM
func (ContractorSpecialty) TableName() string {
return "task_contractorspecialty"
}
// Contractor represents the task_contractor table
type Contractor struct {
BaseModel
ResidenceID *uint `gorm:"column:residence_id;index" json:"residence_id"`
Residence *Residence `gorm:"foreignKey:ResidenceID" json:"-"`
CreatedByID uint `gorm:"column:created_by_id;index;not null" json:"created_by_id"`
CreatedBy User `gorm:"foreignKey:CreatedByID" json:"created_by,omitempty"`
Name string `gorm:"column:name;size:200;not null" json:"name"`
Company string `gorm:"column:company;size:200" json:"company"`
Phone string `gorm:"column:phone;size:20" json:"phone"`
Email string `gorm:"column:email;size:254" json:"email"`
Website string `gorm:"column:website;size:200" json:"website"`
Notes string `gorm:"column:notes;type:text" json:"notes"`
// Address
StreetAddress string `gorm:"column:street_address;size:255" json:"street_address"`
City string `gorm:"column:city;size:100" json:"city"`
StateProvince string `gorm:"column:state_province;size:100" json:"state_province"`
PostalCode string `gorm:"column:postal_code;size:20" json:"postal_code"`
// Specialties (many-to-many)
Specialties []ContractorSpecialty `gorm:"many2many:task_contractor_specialties;" json:"specialties,omitempty"`
// Rating and favorites
Rating *float64 `gorm:"column:rating;type:decimal(2,1)" json:"rating"`
IsFavorite bool `gorm:"column:is_favorite;default:false" json:"is_favorite"`
IsActive bool `gorm:"column:is_active;default:true;index" json:"is_active"`
// Tasks associated with this contractor
Tasks []Task `gorm:"foreignKey:ContractorID" json:"tasks,omitempty"`
}
// TableName returns the table name for GORM
func (Contractor) TableName() string {
return "task_contractor"
}