Initial commit: MyCrib API in Go
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>
This commit is contained in:
170
internal/models/task.go
Normal file
170
internal/models/task.go
Normal file
@@ -0,0 +1,170 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// TaskCategory represents the task_taskcategory table
|
||||
type TaskCategory 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"`
|
||||
Color string `gorm:"column:color;size:7" json:"color"` // Hex color
|
||||
DisplayOrder int `gorm:"column:display_order;default:0" json:"display_order"`
|
||||
}
|
||||
|
||||
// TableName returns the table name for GORM
|
||||
func (TaskCategory) TableName() string {
|
||||
return "task_taskcategory"
|
||||
}
|
||||
|
||||
// TaskPriority represents the task_taskpriority table
|
||||
type TaskPriority struct {
|
||||
BaseModel
|
||||
Name string `gorm:"column:name;size:20;not null" json:"name"`
|
||||
Level int `gorm:"column:level;not null" json:"level"` // 1=low, 2=medium, 3=high, 4=urgent
|
||||
Color string `gorm:"column:color;size:7" json:"color"`
|
||||
DisplayOrder int `gorm:"column:display_order;default:0" json:"display_order"`
|
||||
}
|
||||
|
||||
// TableName returns the table name for GORM
|
||||
func (TaskPriority) TableName() string {
|
||||
return "task_taskpriority"
|
||||
}
|
||||
|
||||
// TaskStatus represents the task_taskstatus table
|
||||
type TaskStatus struct {
|
||||
BaseModel
|
||||
Name string `gorm:"column:name;size:20;not null" json:"name"`
|
||||
Description string `gorm:"column:description;type:text" json:"description"`
|
||||
Color string `gorm:"column:color;size:7" json:"color"`
|
||||
DisplayOrder int `gorm:"column:display_order;default:0" json:"display_order"`
|
||||
}
|
||||
|
||||
// TableName returns the table name for GORM
|
||||
func (TaskStatus) TableName() string {
|
||||
return "task_taskstatus"
|
||||
}
|
||||
|
||||
// TaskFrequency represents the task_taskfrequency table
|
||||
type TaskFrequency struct {
|
||||
BaseModel
|
||||
Name string `gorm:"column:name;size:20;not null" json:"name"`
|
||||
Days *int `gorm:"column:days" json:"days"` // Number of days between occurrences (nil = one-time)
|
||||
DisplayOrder int `gorm:"column:display_order;default:0" json:"display_order"`
|
||||
}
|
||||
|
||||
// TableName returns the table name for GORM
|
||||
func (TaskFrequency) TableName() string {
|
||||
return "task_taskfrequency"
|
||||
}
|
||||
|
||||
// Task represents the task_task table
|
||||
type Task struct {
|
||||
BaseModel
|
||||
ResidenceID uint `gorm:"column:residence_id;index;not null" json:"residence_id"`
|
||||
Residence Residence `gorm:"foreignKey:ResidenceID" json:"residence,omitempty"`
|
||||
CreatedByID uint `gorm:"column:created_by_id;index;not null" json:"created_by_id"`
|
||||
CreatedBy User `gorm:"foreignKey:CreatedByID" json:"created_by,omitempty"`
|
||||
AssignedToID *uint `gorm:"column:assigned_to_id;index" json:"assigned_to_id"`
|
||||
AssignedTo *User `gorm:"foreignKey:AssignedToID" json:"assigned_to,omitempty"`
|
||||
|
||||
Title string `gorm:"column:title;size:200;not null" json:"title"`
|
||||
Description string `gorm:"column:description;type:text" json:"description"`
|
||||
|
||||
CategoryID *uint `gorm:"column:category_id;index" json:"category_id"`
|
||||
Category *TaskCategory `gorm:"foreignKey:CategoryID" json:"category,omitempty"`
|
||||
PriorityID *uint `gorm:"column:priority_id;index" json:"priority_id"`
|
||||
Priority *TaskPriority `gorm:"foreignKey:PriorityID" json:"priority,omitempty"`
|
||||
StatusID *uint `gorm:"column:status_id;index" json:"status_id"`
|
||||
Status *TaskStatus `gorm:"foreignKey:StatusID" json:"status,omitempty"`
|
||||
FrequencyID *uint `gorm:"column:frequency_id;index" json:"frequency_id"`
|
||||
Frequency *TaskFrequency `gorm:"foreignKey:FrequencyID" json:"frequency,omitempty"`
|
||||
|
||||
DueDate *time.Time `gorm:"column:due_date;type:date;index" json:"due_date"`
|
||||
EstimatedCost *decimal.Decimal `gorm:"column:estimated_cost;type:decimal(10,2)" json:"estimated_cost"`
|
||||
ActualCost *decimal.Decimal `gorm:"column:actual_cost;type:decimal(10,2)" json:"actual_cost"`
|
||||
|
||||
// Contractor association
|
||||
ContractorID *uint `gorm:"column:contractor_id;index" json:"contractor_id"`
|
||||
// Contractor *Contractor `gorm:"foreignKey:ContractorID" json:"contractor,omitempty"`
|
||||
|
||||
// State flags
|
||||
IsCancelled bool `gorm:"column:is_cancelled;default:false;index" json:"is_cancelled"`
|
||||
IsArchived bool `gorm:"column:is_archived;default:false;index" json:"is_archived"`
|
||||
|
||||
// Parent task for recurring tasks
|
||||
ParentTaskID *uint `gorm:"column:parent_task_id;index" json:"parent_task_id"`
|
||||
ParentTask *Task `gorm:"foreignKey:ParentTaskID" json:"parent_task,omitempty"`
|
||||
|
||||
// Completions
|
||||
Completions []TaskCompletion `gorm:"foreignKey:TaskID" json:"completions,omitempty"`
|
||||
}
|
||||
|
||||
// TableName returns the table name for GORM
|
||||
func (Task) TableName() string {
|
||||
return "task_task"
|
||||
}
|
||||
|
||||
// IsOverdue returns true if the task is past its due date and not completed
|
||||
func (t *Task) IsOverdue() bool {
|
||||
if t.DueDate == nil || t.IsCancelled || t.IsArchived {
|
||||
return false
|
||||
}
|
||||
// Check if there's a completion
|
||||
if len(t.Completions) > 0 {
|
||||
return false
|
||||
}
|
||||
return time.Now().UTC().After(*t.DueDate)
|
||||
}
|
||||
|
||||
// IsDueSoon returns true if the task is due within the specified days
|
||||
func (t *Task) IsDueSoon(days int) bool {
|
||||
if t.DueDate == nil || t.IsCancelled || t.IsArchived {
|
||||
return false
|
||||
}
|
||||
if len(t.Completions) > 0 {
|
||||
return false
|
||||
}
|
||||
threshold := time.Now().UTC().AddDate(0, 0, days)
|
||||
return t.DueDate.Before(threshold) && !t.IsOverdue()
|
||||
}
|
||||
|
||||
// TaskCompletion represents the task_taskcompletion table
|
||||
type TaskCompletion struct {
|
||||
BaseModel
|
||||
TaskID uint `gorm:"column:task_id;index;not null" json:"task_id"`
|
||||
Task Task `gorm:"foreignKey:TaskID" json:"-"`
|
||||
CompletedByID uint `gorm:"column:completed_by_id;index;not null" json:"completed_by_id"`
|
||||
CompletedBy User `gorm:"foreignKey:CompletedByID" json:"completed_by,omitempty"`
|
||||
CompletedAt time.Time `gorm:"column:completed_at;not null" json:"completed_at"`
|
||||
Notes string `gorm:"column:notes;type:text" json:"notes"`
|
||||
ActualCost *decimal.Decimal `gorm:"column:actual_cost;type:decimal(10,2)" json:"actual_cost"`
|
||||
PhotoURL string `gorm:"column:photo_url;size:500" json:"photo_url"`
|
||||
}
|
||||
|
||||
// TableName returns the table name for GORM
|
||||
func (TaskCompletion) TableName() string {
|
||||
return "task_taskcompletion"
|
||||
}
|
||||
|
||||
// KanbanColumn represents a column in the kanban board
|
||||
type KanbanColumn struct {
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
ButtonTypes []string `json:"button_types"`
|
||||
Icons map[string]string `json:"icons"`
|
||||
Color string `json:"color"`
|
||||
Tasks []Task `json:"tasks"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
// KanbanBoard represents the full kanban board response
|
||||
type KanbanBoard struct {
|
||||
Columns []KanbanColumn `json:"columns"`
|
||||
DaysThreshold int `json:"days_threshold"`
|
||||
ResidenceID string `json:"residence_id"`
|
||||
}
|
||||
Reference in New Issue
Block a user