feat(macros): align attachment uploads
This commit is contained in:
@@ -105,6 +105,10 @@ func (h *MacroHandler) Create(c *gin.Context) {
|
||||
}
|
||||
|
||||
if svcErr := h.svc.Create(c.Request.Context(), macro); svcErr != nil {
|
||||
if strings.Contains(svcErr.Error(), "invalid attachment") {
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": "invalid attachment"})
|
||||
return
|
||||
}
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
@@ -154,6 +158,10 @@ func (h *MacroHandler) Update(c *gin.Context) {
|
||||
|
||||
updated, svcErr := h.svc.UpdateForAccount(c.Request.Context(), accountID, macro)
|
||||
if svcErr != nil {
|
||||
if strings.Contains(svcErr.Error(), "invalid attachment") {
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": "invalid attachment"})
|
||||
return
|
||||
}
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
@@ -312,9 +320,9 @@ type macroActionRequest struct {
|
||||
}
|
||||
|
||||
type macroRequest struct {
|
||||
Name string `json:"name"`
|
||||
Visibility interface{} `json:"visibility"`
|
||||
Actions []macroActionRequest `json:"actions"`
|
||||
Name string `json:"name"`
|
||||
Visibility interface{} `json:"visibility"`
|
||||
Actions *[]macroActionRequest `json:"actions"`
|
||||
}
|
||||
|
||||
func bindMacroRequest(c *gin.Context) (*automation.Macro, error) {
|
||||
@@ -322,13 +330,16 @@ func bindMacroRequest(c *gin.Context) (*automation.Macro, error) {
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
actions := make(automation.Actions, 0, len(req.Actions))
|
||||
for _, actionReq := range req.Actions {
|
||||
params, err := normalizeAutomationActionParams(actionReq.ActionName, actionReq.ActionParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var actions automation.Actions
|
||||
if req.Actions != nil {
|
||||
actions = make(automation.Actions, 0, len(*req.Actions))
|
||||
for _, actionReq := range *req.Actions {
|
||||
params, err := normalizeAutomationActionParams(actionReq.ActionName, actionReq.ActionParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
actions = append(actions, automation.Action{ActionName: actionReq.ActionName, ActionParams: params})
|
||||
}
|
||||
actions = append(actions, automation.Action{ActionName: actionReq.ActionName, ActionParams: params})
|
||||
}
|
||||
return &automation.Macro{
|
||||
Name: strings.TrimSpace(req.Name),
|
||||
@@ -392,6 +403,21 @@ func serializeMacro(macro *automation.Macro) gin.H {
|
||||
if macro.UpdatedBy != nil && macro.UpdatedBy.ID != 0 {
|
||||
item["updated_by"] = serializeMacroAgent(macro.UpdatedBy)
|
||||
}
|
||||
if len(macro.Files) > 0 {
|
||||
files := make([]gin.H, 0, len(macro.Files))
|
||||
for _, file := range macro.Files {
|
||||
files = append(files, gin.H{
|
||||
"id": file.ID,
|
||||
"macro_id": file.MacroID,
|
||||
"file_type": file.FileType,
|
||||
"account_id": file.AccountID,
|
||||
"file_url": file.FileURL,
|
||||
"blob_id": file.BlobID,
|
||||
"filename": file.Filename,
|
||||
})
|
||||
}
|
||||
item["files"] = files
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user