diff --git a/pkg/internal/http/api/events_api.go b/pkg/internal/http/api/events_api.go index 0f56724..5bcc674 100644 --- a/pkg/internal/http/api/events_api.go +++ b/pkg/internal/http/api/events_api.go @@ -34,7 +34,7 @@ func getEvent(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusForbidden, fmt.Sprintf("you need join the channel before you read the messages: %v", err)) } - event, err := services.GetEvent(channel, uint(id)) + event, err := services.GetEvent(channel.ID, uint(id)) if err != nil { return fiber.NewError(fiber.StatusNotFound, err.Error()) } diff --git a/pkg/internal/services/events.go b/pkg/internal/services/events.go index f7176b2..7d96e3b 100644 --- a/pkg/internal/services/events.go +++ b/pkg/internal/services/events.go @@ -46,10 +46,10 @@ func ListEvent(channel models.Channel, take int, offset int) ([]models.Event, er } } -func GetEvent(channel models.Channel, id uint) (models.Event, error) { +func GetEvent(channelId uint, id uint) (models.Event, error) { var event models.Event if err := database.C. - Where("id = ? AND channel_id = ?", id, channel.ID). + Where("id = ? AND channel_id = ?", id, channelId). Preload("Sender"). First(&event).Error; err != nil { return event, err @@ -83,7 +83,7 @@ func NewEvent(event models.Event) (models.Event, error) { return event, nil } - event, err := GetEvent(event.Channel, event.ID) + event, err := GetEvent(event.ChannelID, event.ID) if err != nil { log.Error().Err(err).Msg("Failed to fetch event, the notifying of new event was terminated...") return event, err