package handlers import ( "net/http" "text/template" "synlotto-website/helpers" "synlotto-website/models" "synlotto-website/storage" ) func NotificationsHandler(w http.ResponseWriter, r *http.Request) { session, _ := helpers.GetSession(w, r) var user *models.User switch v := session.Values["user_id"].(type) { case int: user = models.GetUserByID(v) case int64: user = models.GetUserByID(int(v)) } var ( isAdmin bool notificationCount int notifications []models.Notification ) if user != nil { isAdmin = user.IsAdmin notificationCount = storage.GetNotificationCount(user.Id) notifications = storage.GetRecentNotifications(user.Id, 15) } tmpl := template.Must(template.New("notifications.html"). Funcs(helpers.TemplateFuncs()). ParseFiles("templates/notifications.html")) context := helpers.TemplateContext(w, r, user, isAdmin, notificationCount, notifications) if err := tmpl.Execute(w, context); err != nil { http.Error(w, "Template rendering error", http.StatusInternalServerError) } }