diff --git a/handlers/accounts_handler.go b/handlers/accounts_handler.go index 288fd2e45..af3a3f49f 100644 --- a/handlers/accounts_handler.go +++ b/handlers/accounts_handler.go @@ -105,7 +105,7 @@ func (handler *ApiHandler) NewCloudAccountHandler(c *gin.Context) { unsavedAccounts = append(unsavedAccounts, account) } else { - result, err := handler.dbHandler.HandleQuery(handler.ctx, "ADD_ACCOUNT", &account, nil) + result, err := handler.dbHandler.HandleQuery(handler.ctx, "INSERT", &account, nil) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return @@ -170,7 +170,7 @@ func (handler *ApiHandler) DeleteCloudAccountHandler(c *gin.Context) { accountId := c.Param("id") account := new(models.Account) - _, err := handler.dbHandler.HandleQuery(handler.ctx, "DELETE_ACCOUNT", &account, map[string]string{"id": accountId}) + _, err := handler.dbHandler.HandleQuery(handler.ctx, "DELETE", &account, map[string]string{"id": accountId}) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return diff --git a/handlers/alerts_handler.go b/handlers/alerts_handler.go index 10fe3692f..8eff71aba 100644 --- a/handlers/alerts_handler.go +++ b/handlers/alerts_handler.go @@ -2,7 +2,6 @@ package handlers import ( "bytes" - "context" "encoding/json" "net/http" "time" @@ -33,7 +32,7 @@ func (handler *ApiHandler) NewAlertHandler(c *gin.Context) { return } - result, err := handler.db.NewInsert().Model(&alert).Exec(context.Background()) + result, err := handler.dbHandler.HandleQuery(handler.ctx, "INSERT", &alert, nil) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return @@ -62,7 +61,7 @@ func (handler *ApiHandler) UpdateAlertHandler(c *gin.Context) { return } - _, err = handler.db.NewUpdate().Model(&alert).Column("name", "type", "budget", "usage", "endpoint", "secret").Where("id = ?", alertId).Exec(handler.ctx) + _, err = handler.dbHandler.HandleQuery(handler.ctx, "UPDATE_ALERT",&alert, map[string]string{"id": alertId}) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return @@ -75,7 +74,7 @@ func (handler *ApiHandler) DeleteAlertHandler(c *gin.Context) { alertId := c.Param("id") alert := new(models.Alert) - _, err := handler.db.NewDelete().Model(alert).Where("id = ?", alertId).Exec(handler.ctx) + _, err := handler.dbHandler.HandleQuery(handler.ctx, "DELETE", &alert, map[string]string{"id": alertId}) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return diff --git a/models/queries.go b/models/queries.go index cd5bb8d78..4811db4b9 100644 --- a/models/queries.go +++ b/models/queries.go @@ -5,21 +5,21 @@ var Queries = Data{ Query: "SELECT * FROM accounts", Type: SELECT, }, - "INSERT_ACCOUNT": Object{ - Query: "", + "INSERT": Object{ Type: INSERT, }, - "DELETE_ACCOUNT": Object{ - Query: "", + "DELETE": Object{ Type: DELETE, }, "UPDATE_ACCOUNT": Object{ - Query: "", Type: UPDATE, Params: []string{"name", "provider", "credentials"}, }, + "UPDATE_ALERT": Object{ + Type: UPDATE, + Params: []string{"name", "type", "budget", "usage", "endpoint", "secret"}, + }, "RE_SCAN_ACCOUNT": Object{ - Query: "", Type: UPDATE, Params: []string{"status"}, },