Files
honeyDueAPI/internal/dto/requests/task.go
Trey t 5e95dcd015 Add multi-image support for task completions and documents
- Add TaskCompletionImage and DocumentImage models with one-to-many relationships
- Update admin panel to display images for completions and documents
- Add image arrays to API request/response DTOs
- Update repositories with Preload("Images") for eager loading
- Fix seed SQL execution to use raw SQL instead of prepared statements
- Fix table names in seed file (admin_users, push_notifications_*)
- Add comprehensive seed test data with 34 completion images and 24 document images
- Add subscription limitations admin feature with toggle
- Update admin sidebar with limitations link

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 11:07:51 -06:00

100 lines
3.0 KiB
Go

package requests
import (
"encoding/json"
"strings"
"time"
"github.com/shopspring/decimal"
)
// FlexibleDate handles both "2025-11-27" and "2025-11-27T00:00:00Z" formats
type FlexibleDate struct {
time.Time
}
func (fd *FlexibleDate) UnmarshalJSON(data []byte) error {
// Remove quotes
s := strings.Trim(string(data), "\"")
if s == "" || s == "null" {
return nil
}
// Try RFC3339 first (full datetime)
t, err := time.Parse(time.RFC3339, s)
if err == nil {
fd.Time = t
return nil
}
// Try date-only format
t, err = time.Parse("2006-01-02", s)
if err == nil {
fd.Time = t
return nil
}
return err
}
func (fd FlexibleDate) MarshalJSON() ([]byte, error) {
if fd.Time.IsZero() {
return json.Marshal(nil)
}
return json.Marshal(fd.Time.Format(time.RFC3339))
}
// ToTimePtr returns a pointer to the underlying time, or nil if zero
func (fd *FlexibleDate) ToTimePtr() *time.Time {
if fd == nil || fd.Time.IsZero() {
return nil
}
return &fd.Time
}
// CreateTaskRequest represents the request to create a task
type CreateTaskRequest struct {
ResidenceID uint `json:"residence_id" binding:"required"`
Title string `json:"title" binding:"required,min=1,max=200"`
Description string `json:"description"`
CategoryID *uint `json:"category_id"`
PriorityID *uint `json:"priority_id"`
StatusID *uint `json:"status_id"`
FrequencyID *uint `json:"frequency_id"`
AssignedToID *uint `json:"assigned_to_id"`
DueDate *FlexibleDate `json:"due_date"`
EstimatedCost *decimal.Decimal `json:"estimated_cost"`
ContractorID *uint `json:"contractor_id"`
}
// UpdateTaskRequest represents the request to update a task
type UpdateTaskRequest struct {
Title *string `json:"title" binding:"omitempty,min=1,max=200"`
Description *string `json:"description"`
CategoryID *uint `json:"category_id"`
PriorityID *uint `json:"priority_id"`
StatusID *uint `json:"status_id"`
FrequencyID *uint `json:"frequency_id"`
AssignedToID *uint `json:"assigned_to_id"`
DueDate *FlexibleDate `json:"due_date"`
EstimatedCost *decimal.Decimal `json:"estimated_cost"`
ActualCost *decimal.Decimal `json:"actual_cost"`
ContractorID *uint `json:"contractor_id"`
}
// CreateTaskCompletionRequest represents the request to create a task completion
type CreateTaskCompletionRequest struct {
TaskID uint `json:"task_id" binding:"required"`
CompletedAt *time.Time `json:"completed_at"` // Defaults to now
Notes string `json:"notes"`
ActualCost *decimal.Decimal `json:"actual_cost"`
Rating *int `json:"rating"` // 1-5 star rating
ImageURLs []string `json:"image_urls"` // Multiple image URLs
}
// CompletionImageInput represents an image to add to a completion
type CompletionImageInput struct {
ImageURL string `json:"image_url" binding:"required"`
Caption string `json:"caption"`
}