Added temperature exceded event

This commit is contained in:
Nedim
2023-10-16 19:43:35 +02:00
parent 44efa194fc
commit 2e60460131
7 changed files with 109 additions and 70 deletions

View File

@@ -12,18 +12,18 @@ import (
)
func GetNotificationsForUserID(userID int, afterTime time.Time) ([]models.GetNotificationsResponse, int, error) {
func GetNotificationsForCompanyID(companyID int, afterTime time.Time) ([]models.GetNotificationsResponse, int, error) {
// Create a slice to hold the notifications
var notifications []models.Notification
var customNotifications []models.GetNotificationsResponse
// Fetch notifications from the database based on UserID and creation time
if err := shared.GetDb().Where("user_id = ? AND created_at > ?", userID, afterTime).Find(&notifications).Error; err != nil {
if err := shared.GetDb().Where("company_id = ? AND created_at > ?", companyID, afterTime).Find(&notifications).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
log.Printf("GetNotificationsForUserID Error: No notifications found: %v", err)
log.Printf("GetNotificationsForCompanyID Error: No notifications found: %v", err)
return customNotifications, http.StatusNotFound, err
} else {
log.Printf("GetNotificationsForUserID Error: Database error: %v", err)
log.Printf("GetNotificationsForCompanyID Error: Database error: %v", err)
return customNotifications, http.StatusInternalServerError, err
}
}