heating-monitor/internal/repository/repository.go
2024-11-28 13:52:58 +01:00

32 lines
814 B
Go

package repository
import (
"heating-monitor/internal/bot"
"gorm.io/gorm"
)
// GetEventByID obtiene un evento de la base de datos por su ID
func GetEventByID(db *gorm.DB, id int) (*bot.HeatingEvent, error) {
var event bot.HeatingEvent
if err := db.First(&event, id).Error; err != nil {
return nil, err
}
return &event, nil
}
// UpdateEventByID actualiza un evento por su ID
func UpdateEventByID(db *gorm.DB, id int, updatedEvent *bot.HeatingEvent) (*bot.HeatingEvent, error) {
var event bot.HeatingEvent
if err := db.First(&event, id).Error; err != nil {
return nil, err
}
// Actualizamos los campos relevantes del evento
event.EventType = updatedEvent.EventType
event.Timestamp = updatedEvent.Timestamp
if err := db.Save(&event).Error; err != nil {
return nil, err
}
return &event, nil
}