feat(audit): cover operational mutations
This commit is contained in:
@@ -16,7 +16,8 @@ import (
|
||||
// InboxHandler handles inbox-related API endpoints.
|
||||
// Reference: Chatwoot app/controllers/api/v1/inboxes_controller.rb
|
||||
type InboxHandler struct {
|
||||
svc *service.InboxService
|
||||
svc *service.InboxService
|
||||
auditSvc *service.AuditService
|
||||
}
|
||||
|
||||
// NewInboxHandler creates a new InboxHandler.
|
||||
@@ -24,6 +25,11 @@ func NewInboxHandler(svc *service.InboxService) *InboxHandler {
|
||||
return &InboxHandler{svc: svc}
|
||||
}
|
||||
|
||||
func (h *InboxHandler) WithAuditService(auditSvc *service.AuditService) *InboxHandler {
|
||||
h.auditSvc = auditSvc
|
||||
return h
|
||||
}
|
||||
|
||||
// @Summary List inboxes for an account
|
||||
// @Description Retrieves all inboxes for an account with pagination
|
||||
// @Tags Inboxes
|
||||
@@ -131,6 +137,13 @@ func (h *InboxHandler) Create(c *gin.Context) {
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": "failed to create inbox"})
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "Inbox",
|
||||
AuditableID: inbox.ID,
|
||||
Action: "create",
|
||||
AuditedChanges: serializeInbox(inbox),
|
||||
})
|
||||
|
||||
c.JSON(http.StatusOK, serializeInbox(inbox))
|
||||
}
|
||||
@@ -177,6 +190,13 @@ func (h *InboxHandler) Update(c *gin.Context) {
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": "failed to update inbox"})
|
||||
return
|
||||
}
|
||||
recordAuditMutation(c, h.auditSvc, auditMutation{
|
||||
AccountID: accountID,
|
||||
AuditableType: "Inbox",
|
||||
AuditableID: inbox.ID,
|
||||
Action: "update",
|
||||
AuditedChanges: serializeInbox(inbox),
|
||||
})
|
||||
|
||||
c.JSON(http.StatusOK, serializeInbox(inbox))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user