Yimaru-BackEnd/internal/services/report/notification.go
Samuel Tariku 0ffba57ec5 feat: Refactor report generation and management
- Removed detailed event routes from the API.
- Added new report request routes for creating and fetching report requests.
- Introduced new domain models for report requests, including metadata and status handling.
- Implemented report request processing logic, including CSV generation for event interval reports.
- Enhanced company statistics handling with new domain models and service methods.
- Updated repository interfaces and implementations to support new report functionalities.
- Added error handling and logging for report file operations and notifications.
2025-10-28 00:51:52 +03:00

73 lines
1.8 KiB
Go

package report
import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
)
var (
ErrInvalidRequestedByID = errors.New("requested_by needs to be filled in to send report notification")
)
func (s *Service) SendReportRequestNotification(ctx context.Context, param domain.ReportRequestDetail) error {
if !param.RequestedBy.Valid {
return ErrInvalidRequestedByID
}
var (
headline string
message string
level domain.NotificationLevel
)
switch param.Status {
case domain.SuccessReportRequest:
headline = "Report Ready for Download"
message = fmt.Sprintf(
"Your %s report has been successfully generated and is now available for download.",
strings.ToLower(string(param.Type)),
)
level = domain.NotificationLevelSuccess
case domain.RejectReportRequest:
headline = "Report Generation Failed"
message = fmt.Sprintf(
"We were unable to generate your %s report. Please review your request and try again.",
strings.ToLower(string(param.Type)),
)
level = domain.NotificationLevelError
default:
return fmt.Errorf("unsupported request status: %v", param.Status)
}
raw, _ := json.Marshal(map[string]any{
"report_id": param.ID,
"type": param.Type,
"status": param.Status,
})
n := &domain.Notification{
RecipientID: param.RequestedBy.Value,
DeliveryStatus: domain.DeliveryStatusPending,
IsRead: false,
Type: domain.NotificationTypeReportRequest,
Level: level,
Reciever: domain.NotificationRecieverSideCustomer,
DeliveryChannel: domain.DeliveryChannelInApp,
Payload: domain.NotificationPayload{
Headline: headline,
Message: message,
},
Priority: 2,
Metadata: raw,
}
return s.notificationSvc.SendNotification(ctx, n)
}