feat: add Telegram bot with notifications and scheduler
This commit is contained in:
@@ -1,22 +1,31 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Habit struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
UserID int64 `db:"user_id" json:"user_id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Description string `db:"description" json:"description"`
|
||||
Color string `db:"color" json:"color"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
Frequency string `db:"frequency" json:"frequency"` // daily, weekly, custom
|
||||
TargetDays []int `db:"-" json:"target_days"` // 0=Sun, 1=Mon, etc.
|
||||
TargetCount int `db:"target_count" json:"target_count"`
|
||||
IsArchived bool `db:"is_archived" json:"is_archived"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
ID int64 `db:"id" json:"id"`
|
||||
UserID int64 `db:"user_id" json:"user_id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Description string `db:"description" json:"description"`
|
||||
Color string `db:"color" json:"color"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
Frequency string `db:"frequency" json:"frequency"` // daily, weekly, custom
|
||||
TargetDays []int `db:"-" json:"target_days"` // 0=Sun, 1=Mon, etc.
|
||||
TargetCount int `db:"target_count" json:"target_count"`
|
||||
ReminderTime sql.NullString `db:"reminder_time" json:"-"`
|
||||
ReminderTimeStr *string `db:"-" json:"reminder_time"`
|
||||
IsArchived bool `db:"is_archived" json:"is_archived"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
func (h *Habit) ProcessForJSON() {
|
||||
if h.ReminderTime.Valid {
|
||||
h.ReminderTimeStr = &h.ReminderTime.String
|
||||
}
|
||||
}
|
||||
|
||||
type HabitLog struct {
|
||||
@@ -30,24 +39,26 @@ type HabitLog struct {
|
||||
}
|
||||
|
||||
type CreateHabitRequest struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Color string `json:"color,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
Frequency string `json:"frequency,omitempty"`
|
||||
TargetDays []int `json:"target_days,omitempty"`
|
||||
TargetCount int `json:"target_count,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Color string `json:"color,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
Frequency string `json:"frequency,omitempty"`
|
||||
TargetDays []int `json:"target_days,omitempty"`
|
||||
TargetCount int `json:"target_count,omitempty"`
|
||||
ReminderTime *string `json:"reminder_time,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateHabitRequest struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Color *string `json:"color,omitempty"`
|
||||
Icon *string `json:"icon,omitempty"`
|
||||
Frequency *string `json:"frequency,omitempty"`
|
||||
TargetDays []int `json:"target_days,omitempty"`
|
||||
TargetCount *int `json:"target_count,omitempty"`
|
||||
IsArchived *bool `json:"is_archived,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Color *string `json:"color,omitempty"`
|
||||
Icon *string `json:"icon,omitempty"`
|
||||
Frequency *string `json:"frequency,omitempty"`
|
||||
TargetDays []int `json:"target_days,omitempty"`
|
||||
TargetCount *int `json:"target_count,omitempty"`
|
||||
ReminderTime *string `json:"reminder_time,omitempty"`
|
||||
IsArchived *bool `json:"is_archived,omitempty"`
|
||||
}
|
||||
|
||||
type LogHabitRequest struct {
|
||||
|
||||
@@ -6,19 +6,21 @@ import (
|
||||
)
|
||||
|
||||
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"`
|
||||
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
|
||||
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() {
|
||||
@@ -26,23 +28,28 @@ func (t *Task) ProcessForJSON() {
|
||||
s := t.DueDate.Time.Format("2006-01-02")
|
||||
t.DueDateStr = &s
|
||||
}
|
||||
if t.ReminderTime.Valid {
|
||||
t.ReminderTimeStr = &t.ReminderTime.String
|
||||
}
|
||||
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"`
|
||||
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"`
|
||||
ReminderTime *string `json:"reminder_time,omitempty"` // HH:MM
|
||||
}
|
||||
|
||||
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"`
|
||||
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"`
|
||||
}
|
||||
|
||||
@@ -1,17 +1,28 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Email string `db:"email" json:"email"`
|
||||
Username string `db:"username" json:"username"`
|
||||
PasswordHash string `db:"password_hash" json:"-"`
|
||||
EmailVerified bool `db:"email_verified" json:"email_verified"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Email string `db:"email" json:"email"`
|
||||
Username string `db:"username" json:"username"`
|
||||
PasswordHash string `db:"password_hash" json:"-"`
|
||||
EmailVerified bool `db:"email_verified" json:"email_verified"`
|
||||
TelegramChatID sql.NullInt64 `db:"telegram_chat_id" json:"-"`
|
||||
TelegramChatIDValue *int64 `db:"-" json:"telegram_chat_id"`
|
||||
NotificationsEnabled bool `db:"notifications_enabled" json:"notifications_enabled"`
|
||||
Timezone string `db:"timezone" json:"timezone"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
func (u *User) ProcessForJSON() {
|
||||
if u.TelegramChatID.Valid {
|
||||
u.TelegramChatIDValue = &u.TelegramChatID.Int64
|
||||
}
|
||||
}
|
||||
|
||||
type RegisterRequest struct {
|
||||
@@ -26,7 +37,10 @@ type LoginRequest struct {
|
||||
}
|
||||
|
||||
type UpdateProfileRequest struct {
|
||||
Username string `json:"username,omitempty"`
|
||||
Username *string `json:"username,omitempty"`
|
||||
TelegramChatID *int64 `json:"telegram_chat_id,omitempty"`
|
||||
NotificationsEnabled *bool `json:"notifications_enabled,omitempty"`
|
||||
Timezone *string `json:"timezone,omitempty"`
|
||||
}
|
||||
|
||||
type ChangePasswordRequest struct {
|
||||
|
||||
Reference in New Issue
Block a user