From 61cf4512b0d6123330aa443ebec59eb1322cde77 Mon Sep 17 00:00:00 2001 From: email Date: Sat, 5 Feb 2022 13:17:43 +0800 Subject: [PATCH] fix: delete response json --- server/memo.go | 3 +-- server/resource.go | 2 ++ server/shortcut.go | 2 ++ store/shortcut.go | 4 ++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/server/memo.go b/server/memo.go index b433fa14..b54aa7f1 100644 --- a/server/memo.go +++ b/server/memo.go @@ -125,8 +125,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) { return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete memo ID: %v", memoId)).SetInternal(err) } - c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) - c.Response().WriteHeader(http.StatusOK) + c.JSON(http.StatusOK, true) return nil }) diff --git a/server/resource.go b/server/resource.go index 38b91d2c..3672c42a 100644 --- a/server/resource.go +++ b/server/resource.go @@ -89,6 +89,8 @@ func (s *Server) registerResourceRoutes(g *echo.Group) { return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete resource").SetInternal(err) } + c.JSON(http.StatusOK, true) + return nil }) } diff --git a/server/shortcut.go b/server/shortcut.go index 47b70978..27bfe16b 100644 --- a/server/shortcut.go +++ b/server/shortcut.go @@ -108,6 +108,8 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) { return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete shortcut").SetInternal(err) } + c.JSON(http.StatusOK, true) + return nil }) } diff --git a/store/shortcut.go b/store/shortcut.go index 3fbb939e..a2f391f5 100644 --- a/store/shortcut.go +++ b/store/shortcut.go @@ -203,14 +203,14 @@ func findShortcutList(db *DB, find *api.ShortcutFind) ([]*api.Shortcut, error) { } func deleteShortcut(db *DB, delete *api.ShortcutDelete) error { - result, err := db.Db.Exec(`DELETE FROM saved_query WHERE id = ?`, delete.Id) + result, err := db.Db.Exec(`DELETE FROM shortcut WHERE id = ?`, delete.Id) if err != nil { return FormatError(err) } rows, _ := result.RowsAffected() if rows == 0 { - return &common.Error{Code: common.NotFound, Err: fmt.Errorf("memo ID not found: %d", delete.Id)} + return &common.Error{Code: common.NotFound, Err: fmt.Errorf("shortcut ID not found: %d", delete.Id)} } return nil