71 lines
2.3 KiB
Go
71 lines
2.3 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"`
|
|
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
|
|
}
|
|
|
|
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"`
|
|
}
|
|
|
|
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"`
|
|
}
|