Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
4743818f
Commit
4743818f
authored
Sep 03, 2022
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update not found handler in deleting
parent
43575e6f
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
40 additions
and
5 deletions
+40
-5
memo.go
server/memo.go
+3
-0
resource.go
server/resource.go
+4
-0
shortcut.go
server/shortcut.go
+4
-0
user.go
server/user.go
+3
-0
memo.go
store/memo.go
+6
-1
resource.go
store/resource.go
+6
-1
shortcut.go
store/shortcut.go
+6
-1
user.go
store/user.go
+8
-2
No files found.
server/memo.go
View file @
4743818f
...
...
@@ -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
)
}
...
...
server/resource.go
View file @
4743818f
...
...
@@ -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
)
}
...
...
server/shortcut.go
View file @
4743818f
...
...
@@ -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
)
}
...
...
server/user.go
View file @
4743818f
...
...
@@ -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
)
}
...
...
store/memo.go
View file @
4743818f
...
...
@@ -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
}
store/resource.go
View file @
4743818f
...
...
@@ -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
}
store/shortcut.go
View file @
4743818f
...
...
@@ -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
}
store/user.go
View file @
4743818f
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment