Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
chore: update not found handler in deleting
Steven4743818fe700
diff --git a/server/memo.go b/server/memo.goindex 84b9747c3..b41407d0f 100644--- a/server/memo.go+++ b/server/memo.go@@ -230,6 +230,9 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {ID: memoID,}if err := s.Store.DeleteMemo(ctx, memoDelete); err != nil {+ if common.ErrorCode(err) == common.NotFound {+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Memo ID not found: %d", memoID))+ }return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete memo ID: %v", memoID)).SetInternal(err)}diff --git a/server/resource.go b/server/resource.goindex 141efb32e..e12f7e489 100644--- a/server/resource.go+++ b/server/resource.go@@ -8,6 +8,7 @@ import ("strconv""github.com/usememos/memos/api"+ "github.com/usememos/memos/common""github.com/labstack/echo/v4")@@ -158,6 +159,9 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {CreatorID: userID,}if err := s.Store.DeleteResource(ctx, resourceDelete); err != nil {+ if common.ErrorCode(err) == common.NotFound {+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Resource ID not found: %d", resourceID))+ }return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete resource").SetInternal(err)}diff --git a/server/shortcut.go b/server/shortcut.goindex c966ff6e5..36d9355c6 100644--- a/server/shortcut.go+++ b/server/shortcut.go@@ -7,6 +7,7 @@ import ("strconv""github.com/usememos/memos/api"+ "github.com/usememos/memos/common""github.com/labstack/echo/v4")@@ -123,6 +124,9 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {ID: shortcutID,}if err := s.Store.DeleteShortcut(ctx, shortcutDelete); err != nil {+ if common.ErrorCode(err) == common.NotFound {+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Shortcut ID not found: %d", shortcutID))+ }return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete shortcut").SetInternal(err)}diff --git a/server/user.go b/server/user.goindex f5af77986..99c1de357 100644--- a/server/user.go+++ b/server/user.go@@ -250,6 +250,9 @@ func (s *Server) registerUserRoutes(g *echo.Group) {ID: userID,}if err := s.Store.DeleteUser(ctx, userDelete); err != nil {+ if common.ErrorCode(err) == common.NotFound {+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("User ID not found: %d", userID))+ }return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete user").SetInternal(err)}diff --git a/store/memo.go b/store/memo.goindex 036bb5f20..b8cfcc491 100644--- a/store/memo.go+++ b/store/memo.go@@ -348,7 +348,7 @@ func findMemoRawList(ctx context.Context, tx *sql.Tx, find *api.MemoFind) ([]*me}func deleteMemo(ctx context.Context, tx *sql.Tx, delete *api.MemoDelete) error {- _, err := tx.ExecContext(ctx, `+ result, err := tx.ExecContext(ctx, `PRAGMA foreign_keys = ON;DELETE FROM memo WHERE id = ?`, delete.ID)@@ -356,5 +356,10 @@ func deleteMemo(ctx context.Context, tx *sql.Tx, delete *api.MemoDelete) error {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 nil}diff --git a/store/resource.go b/store/resource.goindex ce6b712ad..2605bb17b 100644--- a/store/resource.go+++ b/store/resource.go@@ -235,7 +235,7 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) (}func deleteResource(ctx context.Context, tx *sql.Tx, delete *api.ResourceDelete) error {- _, err := tx.ExecContext(ctx, `+ result, err := tx.ExecContext(ctx, `PRAGMA foreign_keys = ON;DELETE FROM resource WHERE id = ? AND creator_id = ?`, delete.ID, delete.CreatorID)@@ -243,5 +243,10 @@ func deleteResource(ctx context.Context, tx *sql.Tx, delete *api.ResourceDelete)return FormatError(err)}+ rows, _ := result.RowsAffected()+ if rows == 0 {+ return &common.Error{Code: common.NotFound, Err: fmt.Errorf("resource ID not found: %d", delete.ID)}+ }+return nil}diff --git a/store/shortcut.go b/store/shortcut.goindex 2aeb2d9db..0eab5c91a 100644--- a/store/shortcut.go+++ b/store/shortcut.go@@ -287,7 +287,7 @@ func findShortcutList(ctx context.Context, tx *sql.Tx, find *api.ShortcutFind) (}func deleteShortcut(ctx context.Context, tx *sql.Tx, delete *api.ShortcutDelete) error {- _, err := tx.ExecContext(ctx, `+ result, err := tx.ExecContext(ctx, `PRAGMA foreign_keys = ON;DELETE FROM shortcut WHERE id = ?`, delete.ID)@@ -295,5 +295,10 @@ func deleteShortcut(ctx context.Context, tx *sql.Tx, delete *api.ShortcutDelete)return FormatError(err)}+ rows, _ := result.RowsAffected()+ if rows == 0 {+ return &common.Error{Code: common.NotFound, Err: fmt.Errorf("shortcut ID not found: %d", delete.ID)}+ }+return nil}diff --git a/store/user.go b/store/user.goindex d2494d6b0..e0ed79a84 100644--- a/store/user.go+++ b/store/user.go@@ -336,12 +336,18 @@ func findUserList(ctx context.Context, tx *sql.Tx, find *api.UserFind) ([]*userR}func deleteUser(ctx context.Context, tx *sql.Tx, delete *api.UserDelete) error {- if _, err := tx.ExecContext(ctx, `+ result, err := tx.ExecContext(ctx, `PRAGMA foreign_keys = ON;DELETE FROM user WHERE id = ?- `, delete.ID); err != nil {+ `, delete.ID)+ if err != nil {return FormatError(err)}+ rows, _ := result.RowsAffected()+ if rows == 0 {+ return &common.Error{Code: common.NotFound, Err: fmt.Errorf("user ID not found: %d", delete.ID)}+ }+return nil}