package handler import ( "net/http" "dealroom/templates" ) func (h *Handler) handleAuditLog(w http.ResponseWriter, r *http.Request) { profile := getProfile(r.Context()) dealID := r.URL.Query().Get("deal_id") buyerGroup := r.URL.Query().Get("buyer_group") deals := h.getDeals(profile) activities := h.getActivitiesFilteredBuyer(profile.OrganizationID, dealID, buyerGroup, 50) // Populate deal names dealNames := make(map[string]string) for _, d := range deals { dealNames[d.ID] = d.Name } for _, act := range activities { if name, ok := dealNames[act.DealID]; ok { act.DealName = name } } // Get distinct buyer groups for filter var buyerGroups []string rows, _ := h.db.Query(`SELECT DISTINCT COALESCE(buyer_group, '') FROM deal_activity WHERE organization_id = ? AND COALESCE(buyer_group, '') != '' ORDER BY buyer_group`, profile.OrganizationID) if rows != nil { for rows.Next() { var bg string rows.Scan(&bg) buyerGroups = append(buyerGroups, bg) } rows.Close() } templates.AuditLogPage(profile, activities, deals, dealID, buyerGroups, buyerGroup).Render(r.Context(), w) }