package server import ( "log/slog" "net/http" "strings" "github.com/gin-gonic/gin" ) func (s *Server) adminMappings(c *gin.Context) { c.HTML(http.StatusOK, "mappings.html", gin.H{"Mappings": s.mappings.List()}) } func (s *Server) adminAddMapping(c *gin.Context) { source := strings.TrimSpace(c.PostForm("source")) slackEmail := strings.TrimSpace(c.PostForm("slack_email")) if source == "" || slackEmail == "" { c.String(http.StatusBadRequest, "source and slack_email are required") return } if err := s.mappings.Add(source, slackEmail); err != nil { slog.Error("add mapping failed", "source", source, "err", err) c.String(http.StatusInternalServerError, "failed to save") return } // Return the refreshed table partial (HTMX swaps it in). c.HTML(http.StatusOK, "table", gin.H{"Mappings": s.mappings.List()}) } func (s *Server) adminDeleteMapping(c *gin.Context) { source := c.Param("source") if err := s.mappings.Delete(source); err != nil { slog.Error("delete mapping failed", "source", source, "err", err) c.String(http.StatusInternalServerError, "failed to delete") return } c.HTML(http.StatusOK, "table", gin.H{"Mappings": s.mappings.List()}) }