Yimaru-BackEnd/internal/domain/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

136 lines
5.8 KiB
Go

package domain
import (
"encoding/json"
"time"
)
type NotificationType string
type NotificationRecieverSide string
type NotificationDeliveryScheme string
type NotificationLevel string
type NotificationErrorSeverity string
type NotificationDeliveryStatus string
type DeliveryChannel string
const (
NotificationTypeWalletUpdated NotificationType = "wallet_updated"
NotificationTypeDepositResult NotificationType = "deposit_result"
NotificationTypeDepositVerification NotificationType = "deposit_verification"
NotificationTypeCashOutSuccess NotificationType = "cash_out_success"
NotificationTypeDepositSuccess NotificationType = "deposit_success"
NotificationTypeWithdrawSuccess NotificationType = "withdraw_success"
NotificationTypeBetPlaced NotificationType = "bet_placed"
NotificationTypeDailyReport NotificationType = "daily_report"
NotificationTypeReportRequest NotificationType = "report_request"
NotificationTypeHighLossOnBet NotificationType = "high_loss_on_bet"
NotificationTypeBetOverload NotificationType = "bet_overload"
NotificationTypeSignUpWelcome NotificationType = "signup_welcome"
NotificationTypeOTPSent NotificationType = "otp_sent"
NOTIFICATION_TYPE_WALLET NotificationType = "wallet_threshold"
NOTIFICATION_TYPE_TRANSFER_FAIL NotificationType = "transfer_failed"
NOTIFICATION_TYPE_TRANSFER_SUCCESS NotificationType = "transfer_success"
NOTIFICATION_TYPE_ADMIN_ALERT NotificationType = "admin_alert"
NOTIFICATION_TYPE_BET_RESULT NotificationType = "bet_result"
NOTIFICATION_TYPE_TRANSFER_REJECTED NotificationType = "transfer_rejected"
NOTIFICATION_TYPE_APPROVAL_REQUIRED NotificationType = "approval_required"
NOTIFICATION_TYPE_BONUS_AWARDED NotificationType = "bonus_awarded"
NotificationRecieverSideAdmin NotificationRecieverSide = "admin"
NotificationRecieverSideCustomer NotificationRecieverSide = "customer"
NotificationRecieverSideCashier NotificationRecieverSide = "cashier"
NotificationRecieverSideBranchManager NotificationRecieverSide = "branch_manager"
NotificationDeliverySchemeBulk NotificationDeliveryScheme = "bulk"
NotificationDeliverySchemeSingle NotificationDeliveryScheme = "single"
NotificationLevelInfo NotificationLevel = "info"
NotificationLevelError NotificationLevel = "error"
NotificationLevelWarning NotificationLevel = "warning"
NotificationLevelSuccess NotificationLevel = "success"
NotificationErrorSeverityLow NotificationErrorSeverity = "low"
NotificationErrorSeverityMedium NotificationErrorSeverity = "medium"
NotificationErrorSeverityHigh NotificationErrorSeverity = "high"
NotificationErrorSeverityCritical NotificationErrorSeverity = "critical"
NotificationErrorSeverityFatal NotificationErrorSeverity = "fatal"
DeliveryStatusPending NotificationDeliveryStatus = "pending"
DeliveryStatusSent NotificationDeliveryStatus = "sent"
DeliveryStatusFailed NotificationDeliveryStatus = "failed"
DeliveryChannelEmail DeliveryChannel = "email"
DeliveryChannelSMS DeliveryChannel = "sms"
DeliveryChannelPush DeliveryChannel = "push"
DeliveryChannelInApp DeliveryChannel = "in-app"
)
type NotificationPayload struct {
Headline string `json:"headline"`
Message string `json:"message"`
Tags []string `json:"tags"`
}
type Notification struct {
ID string `json:"id"`
RecipientID int64 `json:"recipient_id"`
Type NotificationType `json:"type"`
Level NotificationLevel `json:"level"`
ErrorSeverity NotificationErrorSeverity `json:"error_severity"`
Reciever NotificationRecieverSide `json:"reciever"`
IsRead bool `json:"is_read"`
DeliveryStatus NotificationDeliveryStatus `json:"delivery_status,omitempty"`
DeliveryChannel DeliveryChannel `json:"delivery_channel,omitempty"`
Payload NotificationPayload `json:"payload"`
Priority int `json:"priority,omitempty"`
Version int `json:"-"`
Timestamp time.Time `json:"timestamp"`
Expires time.Time `json:"expires"`
Image string `json:"image"`
Metadata json.RawMessage `json:"metadata,omitempty"`
}
type CreateNotification struct {
RecipientID int64 `json:"recipient_id"`
Type NotificationType `json:"type"`
Level NotificationLevel `json:"level"`
ErrorSeverity *NotificationErrorSeverity `json:"error_severity"`
Reciever NotificationRecieverSide `json:"reciever"`
IsRead bool `json:"is_read"`
DeliveryStatus NotificationDeliveryStatus `json:"delivery_status,omitempty"`
DeliveryChannel DeliveryChannel `json:"delivery_channel,omitempty"`
Payload NotificationPayload `json:"payload"`
Priority int `json:"priority,omitempty"`
Expires time.Time `json:"expires"`
Image string `json:"image,omitempty"`
Metadata json.RawMessage `json:"metadata,omitempty"`
}
func (n *Notification) ToJSON() ([]byte, error) {
return json.Marshal(n)
}
func FromJSON(data []byte) (*Notification, error) {
var n Notification
err := json.Unmarshal(data, &n)
if err != nil {
return nil, err
}
return &n, nil
}
func ReceiverFromRole(role Role) NotificationRecieverSide {
switch role {
case RoleAdmin:
return NotificationRecieverSideAdmin
case RoleCashier:
return NotificationRecieverSideCashier
case RoleBranchManager:
return NotificationRecieverSideBranchManager
case RoleCustomer:
return NotificationRecieverSideCustomer
default:
return ""
}
}