@@ -73,16 +73,21 @@ type Message struct {
7373 // SendDuration is the number of nanoseconds from when the request was received until when the mobile phone send the message
7474 SendDuration * int64 `json:"send_time" example:"133414"`
7575
76- RequestReceivedAt time.Time `json:"request_received_at" example:"2022-06-05T14:26:01.520828+03:00"`
77- CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"`
78- UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"`
79- OrderTimestamp time.Time `json:"order_timestamp" gorm:"index:idx_messages_order_timestamp" example:"2022-06-05T14:26:09.527976+03:00"`
80- LastAttemptedAt * time.Time `json:"last_attempted_at" example:"2022-06-05T14:26:09.527976+03:00"`
81- ScheduledAt * time.Time `json:"scheduled_at" example:"2022-06-05T14:26:09.527976+03:00"`
82- SentAt * time.Time `json:"sent_at" example:"2022-06-05T14:26:09.527976+03:00"`
83- ReceivedAt * time.Time `json:"received_at" example:"2022-06-05T14:26:09.527976+03:00"`
84- SendAttempts []time.Time `json:"send_attempts"`
85- FailureReason * string `json:"failure_reason" example:"UNKNOWN"`
76+ RequestReceivedAt time.Time `json:"request_received_at" example:"2022-06-05T14:26:01.520828+03:00"`
77+ CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"`
78+ UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"`
79+ OrderTimestamp time.Time `json:"order_timestamp" gorm:"index:idx_messages_order_timestamp" example:"2022-06-05T14:26:09.527976+03:00"`
80+ LastAttemptedAt * time.Time `json:"last_attempted_at" example:"2022-06-05T14:26:09.527976+03:00"`
81+ NotificationScheduledAt * time.Time `json:"scheduled_at" example:"2022-06-05T14:26:09.527976+03:00"`
82+ SentAt * time.Time `json:"sent_at" example:"2022-06-05T14:26:09.527976+03:00"`
83+ DeliveredAt * time.Time `json:"delivered_at" example:"2022-06-05T14:26:09.527976+03:00"`
84+ ExpiredAt * time.Time `json:"expired_at" example:"2022-06-05T14:26:09.527976+03:00"`
85+ FailedAt * time.Time `json:"failed_at" example:"2022-06-05T14:26:09.527976+03:00"`
86+ CanBePolled bool `json:"can_be_polled" example:"false"`
87+ SendAttemptCount uint `json:"send_attempt_count" example:"0"`
88+ MaxSendAttempts uint `json:"max_send_attempts" example:"1"`
89+ ReceivedAt * time.Time `json:"received_at" example:"2022-06-05T14:26:09.527976+03:00"`
90+ FailureReason * string `json:"failure_reason" example:"UNKNOWN"`
8691}
8792
8893// IsSending determines if a message is being sent
@@ -100,11 +105,21 @@ func (message *Message) IsPending() bool {
100105 return message .Status == MessageStatusPending
101106}
102107
108+ // IsScheduled checks if a message is scheduled
109+ func (message * Message ) IsScheduled () bool {
110+ return message .Status == MessageStatusScheduled
111+ }
112+
103113// IsExpired checks if a message is expired
104114func (message * Message ) IsExpired () bool {
105115 return message .Status == MessageStatusExpired
106116}
107117
118+ // CanBeRescheduled checks if a message can be rescheduled
119+ func (message * Message ) CanBeRescheduled () bool {
120+ return message .SendAttemptCount < message .MaxSendAttempts
121+ }
122+
108123// IsSent determines if a message has been sent
109124func (message * Message ) IsSent () bool {
110125 return message .Status == MessageStatusSent
@@ -122,7 +137,7 @@ func (message *Message) Sent(timestamp time.Time) *Message {
122137
123138// Failed registers a message as failed
124139func (message * Message ) Failed (timestamp time.Time , errorMessage string ) * Message {
125- message .SentAt = & timestamp
140+ message .FailedAt = & timestamp
126141 message .Status = MessageStatusFailed
127142 message .FailureReason = & errorMessage
128143 message .updateOrderTimestamp (timestamp )
@@ -131,16 +146,26 @@ func (message *Message) Failed(timestamp time.Time, errorMessage string) *Messag
131146
132147// Delivered registers a message as delivered
133148func (message * Message ) Delivered (timestamp time.Time ) * Message {
134- message .SentAt = & timestamp
149+ message .DeliveredAt = & timestamp
135150 message .Status = MessageStatusDelivered
136151 message .updateOrderTimestamp (timestamp )
137152 return message
138153}
139154
140155// Expired registers a message as expired
141156func (message * Message ) Expired (timestamp time.Time ) * Message {
142- message .SentAt = & timestamp
157+ message .ExpiredAt = & timestamp
143158 message .Status = MessageStatusExpired
159+ message .CanBePolled = true
160+ message .SendAttemptCount ++
161+ message .updateOrderTimestamp (timestamp )
162+ return message
163+ }
164+
165+ // NotificationScheduled registers a message as scheduled
166+ func (message * Message ) NotificationScheduled (timestamp time.Time ) * Message {
167+ message .NotificationScheduledAt = & timestamp
168+ message .Status = MessageStatusScheduled
144169 message .updateOrderTimestamp (timestamp )
145170 return message
146171}
0 commit comments