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
ec2995d6
Commit
ec2995d6
authored
Nov 19, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: fix order by pinned
parent
94c71cb8
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
18 deletions
+26
-18
memo.go
api/v1/memo.go
+17
-16
memo.go
store/db/mysql/memo.go
+4
-1
memo.go
store/db/sqlite/memo.go
+4
-1
memo.go
store/memo.go
+1
-0
No files found.
api/v1/memo.go
View file @
ec2995d6
...
@@ -147,47 +147,48 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
...
@@ -147,47 +147,48 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
func
(
s
*
APIV1Service
)
GetMemoList
(
c
echo
.
Context
)
error
{
func
(
s
*
APIV1Service
)
GetMemoList
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
hasParentFlag
:=
false
hasParentFlag
:=
false
find
MemoMessage
:=
&
store
.
FindMemo
{
find
:=
&
store
.
FindMemo
{
HasParent
:
&
hasParentFlag
,
HasParent
:
&
hasParentFlag
,
OrderByPinned
:
true
,
}
}
if
userID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
QueryParam
(
"creatorId"
));
err
==
nil
{
if
userID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
QueryParam
(
"creatorId"
));
err
==
nil
{
find
MemoMessage
.
CreatorID
=
&
userID
find
.
CreatorID
=
&
userID
}
}
if
username
:=
c
.
QueryParam
(
"creatorUsername"
);
username
!=
""
{
if
username
:=
c
.
QueryParam
(
"creatorUsername"
);
username
!=
""
{
user
,
_
:=
s
.
Store
.
GetUser
(
ctx
,
&
store
.
FindUser
{
Username
:
&
username
})
user
,
_
:=
s
.
Store
.
GetUser
(
ctx
,
&
store
.
FindUser
{
Username
:
&
username
})
if
user
!=
nil
{
if
user
!=
nil
{
find
MemoMessage
.
CreatorID
=
&
user
.
ID
find
.
CreatorID
=
&
user
.
ID
}
}
}
}
currentUserID
,
ok
:=
c
.
Get
(
userIDContextKey
)
.
(
int32
)
currentUserID
,
ok
:=
c
.
Get
(
userIDContextKey
)
.
(
int32
)
if
!
ok
{
if
!
ok
{
// Anonymous use should only fetch PUBLIC memos with specified user
// Anonymous use should only fetch PUBLIC memos with specified user
if
find
MemoMessage
.
CreatorID
==
nil
{
if
find
.
CreatorID
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Missing user to find memo"
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Missing user to find memo"
)
}
}
find
MemoMessage
.
VisibilityList
=
[]
store
.
Visibility
{
store
.
Public
}
find
.
VisibilityList
=
[]
store
.
Visibility
{
store
.
Public
}
}
else
{
}
else
{
// Authorized user can fetch all PUBLIC/PROTECTED memo
// Authorized user can fetch all PUBLIC/PROTECTED memo
visibilityList
:=
[]
store
.
Visibility
{
store
.
Public
,
store
.
Protected
}
visibilityList
:=
[]
store
.
Visibility
{
store
.
Public
,
store
.
Protected
}
// If Creator is authorized user (as default), PRIVATE memo is OK
// If Creator is authorized user (as default), PRIVATE memo is OK
if
find
MemoMessage
.
CreatorID
==
nil
||
*
findMemoMessage
.
CreatorID
==
currentUserID
{
if
find
.
CreatorID
==
nil
||
*
find
.
CreatorID
==
currentUserID
{
find
MemoMessage
.
CreatorID
=
&
currentUserID
find
.
CreatorID
=
&
currentUserID
visibilityList
=
append
(
visibilityList
,
store
.
Private
)
visibilityList
=
append
(
visibilityList
,
store
.
Private
)
}
}
find
MemoMessage
.
VisibilityList
=
visibilityList
find
.
VisibilityList
=
visibilityList
}
}
rowStatus
:=
store
.
RowStatus
(
c
.
QueryParam
(
"rowStatus"
))
rowStatus
:=
store
.
RowStatus
(
c
.
QueryParam
(
"rowStatus"
))
if
rowStatus
!=
""
{
if
rowStatus
!=
""
{
find
MemoMessage
.
RowStatus
=
&
rowStatus
find
.
RowStatus
=
&
rowStatus
}
}
pinnedStr
:=
c
.
QueryParam
(
"pinned"
)
pinnedStr
:=
c
.
QueryParam
(
"pinned"
)
if
pinnedStr
!=
""
{
if
pinnedStr
!=
""
{
pinned
:=
pinnedStr
==
"true"
pinned
:=
pinnedStr
==
"true"
find
MemoMessage
.
Pinned
=
&
pinned
find
.
Pinned
=
&
pinned
}
}
contentSearch
:=
[]
string
{}
contentSearch
:=
[]
string
{}
...
@@ -199,13 +200,13 @@ func (s *APIV1Service) GetMemoList(c echo.Context) error {
...
@@ -199,13 +200,13 @@ func (s *APIV1Service) GetMemoList(c echo.Context) error {
if
content
!=
""
{
if
content
!=
""
{
contentSearch
=
append
(
contentSearch
,
content
)
contentSearch
=
append
(
contentSearch
,
content
)
}
}
find
MemoMessage
.
ContentSearch
=
contentSearch
find
.
ContentSearch
=
contentSearch
if
limit
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"limit"
));
err
==
nil
{
if
limit
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"limit"
));
err
==
nil
{
find
MemoMessage
.
Limit
=
&
limit
find
.
Limit
=
&
limit
}
}
if
offset
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"offset"
));
err
==
nil
{
if
offset
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"offset"
));
err
==
nil
{
find
MemoMessage
.
Offset
=
&
offset
find
.
Offset
=
&
offset
}
}
memoDisplayWithUpdatedTs
,
err
:=
s
.
getMemoDisplayWithUpdatedTsSettingValue
(
ctx
)
memoDisplayWithUpdatedTs
,
err
:=
s
.
getMemoDisplayWithUpdatedTsSettingValue
(
ctx
)
...
@@ -213,10 +214,10 @@ func (s *APIV1Service) GetMemoList(c echo.Context) error {
...
@@ -213,10 +214,10 @@ func (s *APIV1Service) GetMemoList(c echo.Context) error {
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to get memo display with updated ts setting value"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to get memo display with updated ts setting value"
)
.
SetInternal
(
err
)
}
}
if
memoDisplayWithUpdatedTs
{
if
memoDisplayWithUpdatedTs
{
find
MemoMessage
.
OrderByUpdatedTs
=
true
find
.
OrderByUpdatedTs
=
true
}
}
list
,
err
:=
s
.
Store
.
ListMemos
(
ctx
,
find
MemoMessage
)
list
,
err
:=
s
.
Store
.
ListMemos
(
ctx
,
find
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to fetch memo list"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to fetch memo list"
)
.
SetInternal
(
err
)
}
}
...
...
store/db/mysql/memo.go
View file @
ec2995d6
...
@@ -96,7 +96,10 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
...
@@ -96,7 +96,10 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
}
}
where
=
append
(
where
,
fmt
.
Sprintf
(
"`memo`.`visibility` in (%s)"
,
strings
.
Join
(
list
,
","
)))
where
=
append
(
where
,
fmt
.
Sprintf
(
"`memo`.`visibility` in (%s)"
,
strings
.
Join
(
list
,
","
)))
}
}
orders
:=
[]
string
{
"`pinned` DESC"
}
orders
:=
[]
string
{}
if
find
.
OrderByPinned
{
orders
=
append
(
orders
,
"`pinned` DESC"
)
}
if
find
.
OrderByUpdatedTs
{
if
find
.
OrderByUpdatedTs
{
orders
=
append
(
orders
,
"`updated_ts` DESC"
)
orders
=
append
(
orders
,
"`updated_ts` DESC"
)
}
else
{
}
else
{
...
...
store/db/sqlite/memo.go
View file @
ec2995d6
...
@@ -96,7 +96,10 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
...
@@ -96,7 +96,10 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
}
}
}
}
orders
:=
[]
string
{
"pinned DESC"
}
orders
:=
[]
string
{}
if
find
.
OrderByPinned
{
orders
=
append
(
orders
,
"pinned DESC"
)
}
if
find
.
OrderByUpdatedTs
{
if
find
.
OrderByUpdatedTs
{
orders
=
append
(
orders
,
"updated_ts DESC"
)
orders
=
append
(
orders
,
"updated_ts DESC"
)
}
else
{
}
else
{
...
...
store/memo.go
View file @
ec2995d6
...
@@ -70,6 +70,7 @@ type FindMemo struct {
...
@@ -70,6 +70,7 @@ type FindMemo struct {
Limit
*
int
Limit
*
int
Offset
*
int
Offset
*
int
OrderByUpdatedTs
bool
OrderByUpdatedTs
bool
OrderByPinned
bool
}
}
type
UpdateMemo
struct
{
type
UpdateMemo
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