Complete rewrite of Django REST API to Go with: - Gin web framework for HTTP routing - GORM for database operations - GoAdmin for admin panel - Gorush integration for push notifications - Redis for caching and job queues Features implemented: - User authentication (login, register, logout, password reset) - Residence management (CRUD, sharing, share codes) - Task management (CRUD, kanban board, completions) - Contractor management (CRUD, specialties) - Document management (CRUD, warranties) - Notifications (preferences, push notifications) - Subscription management (tiers, limits) Infrastructure: - Docker Compose for local development - Database migrations and seed data - Admin panel for data management 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
76 lines
3.0 KiB
Go
76 lines
3.0 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
// DocumentType represents the type of document
|
|
type DocumentType string
|
|
|
|
const (
|
|
DocumentTypeGeneral DocumentType = "general"
|
|
DocumentTypeWarranty DocumentType = "warranty"
|
|
DocumentTypeReceipt DocumentType = "receipt"
|
|
DocumentTypeContract DocumentType = "contract"
|
|
DocumentTypeInsurance DocumentType = "insurance"
|
|
DocumentTypeManual DocumentType = "manual"
|
|
)
|
|
|
|
// Document represents the task_document table
|
|
type Document struct {
|
|
BaseModel
|
|
ResidenceID uint `gorm:"column:residence_id;index;not null" 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"`
|
|
|
|
Title string `gorm:"column:title;size:200;not null" json:"title"`
|
|
Description string `gorm:"column:description;type:text" json:"description"`
|
|
DocumentType DocumentType `gorm:"column:document_type;size:20;default:'general'" json:"document_type"`
|
|
|
|
// File information
|
|
FileURL string `gorm:"column:file_url;size:500" json:"file_url"`
|
|
FileName string `gorm:"column:file_name;size:255" json:"file_name"`
|
|
FileSize *int64 `gorm:"column:file_size" json:"file_size"`
|
|
MimeType string `gorm:"column:mime_type;size:100" json:"mime_type"`
|
|
|
|
// Warranty-specific fields
|
|
PurchaseDate *time.Time `gorm:"column:purchase_date;type:date" json:"purchase_date"`
|
|
ExpiryDate *time.Time `gorm:"column:expiry_date;type:date;index" json:"expiry_date"`
|
|
PurchasePrice *decimal.Decimal `gorm:"column:purchase_price;type:decimal(10,2)" json:"purchase_price"`
|
|
Vendor string `gorm:"column:vendor;size:200" json:"vendor"`
|
|
SerialNumber string `gorm:"column:serial_number;size:100" json:"serial_number"`
|
|
ModelNumber string `gorm:"column:model_number;size:100" json:"model_number"`
|
|
|
|
// Associated task (optional)
|
|
TaskID *uint `gorm:"column:task_id;index" json:"task_id"`
|
|
Task *Task `gorm:"foreignKey:TaskID" json:"task,omitempty"`
|
|
|
|
// State
|
|
IsActive bool `gorm:"column:is_active;default:true;index" json:"is_active"`
|
|
}
|
|
|
|
// TableName returns the table name for GORM
|
|
func (Document) TableName() string {
|
|
return "task_document"
|
|
}
|
|
|
|
// IsWarrantyExpiringSoon returns true if the warranty expires within the specified days
|
|
func (d *Document) IsWarrantyExpiringSoon(days int) bool {
|
|
if d.DocumentType != DocumentTypeWarranty || d.ExpiryDate == nil {
|
|
return false
|
|
}
|
|
threshold := time.Now().UTC().AddDate(0, 0, days)
|
|
return d.ExpiryDate.Before(threshold) && d.ExpiryDate.After(time.Now().UTC())
|
|
}
|
|
|
|
// IsWarrantyExpired returns true if the warranty has expired
|
|
func (d *Document) IsWarrantyExpired() bool {
|
|
if d.DocumentType != DocumentTypeWarranty || d.ExpiryDate == nil {
|
|
return false
|
|
}
|
|
return time.Now().UTC().After(*d.ExpiryDate)
|
|
}
|