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
ef549207
Unverified
Commit
ef549207
authored
Oct 31, 2022
by
boojack
Committed by
GitHub
Oct 31, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update memo stats api (#387)
parent
40d56860
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
36 deletions
+42
-36
acl.go
server/acl.go
+1
-1
memo.go
server/memo.go
+23
-25
UsageHeatMap.tsx
web/src/components/UsageHeatMap.tsx
+6
-7
UserBanner.tsx
web/src/components/UserBanner.tsx
+1
-1
api.ts
web/src/helpers/api.ts
+2
-2
userService.ts
web/src/services/userService.ts
+9
-0
No files found.
server/acl.go
View file @
ef549207
...
@@ -104,7 +104,7 @@ func aclMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {
...
@@ -104,7 +104,7 @@ func aclMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {
}
}
}
}
if
common
.
HasPrefixes
(
path
,
"/api/memo/all"
,
"/api/memo/:memoId"
)
&&
c
.
Request
()
.
Method
==
http
.
MethodGet
{
if
common
.
HasPrefixes
(
path
,
"/api/memo/all"
,
"/api/memo/:memoId"
,
"/api/memo/amount"
,
"/api/memo/stats"
)
&&
c
.
Request
()
.
Method
==
http
.
MethodGet
{
return
next
(
c
)
return
next
(
c
)
}
}
...
...
server/memo.go
View file @
ef549207
...
@@ -229,13 +229,35 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
...
@@ -229,13 +229,35 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
return
nil
return
nil
})
})
g
.
GET
(
"/memo/amount"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
normalRowStatus
:=
api
.
Normal
memoFind
:=
&
api
.
MemoFind
{
RowStatus
:
&
normalRowStatus
,
}
if
userID
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"userId"
));
err
==
nil
{
memoFind
.
CreatorID
=
&
userID
}
memoList
,
err
:=
s
.
Store
.
FindMemoList
(
ctx
,
memoFind
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find memo list"
)
.
SetInternal
(
err
)
}
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
len
(
memoList
)));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to encode memo amount"
)
.
SetInternal
(
err
)
}
return
nil
})
g
.
GET
(
"/memo/stats"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/memo/stats"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
normalStatus
:=
api
.
Normal
normalStatus
:=
api
.
Normal
memoFind
:=
&
api
.
MemoFind
{
memoFind
:=
&
api
.
MemoFind
{
RowStatus
:
&
normalStatus
,
RowStatus
:
&
normalStatus
,
}
}
if
userID
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"
creato
rId"
));
err
==
nil
{
if
userID
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"
use
rId"
));
err
==
nil
{
memoFind
.
CreatorID
=
&
userID
memoFind
.
CreatorID
=
&
userID
}
}
...
@@ -525,28 +547,4 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
...
@@ -525,28 +547,4 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
return
c
.
JSON
(
http
.
StatusOK
,
true
)
return
c
.
JSON
(
http
.
StatusOK
,
true
)
})
})
g
.
GET
(
"/memo/amount"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
getUserIDContextKey
())
.
(
int
)
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
normalRowStatus
:=
api
.
Normal
memoFind
:=
&
api
.
MemoFind
{
CreatorID
:
&
userID
,
RowStatus
:
&
normalRowStatus
,
}
memoList
,
err
:=
s
.
Store
.
FindMemoList
(
ctx
,
memoFind
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find memo list"
)
.
SetInternal
(
err
)
}
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
len
(
memoList
)));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to encode memo amount"
)
.
SetInternal
(
err
)
}
return
nil
})
}
}
web/src/components/UsageHeatMap.tsx
View file @
ef549207
import
{
useCallback
,
useEffect
,
useRef
,
useState
}
from
"react"
;
import
{
useCallback
,
useEffect
,
useRef
,
useState
}
from
"react"
;
import
{
useAppSelector
}
from
"../store"
;
import
{
useAppSelector
}
from
"../store"
;
import
{
locationService
}
from
"../services"
;
import
{
locationService
,
userService
}
from
"../services"
;
import
{
getMemoStats
}
from
"../helpers/api"
;
import
{
getMemoStats
}
from
"../helpers/api"
;
import
{
DAILY_TIMESTAMP
}
from
"../helpers/consts"
;
import
{
DAILY_TIMESTAMP
}
from
"../helpers/consts"
;
import
*
as
utils
from
"../helpers/utils"
;
import
*
as
utils
from
"../helpers/utils"
;
...
@@ -28,19 +28,18 @@ interface DailyUsageStat {
...
@@ -28,19 +28,18 @@ interface DailyUsageStat {
}
}
const
UsageHeatMap
=
()
=>
{
const
UsageHeatMap
=
()
=>
{
const
{
memos
}
=
useAppSelector
((
state
)
=>
state
.
memo
);
const
[
allStat
,
setAllStat
]
=
useState
<
DailyUsageStat
[]
>
([]);
const
[
currentStat
,
setCurrentStat
]
=
useState
<
DailyUsageStat
|
null
>
(
null
);
const
containerElRef
=
useRef
<
HTMLDivElement
>
(
null
);
const
todayTimeStamp
=
utils
.
getDateStampByDate
(
Date
.
now
());
const
todayTimeStamp
=
utils
.
getDateStampByDate
(
Date
.
now
());
const
todayDay
=
new
Date
(
todayTimeStamp
).
getDay
()
+
1
;
const
todayDay
=
new
Date
(
todayTimeStamp
).
getDay
()
+
1
;
const
nullCell
=
new
Array
(
7
-
todayDay
).
fill
(
0
);
const
nullCell
=
new
Array
(
7
-
todayDay
).
fill
(
0
);
const
usedDaysAmount
=
(
tableConfig
.
width
-
1
)
*
tableConfig
.
height
+
todayDay
;
const
usedDaysAmount
=
(
tableConfig
.
width
-
1
)
*
tableConfig
.
height
+
todayDay
;
const
beginDayTimestemp
=
todayTimeStamp
-
usedDaysAmount
*
DAILY_TIMESTAMP
;
const
beginDayTimestemp
=
todayTimeStamp
-
usedDaysAmount
*
DAILY_TIMESTAMP
;
const
{
memos
}
=
useAppSelector
((
state
)
=>
state
.
memo
);
const
[
allStat
,
setAllStat
]
=
useState
<
DailyUsageStat
[]
>
(
getInitialUsageStat
(
usedDaysAmount
,
beginDayTimestemp
));
const
[
currentStat
,
setCurrentStat
]
=
useState
<
DailyUsageStat
|
null
>
(
null
);
const
containerElRef
=
useRef
<
HTMLDivElement
>
(
null
);
useEffect
(()
=>
{
useEffect
(()
=>
{
getMemoStats
()
getMemoStats
(
userService
.
getCurrentUserId
()
)
.
then
(({
data
:
{
data
}
})
=>
{
.
then
(({
data
:
{
data
}
})
=>
{
const
newStat
:
DailyUsageStat
[]
=
getInitialUsageStat
(
usedDaysAmount
,
beginDayTimestemp
);
const
newStat
:
DailyUsageStat
[]
=
getInitialUsageStat
(
usedDaysAmount
,
beginDayTimestemp
);
for
(
const
record
of
data
)
{
for
(
const
record
of
data
)
{
...
...
web/src/components/UserBanner.tsx
View file @
ef549207
...
@@ -37,7 +37,7 @@ const UserBanner = () => {
...
@@ -37,7 +37,7 @@ const UserBanner = () => {
},
[
isVisitorMode
,
user
,
owner
]);
},
[
isVisitorMode
,
user
,
owner
]);
useEffect
(()
=>
{
useEffect
(()
=>
{
getMemoStats
()
getMemoStats
(
userService
.
getCurrentUserId
()
)
.
then
(({
data
:
{
data
}
})
=>
{
.
then
(({
data
:
{
data
}
})
=>
{
setMemoAmount
(
data
.
length
);
setMemoAmount
(
data
.
length
);
})
})
...
...
web/src/helpers/api.ts
View file @
ef549207
...
@@ -90,8 +90,8 @@ export function getMemoList(memoFind?: MemoFind) {
...
@@ -90,8 +90,8 @@ export function getMemoList(memoFind?: MemoFind) {
return
axios
.
get
<
ResponseObject
<
Memo
[]
>>
(
`/api/memo?
${
queryList
.
join
(
"&"
)}
`
);
return
axios
.
get
<
ResponseObject
<
Memo
[]
>>
(
`/api/memo?
${
queryList
.
join
(
"&"
)}
`
);
}
}
export
function
getMemoStats
()
{
export
function
getMemoStats
(
userId
:
UserId
)
{
return
axios
.
get
<
ResponseObject
<
number
[]
>>
(
`/api/memo/stats`
);
return
axios
.
get
<
ResponseObject
<
number
[]
>>
(
`/api/memo/stats
?userId=
${
userId
}
`
);
}
}
export
function
getMemoById
(
id
:
MemoId
)
{
export
function
getMemoById
(
id
:
MemoId
)
{
...
...
web/src/services/userService.ts
View file @
ef549207
import
{
locationService
}
from
"."
;
import
{
locationService
}
from
"."
;
import
*
as
api
from
"../helpers/api"
;
import
*
as
api
from
"../helpers/api"
;
import
{
UNKNOWN_ID
}
from
"../helpers/consts"
;
import
store
from
"../store"
;
import
store
from
"../store"
;
import
{
setUser
,
patchUser
,
setHost
,
setOwner
}
from
"../store/modules/user"
;
import
{
setUser
,
patchUser
,
setHost
,
setOwner
}
from
"../store/modules/user"
;
...
@@ -57,6 +58,14 @@ const userService = {
...
@@ -57,6 +58,14 @@ const userService = {
}
}
},
},
getCurrentUserId
:
()
=>
{
if
(
userService
.
isVisitorMode
())
{
return
userService
.
getUserIdFromPath
()
||
UNKNOWN_ID
;
}
else
{
return
userService
.
getState
().
user
?.
id
||
UNKNOWN_ID
;
}
},
isVisitorMode
:
()
=>
{
isVisitorMode
:
()
=>
{
return
!
(
userService
.
getUserIdFromPath
()
===
undefined
);
return
!
(
userService
.
getUserIdFromPath
()
===
undefined
);
},
},
...
...
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