dealroom/internal/handler/contacts.go

29 lines
760 B
Go

package handler
import (
"net/http"
"dealroom/internal/model"
"dealroom/templates"
)
func (h *Handler) handleContacts(w http.ResponseWriter, r *http.Request) {
profile := getProfile(r.Context())
rows, err := h.db.Query("SELECT id, full_name, email, phone, company, title, contact_type, tags FROM contacts WHERE organization_id = ? ORDER BY full_name", profile.OrganizationID)
if err != nil {
http.Error(w, "Error loading contacts", 500)
return
}
defer rows.Close()
var contacts []*model.Contact
for rows.Next() {
c := &model.Contact{}
rows.Scan(&c.ID, &c.FullName, &c.Email, &c.Phone, &c.Company, &c.Title, &c.ContactType, &c.Tags)
contacts = append(contacts, c)
}
templates.ContactsPage(profile, contacts).Render(r.Context(), w)
}