Files
pulse-api/internal/model/task.go
Cosmo 2a50e50771 feat(savings): Add savings module with categories, transactions, recurring plans
- Categories: regular, deposits, credits, recurring, multi-user, accounts
- Transactions: deposits and withdrawals with user tracking
- Recurring plans: monthly payment obligations per user
- Stats: overdues calculation with allocation algorithm
- Excludes is_account categories from total sums
- Documentation: docs/SAVINGS.md
2026-02-16 06:48:09 +00:00

102 lines
3.9 KiB
Go

package model
import (
"database/sql"
"strings"
"time"
)
type Task struct {
ID int64 `db:"id" json:"id"`
UserID int64 `db:"user_id" json:"user_id"`
Title string `db:"title" json:"title"`
Description string `db:"description" json:"description"`
Icon string `db:"icon" json:"icon"`
Color string `db:"color" json:"color"`
DueDate sql.NullTime `db:"due_date" json:"-"`
DueDateStr *string `db:"-" json:"due_date"`
Priority int `db:"priority" json:"priority"`
ReminderTime sql.NullString `db:"reminder_time" json:"-"`
ReminderTimeStr *string `db:"-" json:"reminder_time"`
CompletedAt sql.NullTime `db:"completed_at" json:"-"`
Completed bool `db:"-" json:"completed"`
// Recurring task fields
IsRecurring bool `db:"is_recurring" json:"is_recurring"`
RecurrenceType sql.NullString `db:"recurrence_type" json:"-"`
RecurrenceTypeStr *string `db:"-" json:"recurrence_type"`
RecurrenceInterval int `db:"recurrence_interval" json:"recurrence_interval"`
RecurrenceEndDate sql.NullTime `db:"recurrence_end_date" json:"-"`
RecurrenceEndStr *string `db:"-" json:"recurrence_end_date"`
ParentTaskID sql.NullInt64 `db:"parent_task_id" json:"-"`
ParentTaskIDPtr *int64 `db:"-" json:"parent_task_id"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
}
func (t *Task) ProcessForJSON() {
if t.DueDate.Valid {
s := t.DueDate.Time.Format("2006-01-02")
t.DueDateStr = &s
}
if t.ReminderTime.Valid && t.ReminderTime.String != "" {
timeStr := t.ReminderTime.String
// Handle formats like "0000-01-01T19:00:00Z" or "19:00:00"
if strings.Contains(timeStr, "T") {
parsed, err := time.Parse(time.RFC3339, timeStr)
if err == nil {
formatted := parsed.Format("15:04")
t.ReminderTimeStr = &formatted
return
}
}
// Handle "19:00:00" format
if len(timeStr) >= 5 {
formatted := timeStr[:5]
t.ReminderTimeStr = &formatted
}
}
t.Completed = t.CompletedAt.Valid
// Process recurring fields
if t.RecurrenceType.Valid {
t.RecurrenceTypeStr = &t.RecurrenceType.String
}
if t.RecurrenceEndDate.Valid {
s := t.RecurrenceEndDate.Time.Format("2006-01-02")
t.RecurrenceEndStr = &s
}
if t.ParentTaskID.Valid {
t.ParentTaskIDPtr = &t.ParentTaskID.Int64
}
}
type CreateTaskRequest struct {
Title string `json:"title"`
Description string `json:"description,omitempty"`
Icon string `json:"icon,omitempty"`
Color string `json:"color,omitempty"`
DueDate *string `json:"due_date,omitempty"`
Priority int `json:"priority,omitempty"`
ReminderTime *string `json:"reminder_time,omitempty"`
// Recurring fields
IsRecurring bool `json:"is_recurring,omitempty"`
RecurrenceType *string `json:"recurrence_type,omitempty"`
RecurrenceInterval int `json:"recurrence_interval,omitempty"`
RecurrenceEndDate *string `json:"recurrence_end_date,omitempty"`
}
type UpdateTaskRequest struct {
Title *string `json:"title,omitempty"`
Description *string `json:"description,omitempty"`
Icon *string `json:"icon,omitempty"`
Color *string `json:"color,omitempty"`
DueDate *string `json:"due_date,omitempty"`
Priority *int `json:"priority,omitempty"`
ReminderTime *string `json:"reminder_time,omitempty"`
// Recurring fields
IsRecurring *bool `json:"is_recurring,omitempty"`
RecurrenceType *string `json:"recurrence_type,omitempty"`
RecurrenceInterval *int `json:"recurrence_interval,omitempty"`
RecurrenceEndDate *string `json:"recurrence_end_date,omitempty"`
}