Skip to content

Commit 5f46599

Browse files
committed
Implement Price Alerts for Cryptocurrencies
1 parent 85dd725 commit 5f46599

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

models/event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ type Event struct {
99
ToAddress string `gorm:"index"`
1010
Value string `gorm:"type:numeric"`
1111
EventType string `gorm:"index"`
12+
Message string
1213
Notified bool
1314
}

services/price_alert.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,13 @@ func (s *PriceAlertService) triggerAlert(alert *models.PriceAlert, currentPrice
7474
)
7575

7676
if alert.EmailNotification {
77-
// Create event for notification
7877
event := &models.Event{
79-
EventType: "PRICE_ALERT",
80-
Value: fmt.Sprintf("%.2f", currentPrice),
78+
EventType: "PRICE_ALERT",
79+
Value: fmt.Sprintf("%.2f", currentPrice),
80+
Message: message,
81+
FromAddress: "PriceAlert",
82+
ToAddress: alert.UserID,
83+
Notified: false,
8184
}
8285

8386
userPref := &models.UserPreference{
@@ -89,9 +92,4 @@ func (s *PriceAlertService) triggerAlert(alert *models.PriceAlert, currentPrice
8992
log.Printf("Failed to send price alert email: %v", err)
9093
}
9194
}
92-
93-
// Deactivate the alert after triggering
94-
if err := s.alertRepo.DeactivateAlert(alert.ID); err != nil {
95-
log.Printf("Failed to deactivate alert: %v", err)
96-
}
9795
}

0 commit comments

Comments
 (0)