add user role

This commit is contained in:
Aditya Siregar
2025-09-08 15:21:17 +07:00
parent 2319019eb2
commit d869d83d4b
14 changed files with 162 additions and 56 deletions
+3 -7
View File
@@ -3,6 +3,7 @@ package service
import (
"context"
"eslogad-be/internal/logger"
"fmt"
"time"
"eslogad-be/internal/appcontext"
@@ -134,7 +135,6 @@ func (s *LetterServiceImpl) CreateIncomingLetter(ctx context.Context, req *contr
return nil, err
}
// Send notifications to all recipients after successful creation
if s.notificationProcessor != nil && len(recipients) > 0 {
go s.sendLetterNotifications(context.Background(), result, recipients)
}
@@ -239,19 +239,15 @@ func (s *LetterServiceImpl) addCreatorAsRecipient(ctx context.Context, letterID
func (s *LetterServiceImpl) sendLetterNotifications(ctx context.Context, letter *contract.IncomingLetterResponse, recipients []entities.LetterIncomingRecipient) {
for _, recipient := range recipients {
// Only send notification to user recipients (not department recipients)
// Also exclude the creator from receiving notifications
if recipient.RecipientUserID != nil && *recipient.RecipientUserID != letter.CreatedBy {
// Use description if available, otherwise use subject
if recipient.Status != "completed" {
err := s.notificationProcessor.SendIncomingLetterNotification(
ctx,
letter.ID,
*recipient.RecipientUserID,
"Surat Masuk",
letter.Subject)
fmt.Sprintf("%s: %s", letter.SenderInstitution.Name, letter.Subject))
if err != nil {
// Log error but don't fail the entire operation
logger.FromContext(ctx).Error("failed to send notification", err)
}
}