Rename ticktickutil, add interface for di
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/t-liu93/home-automation-backend/util/ticktick"
|
||||
"github.com/t-liu93/home-automation-backend/util/ticktickutil"
|
||||
)
|
||||
|
||||
type haMessage struct {
|
||||
@@ -23,6 +23,14 @@ type actionTask struct {
|
||||
DueHour int `json:"due_hour"`
|
||||
}
|
||||
|
||||
var (
|
||||
ticktickUtil ticktickutil.TicktickUtil
|
||||
)
|
||||
|
||||
func Init(ticktick ticktickutil.TicktickUtil) {
|
||||
ticktickUtil = ticktick
|
||||
}
|
||||
|
||||
func HandleHaMessage(w http.ResponseWriter, r *http.Request) {
|
||||
var message haMessage
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
@@ -112,13 +120,13 @@ func createActionTask(message haMessage) {
|
||||
dueHour := task.DueHour
|
||||
due := time.Now().Add(time.Hour * time.Duration(dueHour))
|
||||
dueNextMidnight := time.Date(due.Year(), due.Month(), due.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, 1)
|
||||
dueTicktick := dueNextMidnight.UTC().Format(ticktick.DateTimeLayout)
|
||||
ticktickTask := ticktick.Task{
|
||||
dueTicktick := dueNextMidnight.UTC().Format(ticktickutil.DateTimeLayout)
|
||||
ticktickTask := ticktickutil.Task{
|
||||
ProjectId: projectId,
|
||||
Title: task.Action,
|
||||
DueDate: dueTicktick,
|
||||
}
|
||||
err = ticktick.CreateTask(ticktickTask)
|
||||
err = ticktickUtil.CreateTask(ticktickTask)
|
||||
if err != nil {
|
||||
slog.Warn(fmt.Sprintf("Homeassistant.createActionTask Error creating task %s", err))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user