Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion apiserver/internal/apis/caldav.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package apis

import (
"bytes"
"context"
"encoding/xml"
"io"
"net/http"
Expand All @@ -12,6 +13,7 @@ import (
authMW "dkhalife.com/tasks/core/internal/middleware/auth"
models "dkhalife.com/tasks/core/internal/models"
cRepo "dkhalife.com/tasks/core/internal/repos/caldav"
nRepo "dkhalife.com/tasks/core/internal/repos/notifier"
tRepo "dkhalife.com/tasks/core/internal/repos/task"
"dkhalife.com/tasks/core/internal/services/logging"
"dkhalife.com/tasks/core/internal/utils/auth"
Expand All @@ -20,18 +22,21 @@ import (
"dkhalife.com/tasks/core/internal/ws"
jwt "github.com/appleboy/gin-jwt/v2"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)

type CalDAVAPIHandler struct {
tRepo *tRepo.TaskRepository
cRepo *cRepo.CalDavRepository
nRepo *nRepo.NotificationRepository
ws *ws.WSServer
}

func CalDAVAPI(tRepo *tRepo.TaskRepository, cRepo *cRepo.CalDavRepository, wsServer *ws.WSServer) *CalDAVAPIHandler {
func CalDAVAPI(tRepo *tRepo.TaskRepository, cRepo *cRepo.CalDavRepository, nRepo *nRepo.NotificationRepository, wsServer *ws.WSServer) *CalDAVAPIHandler {
return &CalDAVAPIHandler{
tRepo: tRepo,
cRepo: cRepo,
nRepo: nRepo,
ws: wsServer,
}
}
Expand Down Expand Up @@ -272,6 +277,12 @@ func (h *CalDAVAPIHandler) handlePut(c *gin.Context) {
log.Errorf("Error getting updated task: %s", err.Error())
// Don't fail the request if we can't broadcast
} else {
// Regenerate notifications for the updated task
go func(task *models.Task, logger *zap.SugaredLogger) {
ctx := logging.ContextWithLogger(context.Background(), logger)
h.nRepo.GenerateNotifications(ctx, task)
}(updatedTask, log)

// Broadcast the update to all connected clients for this user
h.ws.BroadcastToUser(currentIdentity.UserID, ws.WSResponse{
Action: "task_updated",
Expand Down
4 changes: 2 additions & 2 deletions apiserver/internal/models/recurrence.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ type Frequency struct {
On RepeatOn `json:"on" validate:"required_if=Type interval custom" gorm:"type:varchar(18);default:null"`
Every int `json:"every" validate:"required_if=On interval" gorm:"type:int;default:null"`
Unit IntervalUnit `json:"unit" validate:"required_if=On interval" gorm:"type:varchar(9);default:null"`
Days []int32 `json:"days" validate:"required_if=Type custom On days_of_the_week,dive,gte=0,lte=6" gorm:"serializer:json;type:json"`
Months []int32 `json:"months" validate:"required_if=Type custom On day_of_the_months,dive,gte=0,lte=11" gorm:"serializer:json;type:json"`
Days []int32 `json:"days" validate:"required_if=Type custom On days_of_the_week,dive,gte=0,lte=6" gorm:"serializer:json"`
Months []int32 `json:"months" validate:"required_if=Type custom On day_of_the_months,dive,gte=0,lte=11" gorm:"serializer:json"`
}
2 changes: 1 addition & 1 deletion apiserver/internal/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type AppToken struct {
UserID int `json:"user_id" gorm:"column:user_id;not null"`
Name string `json:"name" gorm:"column:name;not null"`
Token string `json:"token" gorm:"column:token;index;not null"`
Scopes []string `json:"scopes" gorm:"column:scopes;serializer:json;type:json"`
Scopes []string `json:"scopes" gorm:"column:scopes;serializer:json"`
CreatedAt time.Time `json:"-" gorm:"column:created_at;default:CURRENT_TIMESTAMP"`
ExpiresAt time.Time `json:"expires_at" gorm:"column:expires_at;default:CURRENT_TIMESTAMP"`
User User `json:"-" gorm:"foreignKey:UserID"`
Expand Down
5 changes: 5 additions & 0 deletions apiserver/internal/services/tasks/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ func (s *TaskService) UpdateDueDate(ctx context.Context, userID, taskID int, req
}
}

go func(task *models.Task, logger *zap.SugaredLogger) {
ctx := logging.ContextWithLogger(context.Background(), logger)
s.n.GenerateNotifications(ctx, task)
}(task, log)

s.ws.BroadcastToUser(userID, ws.WSResponse{
Action: "task_updated",
Data: task,
Expand Down
Loading