68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"dealroom/internal/rbac"
|
|
"dealroom/templates"
|
|
)
|
|
|
|
func (h *Handler) handleRequestList(w http.ResponseWriter, r *http.Request) {
|
|
profile := getProfile(r.Context())
|
|
deals := h.getDeals(profile)
|
|
|
|
// Get all requests grouped by deal
|
|
dealRequests := make(map[string][]*templates.RequestsByGroup)
|
|
for _, deal := range deals {
|
|
reqs := h.getRequests(deal.ID, profile)
|
|
// Group by buyer_group
|
|
groups := make(map[string][]*templates.RequestItem)
|
|
for _, req := range reqs {
|
|
group := req.BuyerGroup
|
|
if group == "" {
|
|
group = "Unassigned"
|
|
}
|
|
groups[group] = append(groups[group], &templates.RequestItem{
|
|
ID: req.ID,
|
|
ItemNumber: req.ItemNumber,
|
|
Section: req.Section,
|
|
Description: req.Description,
|
|
Priority: req.Priority,
|
|
AtlasStatus: req.AtlasStatus,
|
|
AtlasNote: req.AtlasNote,
|
|
Confidence: req.Confidence,
|
|
BuyerComment: req.BuyerComment,
|
|
SellerComment: req.SellerComment,
|
|
BuyerGroup: req.BuyerGroup,
|
|
})
|
|
}
|
|
var groupList []*templates.RequestsByGroup
|
|
for name, items := range groups {
|
|
groupList = append(groupList, &templates.RequestsByGroup{Name: name, Requests: items})
|
|
}
|
|
dealRequests[deal.ID] = groupList
|
|
}
|
|
|
|
templates.RequestListPage(profile, deals, dealRequests).Render(r.Context(), w)
|
|
}
|
|
|
|
func (h *Handler) handleUpdateComment(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodPost {
|
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
profile := getProfile(r.Context())
|
|
reqID := r.FormValue("request_id")
|
|
value := r.FormValue("value")
|
|
|
|
field := "seller_comment"
|
|
if rbac.EffectiveIsBuyer(profile) {
|
|
field = "buyer_comment"
|
|
}
|
|
|
|
h.db.Exec("UPDATE diligence_requests SET "+field+" = ?, updated_at = datetime('now') WHERE id = ?", value, reqID)
|
|
|
|
w.Header().Set("Content-Type", "text/html")
|
|
w.Write([]byte(`<span class="text-xs text-green-400">✓ Saved</span>`))
|
|
}
|