send notification to createor letter
This commit is contained in:
parent
cf6708899d
commit
048ff264ce
@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"eslogad-be/internal/appcontext"
|
||||
@ -448,6 +449,7 @@ func (s *LetterServiceImpl) SoftDeleteIncomingLetter(ctx context.Context, id uui
|
||||
}
|
||||
|
||||
func (s *LetterServiceImpl) CreateDispositions(ctx context.Context, req *contract.CreateLetterDispositionRequest) (*contract.ListDispositionsResponse, error) {
|
||||
log.Printf("[DEBUG] CreateDispositions START - LetterID: %s\n", req.LetterID.String())
|
||||
userID := appcontext.FromGinContext(ctx).UserID
|
||||
req.CreatedBy = userID
|
||||
|
||||
@ -486,8 +488,14 @@ func (s *LetterServiceImpl) CreateDispositions(ctx context.Context, req *contrac
|
||||
}
|
||||
|
||||
// Send notifications to newly created recipients asynchronously
|
||||
if s.notificationProcessor != nil && len(recipients) > 0 {
|
||||
go s.sendDispositionNotifications(context.Background(), req.LetterID, recipients)
|
||||
if s.notificationProcessor != nil {
|
||||
// Send notifications to newly created recipients
|
||||
if len(recipients) > 0 {
|
||||
go s.sendDispositionNotifications(context.Background(), req.LetterID, recipients)
|
||||
}
|
||||
|
||||
// Send notification to letter creator about new disposition
|
||||
go s.sendDispositionCreatorNotification(context.Background(), req.LetterID, userID)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@ -658,4 +666,45 @@ func (s *LetterServiceImpl) extractUserIDsFromMentions(mentions map[string]inter
|
||||
}
|
||||
|
||||
return userIDs
|
||||
}
|
||||
|
||||
func (s *LetterServiceImpl) sendDispositionCreatorNotification(ctx context.Context, letterID uuid.UUID, dispositionCreatorID uuid.UUID) {
|
||||
// Get letter details
|
||||
letter, err := s.processor.GetIncomingLetterByID(ctx, letterID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("[DEBUG] Starting sendDispositionCreatorNotification for letterID: %s\n", letterID.String())
|
||||
fmt.Printf("[DEBUG] Successfully retrieved letter: %s\n", letter.Subject)
|
||||
fmt.Printf("[DEBUG] Successfully retrieved letter: %s\n", letter.CreatedBy)
|
||||
|
||||
|
||||
|
||||
letterCreatorID := letter.CreatedBy
|
||||
|
||||
// Don't send notification if the disposition creator is the same as letter creator
|
||||
if letterCreatorID == dispositionCreatorID {
|
||||
return
|
||||
}
|
||||
|
||||
// Get disposition creator name from context
|
||||
appContext := appcontext.FromGinContext(ctx)
|
||||
dispositionCreatorName := appContext.UserName
|
||||
|
||||
subject := "Disposisi Baru pada Surat Anda"
|
||||
message := fmt.Sprintf("Surat yang Anda buat telah didisposisikan oleh %s: %s",
|
||||
dispositionCreatorName, letter.Subject)
|
||||
|
||||
err = s.notificationProcessor.SendIncomingLetterNotification(
|
||||
ctx,
|
||||
letterID,
|
||||
letterCreatorID,
|
||||
subject,
|
||||
message)
|
||||
|
||||
if err != nil {
|
||||
// Log error but don't fail the operation
|
||||
// You might want to add proper logging here
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user