mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update not found handler in deleting
This commit is contained in:
@ -230,6 +230,9 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|||||||
ID: memoID,
|
ID: memoID,
|
||||||
}
|
}
|
||||||
if err := s.Store.DeleteMemo(ctx, memoDelete); err != nil {
|
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)
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to delete memo ID: %v", memoID)).SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/usememos/memos/api"
|
"github.com/usememos/memos/api"
|
||||||
|
"github.com/usememos/memos/common"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
@ -158,6 +159,9 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
|
|||||||
CreatorID: userID,
|
CreatorID: userID,
|
||||||
}
|
}
|
||||||
if err := s.Store.DeleteResource(ctx, resourceDelete); err != nil {
|
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)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete resource").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/usememos/memos/api"
|
"github.com/usememos/memos/api"
|
||||||
|
"github.com/usememos/memos/common"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
@ -123,6 +124,9 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
|
|||||||
ID: shortcutID,
|
ID: shortcutID,
|
||||||
}
|
}
|
||||||
if err := s.Store.DeleteShortcut(ctx, shortcutDelete); err != nil {
|
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)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete shortcut").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,6 +250,9 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
|
|||||||
ID: userID,
|
ID: userID,
|
||||||
}
|
}
|
||||||
if err := s.Store.DeleteUser(ctx, userDelete); err != nil {
|
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)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete user").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
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;
|
PRAGMA foreign_keys = ON;
|
||||||
DELETE FROM memo WHERE id = ?
|
DELETE FROM memo WHERE id = ?
|
||||||
`, delete.ID)
|
`, delete.ID)
|
||||||
@ -356,5 +356,10 @@ func deleteMemo(ctx context.Context, tx *sql.Tx, delete *api.MemoDelete) error {
|
|||||||
return FormatError(err)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
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;
|
PRAGMA foreign_keys = ON;
|
||||||
DELETE FROM resource WHERE id = ? AND creator_id = ?
|
DELETE FROM resource WHERE id = ? AND creator_id = ?
|
||||||
`, delete.ID, delete.CreatorID)
|
`, delete.ID, delete.CreatorID)
|
||||||
@ -243,5 +243,10 @@ func deleteResource(ctx context.Context, tx *sql.Tx, delete *api.ResourceDelete)
|
|||||||
return FormatError(err)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
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;
|
PRAGMA foreign_keys = ON;
|
||||||
DELETE FROM shortcut WHERE id = ?
|
DELETE FROM shortcut WHERE id = ?
|
||||||
`, delete.ID)
|
`, delete.ID)
|
||||||
@ -295,5 +295,10 @@ func deleteShortcut(ctx context.Context, tx *sql.Tx, delete *api.ShortcutDelete)
|
|||||||
return FormatError(err)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
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;
|
PRAGMA foreign_keys = ON;
|
||||||
DELETE FROM user WHERE id = ?
|
DELETE FROM user WHERE id = ?
|
||||||
`, delete.ID); err != nil {
|
`, delete.ID)
|
||||||
|
if err != nil {
|
||||||
return FormatError(err)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user