send notification update status letter
This commit is contained in:
parent
048ff264ce
commit
acb9f75a18
@ -575,9 +575,36 @@ func (s *LetterServiceImpl) GetDepartmentDispositionStatus(ctx context.Context,
|
||||
}
|
||||
|
||||
func (s *LetterServiceImpl) UpdateDispositionStatus(ctx context.Context, req *contract.UpdateDispositionStatusRequest) (*contract.DepartmentDispositionStatusResponse, error) {
|
||||
// For now, delegate to the processor which handles this
|
||||
// The processor needs to be refactored to remove context extraction
|
||||
return s.processor.UpdateDispositionStatus(ctx, req)
|
||||
var result *contract.DepartmentDispositionStatusResponse
|
||||
|
||||
err := s.txManager.WithTransaction(ctx, func(txCtx context.Context) error {
|
||||
var err error
|
||||
result, err = s.processor.UpdateDispositionStatus(txCtx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Log activity for disposition status update
|
||||
if s.activityLogger != nil && result != nil {
|
||||
userID := appcontext.FromGinContext(txCtx).UserID
|
||||
if err := s.activityLogger.LogLetterDispositionStatusUpdate(txCtx, req.LetterIncomingID, userID, req.Status); err != nil {
|
||||
// Don't fail the transaction for logging errors
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send notification to letter creator asynchronously
|
||||
if s.notificationProcessor != nil && result != nil {
|
||||
go s.sendDispositionStatusUpdateNotification(context.Background(), req.LetterIncomingID, req.Status)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *LetterServiceImpl) GetLetterCTA(ctx context.Context, letterID uuid.UUID) (*contract.LetterCTAResponse, error) {
|
||||
@ -693,7 +720,7 @@ func (s *LetterServiceImpl) sendDispositionCreatorNotification(ctx context.Conte
|
||||
dispositionCreatorName := appContext.UserName
|
||||
|
||||
subject := "Disposisi Baru pada Surat Anda"
|
||||
message := fmt.Sprintf("Surat yang Anda buat telah didisposisikan oleh %s: %s",
|
||||
message := fmt.Sprintf("Surat yang Anda buat telah didisposisikan %s: %s",
|
||||
dispositionCreatorName, letter.Subject)
|
||||
|
||||
err = s.notificationProcessor.SendIncomingLetterNotification(
|
||||
@ -708,3 +735,55 @@ func (s *LetterServiceImpl) sendDispositionCreatorNotification(ctx context.Conte
|
||||
// You might want to add proper logging here
|
||||
}
|
||||
}
|
||||
|
||||
func (s *LetterServiceImpl) sendDispositionStatusUpdateNotification(ctx context.Context, letterID uuid.UUID, newStatus string) {
|
||||
// Get letter details
|
||||
letter, err := s.processor.GetIncomingLetterByID(ctx, letterID)
|
||||
if err != nil {
|
||||
// Log error but don't fail
|
||||
return
|
||||
}
|
||||
|
||||
// Get current user context (the one updating the status)
|
||||
appContext := appcontext.FromGinContext(ctx)
|
||||
updaterUserID := appContext.UserID
|
||||
updaterName := appContext.UserName
|
||||
|
||||
letterCreatorID := letter.CreatedBy
|
||||
|
||||
// Don't send notification if the updater is the same as letter creator
|
||||
if letterCreatorID == updaterUserID {
|
||||
return
|
||||
}
|
||||
|
||||
// Create status-specific notification message
|
||||
var statusMessage string
|
||||
switch newStatus {
|
||||
case "pending":
|
||||
statusMessage = "sedang menunggu"
|
||||
case "in_progress":
|
||||
statusMessage = "sedang diproses"
|
||||
case "completed":
|
||||
statusMessage = "telah diselesaikan"
|
||||
case "cancelled":
|
||||
statusMessage = "dibatalkan"
|
||||
default:
|
||||
statusMessage = fmt.Sprintf("diubah statusnya menjadi %s", newStatus)
|
||||
}
|
||||
|
||||
subject := "Status Disposisi Surat Diperbarui"
|
||||
message := fmt.Sprintf("Disposisi surat '%s' %s %s",
|
||||
letter.Subject, statusMessage, updaterName)
|
||||
|
||||
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