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
08f9b18c
Unverified
Commit
08f9b18c
authored
Apr 12, 2025
by
Johnny
Committed by
GitHub
Apr 12, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: list memo relations
parent
2f6dc2b5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
1 deletion
+36
-1
memo_relation_service.go
server/router/api/v1/memo_relation_service.go
+14
-1
memo_relation.go
store/db/sqlite/memo_relation.go
+21
-0
memo_relation.go
store/memo_relation.go
+1
-0
No files found.
server/router/api/v1/memo_relation_service.go
View file @
08f9b18c
...
...
@@ -70,9 +70,21 @@ func (s *APIV1Service) ListMemoRelations(ctx context.Context, request *v1pb.List
if
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to get memo"
)
}
currentUser
,
err
:=
s
.
GetCurrentUser
(
ctx
)
if
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to get user"
)
}
var
memoFilter
string
if
currentUser
==
nil
{
memoFilter
=
`visibility == "PUBLIC"`
}
else
{
memoFilter
=
fmt
.
Sprintf
(
`creator_id == %d || visibility in ["PUBLIC", "PROTECTED"]`
,
currentUser
.
ID
)
}
relationList
:=
[]
*
v1pb
.
MemoRelation
{}
tempList
,
err
:=
s
.
Store
.
ListMemoRelations
(
ctx
,
&
store
.
FindMemoRelation
{
MemoID
:
&
memo
.
ID
,
MemoID
:
&
memo
.
ID
,
MemoFilter
:
&
memoFilter
,
})
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -86,6 +98,7 @@ func (s *APIV1Service) ListMemoRelations(ctx context.Context, request *v1pb.List
}
tempList
,
err
=
s
.
Store
.
ListMemoRelations
(
ctx
,
&
store
.
FindMemoRelation
{
RelatedMemoID
:
&
memo
.
ID
,
MemoFilter
:
&
memoFilter
,
})
if
err
!=
nil
{
return
nil
,
err
...
...
store/db/sqlite/memo_relation.go
View file @
08f9b18c
...
...
@@ -2,8 +2,10 @@ package sqlite
import
(
"context"
"fmt"
"strings"
"github.com/usememos/memos/plugin/filter"
"github.com/usememos/memos/store"
)
...
...
@@ -46,6 +48,25 @@ func (d *DB) ListMemoRelations(ctx context.Context, find *store.FindMemoRelation
if
find
.
Type
!=
nil
{
where
,
args
=
append
(
where
,
"type = ?"
),
append
(
args
,
find
.
Type
)
}
if
find
.
MemoFilter
!=
nil
{
// Parse filter string and return the parsed expression.
// The filter string should be a CEL expression.
parsedExpr
,
err
:=
filter
.
Parse
(
*
find
.
MemoFilter
,
filter
.
MemoFilterCELAttributes
...
)
if
err
!=
nil
{
return
nil
,
err
}
convertCtx
:=
filter
.
NewConvertContext
()
// ConvertExprToSQL converts the parsed expression to a SQL condition string.
if
err
:=
d
.
ConvertExprToSQL
(
convertCtx
,
parsedExpr
.
GetExpr
());
err
!=
nil
{
return
nil
,
err
}
condition
:=
convertCtx
.
Buffer
.
String
()
if
condition
!=
""
{
where
=
append
(
where
,
fmt
.
Sprintf
(
"memo_id IN (SELECT id FROM memo WHERE %s)"
,
condition
))
where
=
append
(
where
,
fmt
.
Sprintf
(
"related_memo_id IN (SELECT id FROM memo WHERE %s)"
,
condition
))
args
=
append
(
args
,
append
(
convertCtx
.
Args
,
convertCtx
.
Args
...
)
...
)
}
}
rows
,
err
:=
d
.
db
.
QueryContext
(
ctx
,
`
SELECT
...
...
store/memo_relation.go
View file @
08f9b18c
...
...
@@ -23,6 +23,7 @@ type FindMemoRelation struct {
MemoID
*
int32
RelatedMemoID
*
int32
Type
*
MemoRelationType
MemoFilter
*
string
}
type
DeleteMemoRelation
struct
{
...
...
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