From 0564467c597d0a3e787f9fbe37d459e850beccaf Mon Sep 17 00:00:00 2001 From: Akulij Date: Sat, 29 Mar 2025 19:15:11 +0800 Subject: [PATCH] create tasks table --- cmd/app/db.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/cmd/app/db.go b/cmd/app/db.go index 507d128..557bdf5 100644 --- a/cmd/app/db.go +++ b/cmd/app/db.go @@ -90,3 +90,42 @@ func (bc BotController) LogMessageRaw(UserID int64, Msg string, Time time.Time) } bc.db.Create(&msg) } + +type TaskType int64 +const ( + SyncSheet TaskType = iota + NotifyAboutEvent +) + +type Task struct { + gorm.Model + ID int64 `gorm:"primary_key"` + Type TaskType + EventID int64 +} + +func (bc BotController) CreateSimpleTask(taskType TaskType) error { + task := Task{ + Type: taskType, + } + return bc.CreateTask(task) +} + +func (bc BotController) CreateTask(task Task) error { + result := bc.db.Create(&task) + return result.Error +} + +func (bc BotController) DeleteTask(taskID int64) error { + result := bc.db.Delete(&Task{}, taskID) + return result.Error +} + +func (bc BotController) GetAllTasks() ([]Task, error) { + var tasks []Task + result := bc.db.Find(&tasks) + if result.Error != nil { + return nil, result.Error + } + return tasks, nil +}