Add subtask model and repository, implement webhook notification handling

fix Issue with Scheduler
Support NotificationPlatformWebhook
support Discord as notification target
This commit is contained in:
Mo Tarbin 2025-03-05 19:52:10 -05:00
parent 8db572f1ec
commit 81acbd8eba
8 changed files with 136 additions and 11 deletions

View file

@ -243,7 +243,6 @@ func (h *Handler) createChore(c *gin.Context) {
stringLabels = &labels
}
createdChore := &chModel.Chore{
Name: choreReq.Name,
FrequencyType: choreReq.FrequencyType,
Frequency: choreReq.Frequency,
@ -264,6 +263,7 @@ func (h *Handler) createChore(c *gin.Context) {
CompletionWindow: choreReq.CompletionWindow,
Description: choreReq.Description,
SubTasks: choreReq.SubTasks,
Priority: choreReq.Priority,
}
id, err := h.choreRepo.CreateChore(c, createdChore)
createdChore.ID = id
@ -547,6 +547,7 @@ func (h *Handler) editChore(c *gin.Context) {
if choreReq.SubTasks == nil {
choreReq.SubTasks = &[]stModel.SubTask{}
}
// check what subtask needed to be removed:
for _, existedSubTask := range *oldChore.SubTasks {
found := false
for _, newSubTask := range *choreReq.SubTasks {
@ -559,14 +560,16 @@ func (h *Handler) editChore(c *gin.Context) {
ToBeRemoved = append(ToBeRemoved, existedSubTask)
}
}
// check what subtask needed to be added or updated:
for _, newSubTask := range *choreReq.SubTasks {
found := false
newSubTask.ChoreID = oldChore.ID
for _, existedSubTask := range *oldChore.SubTasks {
if existedSubTask.ID == newSubTask.ID {
if existedSubTask.Name != newSubTask.Name || existedSubTask.OrderID != newSubTask.OrderID {
if existedSubTask.Name != newSubTask.Name ||
existedSubTask.OrderID != newSubTask.OrderID ||
existedSubTask.ParentId != newSubTask.ParentId {
// there is a change in the subtask, update it
break
}

View file

@ -38,9 +38,8 @@ func scheduleNextDueDate(chore *chModel.Chore, completedDate time.Time) (*time.T
if err != nil {
return nil, fmt.Errorf("error parsing time in frequency metadata: %w", err)
}
t = t.UTC()
baseDate = time.Date(baseDate.Year(), baseDate.Month(), baseDate.Day(), t.Hour(), t.Minute(), t.Second(), 0, time.UTC)
// If the time is in the past today, move it to tomorrow
if baseDate.Before(completedDate) {
baseDate = baseDate.AddDate(0, 0, 1)