Initial commit: Homelab API
This commit is contained in:
48
internal/model/task.go
Normal file
48
internal/model/task.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"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"` // 0=none, 1=low, 2=medium, 3=high
|
||||
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
|
||||
}
|
||||
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"` // YYYY-MM-DD
|
||||
Priority int `json:"priority,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"`
|
||||
}
|
||||
Reference in New Issue
Block a user