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
94df09c8
Unverified
Commit
94df09c8
authored
Oct 27, 2022
by
boojack
Committed by
GitHub
Oct 27, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update memo list api (#350)
parent
bdf6d4d4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
26 additions
and
12 deletions
+26
-12
util.go
common/util.go
+7
-0
memo.go
server/memo.go
+11
-1
memo.go
store/memo.go
+1
-9
api.ts
web/src/helpers/api.ts
+3
-0
memoService.ts
web/src/services/memoService.ts
+2
-1
memo.ts
web/src/store/modules/memo.ts
+1
-1
memo.d.ts
web/src/types/modules/memo.d.ts
+1
-0
No files found.
common/util.go
View file @
94df09c8
...
@@ -28,3 +28,10 @@ func ValidateEmail(email string) bool {
...
@@ -28,3 +28,10 @@ func ValidateEmail(email string) bool {
func
GenUUID
()
string
{
func
GenUUID
()
string
{
return
uuid
.
New
()
.
String
()
return
uuid
.
New
()
.
String
()
}
}
func
Min
(
x
,
y
int
)
int
{
if
x
<
y
{
return
x
}
return
y
}
server/memo.go
View file @
94df09c8
...
@@ -193,9 +193,19 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
...
@@ -193,9 +193,19 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
}
}
sort
.
Slice
(
list
,
func
(
i
,
j
int
)
bool
{
sort
.
Slice
(
list
,
func
(
i
,
j
int
)
bool
{
return
list
[
i
]
.
DisplayTs
>
list
[
j
]
.
DisplayTs
return
list
[
i
]
.
DisplayTs
<
list
[
j
]
.
DisplayTs
})
sort
.
Slice
(
list
,
func
(
i
,
j
int
)
bool
{
if
!
list
[
i
]
.
Pinned
&&
list
[
j
]
.
Pinned
{
return
false
}
return
true
})
})
if
memoFind
.
Limit
!=
0
{
list
=
list
[
memoFind
.
Offset
:
common
.
Min
(
len
(
list
),
memoFind
.
Offset
+
memoFind
.
Limit
)]
}
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
list
));
err
!=
nil
{
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
list
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to encode memo list response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to encode memo list response"
)
.
SetInternal
(
err
)
...
...
store/memo.go
View file @
94df09c8
...
@@ -329,14 +329,6 @@ func findMemoRawList(ctx context.Context, tx *sql.Tx, find *api.MemoFind) ([]*me
...
@@ -329,14 +329,6 @@ func findMemoRawList(ctx context.Context, tx *sql.Tx, find *api.MemoFind) ([]*me
where
=
append
(
where
,
fmt
.
Sprintf
(
"visibility in (%s)"
,
strings
.
Join
(
list
,
","
)))
where
=
append
(
where
,
fmt
.
Sprintf
(
"visibility in (%s)"
,
strings
.
Join
(
list
,
","
)))
}
}
pagination
:=
""
if
find
.
Limit
>
0
{
pagination
=
fmt
.
Sprintf
(
"%s LIMIT %d"
,
pagination
,
find
.
Limit
)
if
find
.
Offset
>
0
{
pagination
=
fmt
.
Sprintf
(
"%s OFFSET %d"
,
pagination
,
find
.
Offset
)
}
}
query
:=
`
query
:=
`
SELECT
SELECT
id,
id,
...
@@ -349,7 +341,7 @@ func findMemoRawList(ctx context.Context, tx *sql.Tx, find *api.MemoFind) ([]*me
...
@@ -349,7 +341,7 @@ func findMemoRawList(ctx context.Context, tx *sql.Tx, find *api.MemoFind) ([]*me
FROM memo
FROM memo
WHERE `
+
strings
.
Join
(
where
,
" AND "
)
+
`
WHERE `
+
strings
.
Join
(
where
,
" AND "
)
+
`
ORDER BY created_ts DESC
ORDER BY created_ts DESC
`
+
pagination
`
rows
,
err
:=
tx
.
QueryContext
(
ctx
,
query
,
args
...
)
rows
,
err
:=
tx
.
QueryContext
(
ctx
,
query
,
args
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
FormatError
(
err
)
return
nil
,
FormatError
(
err
)
...
...
web/src/helpers/api.ts
View file @
94df09c8
...
@@ -78,6 +78,9 @@ export function getMemoList(memoFind?: MemoFind) {
...
@@ -78,6 +78,9 @@ export function getMemoList(memoFind?: MemoFind) {
if
(
memoFind
?.
rowStatus
)
{
if
(
memoFind
?.
rowStatus
)
{
queryList
.
push
(
`rowStatus=
${
memoFind
.
rowStatus
}
`
);
queryList
.
push
(
`rowStatus=
${
memoFind
.
rowStatus
}
`
);
}
}
if
(
memoFind
?.
pinned
)
{
queryList
.
push
(
`pinned=
${
memoFind
.
pinned
}
`
);
}
if
(
memoFind
?.
offset
)
{
if
(
memoFind
?.
offset
)
{
queryList
.
push
(
`offset=
${
memoFind
.
offset
}
`
);
queryList
.
push
(
`offset=
${
memoFind
.
offset
}
`
);
}
}
...
...
web/src/services/memoService.ts
View file @
94df09c8
import
{
uniqBy
}
from
"lodash"
;
import
*
as
api
from
"../helpers/api"
;
import
*
as
api
from
"../helpers/api"
;
import
{
createMemo
,
deleteMemo
,
patchMemo
,
setIsFetching
,
setMemos
,
setTags
}
from
"../store/modules/memo"
;
import
{
createMemo
,
deleteMemo
,
patchMemo
,
setIsFetching
,
setMemos
,
setTags
}
from
"../store/modules/memo"
;
import
store
from
"../store"
;
import
store
from
"../store"
;
...
@@ -35,7 +36,7 @@ const memoService = {
...
@@ -35,7 +36,7 @@ const memoService = {
store
.
dispatch
(
setMemos
([]));
store
.
dispatch
(
setMemos
([]));
}
}
const
memos
=
memoService
.
getState
().
memos
;
const
memos
=
memoService
.
getState
().
memos
;
store
.
dispatch
(
setMemos
(
memos
.
concat
(
fetchedMemos
)));
store
.
dispatch
(
setMemos
(
uniqBy
(
memos
.
concat
(
fetchedMemos
),
"id"
)));
store
.
dispatch
(
setIsFetching
(
false
));
store
.
dispatch
(
setIsFetching
(
false
));
return
fetchedMemos
;
return
fetchedMemos
;
...
...
web/src/store/modules/memo.ts
View file @
94df09c8
...
@@ -18,7 +18,7 @@ const memoSlice = createSlice({
...
@@ -18,7 +18,7 @@ const memoSlice = createSlice({
setMemos
:
(
state
,
action
:
PayloadAction
<
Memo
[]
>
)
=>
{
setMemos
:
(
state
,
action
:
PayloadAction
<
Memo
[]
>
)
=>
{
return
{
return
{
...
state
,
...
state
,
memos
:
action
.
payload
.
filter
((
m
)
=>
m
.
rowStatus
===
"NORMAL"
)
,
memos
:
action
.
payload
,
};
};
},
},
createMemo
:
(
state
,
action
:
PayloadAction
<
Memo
>
)
=>
{
createMemo
:
(
state
,
action
:
PayloadAction
<
Memo
>
)
=>
{
...
...
web/src/types/modules/memo.d.ts
View file @
94df09c8
...
@@ -37,6 +37,7 @@ interface MemoPatch {
...
@@ -37,6 +37,7 @@ interface MemoPatch {
interface
MemoFind
{
interface
MemoFind
{
creatorId
?:
UserId
;
creatorId
?:
UserId
;
rowStatus
?:
RowStatus
;
rowStatus
?:
RowStatus
;
pinned
?:
boolean
;
visibility
?:
Visibility
;
visibility
?:
Visibility
;
offset
?:
number
;
offset
?:
number
;
limit
?:
number
;
limit
?:
number
;
...
...
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