feat: complete current GoChat updates
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/gochat/gochat/internal/model"
|
||||
"github.com/gochat/gochat/internal/repository"
|
||||
"github.com/gochat/gochat/internal/service"
|
||||
"github.com/gochat/gochat/internal/ws"
|
||||
applogger "github.com/gochat/gochat/pkg/logger"
|
||||
"github.com/gochat/gochat/pkg/response"
|
||||
)
|
||||
@@ -18,8 +19,9 @@ import (
|
||||
// Reference: Chatwoot app/controllers/api/v1/accounts/agents_controller.rb
|
||||
// An "agent" in Chatwoot is a User with an AccountUser membership in a specific account.
|
||||
type AgentHandler struct {
|
||||
svc *service.AgentService
|
||||
audit *service.AuditService
|
||||
svc *service.AgentService
|
||||
audit *service.AuditService
|
||||
events *ws.EventPublisher
|
||||
}
|
||||
|
||||
func (h *AgentHandler) WithAuditService(audit *service.AuditService) *AgentHandler {
|
||||
@@ -27,6 +29,11 @@ func (h *AgentHandler) WithAuditService(audit *service.AuditService) *AgentHandl
|
||||
return h
|
||||
}
|
||||
|
||||
func (h *AgentHandler) WithEventPublisher(events *ws.EventPublisher) *AgentHandler {
|
||||
h.events = events
|
||||
return h
|
||||
}
|
||||
|
||||
// NewAgentHandler creates a new AgentHandler.
|
||||
func NewAgentHandler(svc *service.AgentService) *AgentHandler {
|
||||
return &AgentHandler{svc: svc}
|
||||
@@ -127,6 +134,7 @@ func (h *AgentHandler) Create(c *gin.Context) {
|
||||
|
||||
c.Header("Cache-Control", "no-store")
|
||||
recordAuditMutation(c, h.audit, auditMutation{AccountID: accountID, AuditableType: "User", AuditableID: agent.ID, Action: "create", AuditedChanges: gin.H{"role": agent.Role, "active": agent.Active}})
|
||||
publishRealtimeEvent(h.events, accountID, "page:reload", nil)
|
||||
c.JSON(http.StatusOK, serializeAgentDetail(agent, accountID))
|
||||
}
|
||||
|
||||
@@ -171,6 +179,7 @@ func (h *AgentHandler) Update(c *gin.Context) {
|
||||
}
|
||||
|
||||
recordAuditMutation(c, h.audit, auditMutation{AccountID: accountID, AuditableType: "User", AuditableID: uint(id), Action: "update", AuditedChanges: agentUpdateAuditChanges(req)})
|
||||
publishRealtimeEvent(h.events, accountID, "page:reload", nil)
|
||||
c.JSON(http.StatusOK, serializeAgentDetail(agent, accountID))
|
||||
}
|
||||
|
||||
@@ -198,6 +207,7 @@ func (h *AgentHandler) Delete(c *gin.Context) {
|
||||
}
|
||||
|
||||
recordAuditMutation(c, h.audit, auditMutation{AccountID: accountID, AuditableType: "User", AuditableID: uint(id), Action: "destroy", AuditedChanges: gin.H{"account_id": accountID}})
|
||||
publishRealtimeEvent(h.events, accountID, "page:reload", nil)
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
@@ -267,6 +277,7 @@ func (h *AgentHandler) BulkCreate(c *gin.Context) {
|
||||
}
|
||||
|
||||
c.Header("Cache-Control", "no-store")
|
||||
publishRealtimeEvent(h.events, accountID, "page:reload", nil)
|
||||
c.JSON(http.StatusOK, serializeAgentDetails(agents, accountID))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user