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
d8d6de9f
Unverified
Commit
d8d6de9f
authored
Jul 26, 2023
by
boojack
Committed by
GitHub
Jul 26, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: get user by username api (#2034)
parent
56c321ae
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
21 additions
and
43 deletions
+21
-43
memo.go
api/v1/memo.go
+0
-7
user.go
api/v1/user.go
+3
-2
ResourceItemDropdown.tsx
web/src/components/ResourceItemDropdown.tsx
+1
-5
api.ts
web/src/helpers/api.ts
+1
-1
Archived.tsx
web/src/pages/Archived.tsx
+1
-1
Explore.tsx
web/src/pages/Explore.tsx
+10
-15
Home.tsx
web/src/pages/Home.tsx
+3
-5
index.tsx
web/src/router/index.tsx
+1
-1
memo.ts
web/src/store/module/memo.ts
+1
-5
shortcut.d.ts
web/src/types/modules/shortcut.d.ts
+0
-1
No files found.
api/v1/memo.go
View file @
d8d6de9f
...
...
@@ -542,13 +542,6 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
findMemoMessage
.
Pinned
=
&
pinned
}
if
username
:=
c
.
QueryParam
(
"creatorUsername"
);
username
!=
""
{
user
,
_
:=
s
.
Store
.
GetUser
(
ctx
,
&
store
.
FindUser
{
Username
:
&
username
})
if
user
!=
nil
{
findMemoMessage
.
CreatorID
=
&
user
.
ID
}
}
contentSearch
:=
[]
string
{}
tag
:=
c
.
QueryParam
(
"tag"
)
if
tag
!=
""
{
...
...
api/v1/user.go
View file @
d8d6de9f
...
...
@@ -258,8 +258,9 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
return
c
.
JSON
(
http
.
StatusOK
,
userMessage
)
})
// GET /user/:username - Get user by username.
g
.
GET
(
"/user/:username"
,
func
(
c
echo
.
Context
)
error
{
// GET /user/name/:username - Get user by username.
// NOTE: This should be moved to /api/v2/user/:username
g
.
GET
(
"/user/name/:username"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
username
:=
c
.
Param
(
"username"
)
user
,
err
:=
s
.
Store
.
GetUser
(
ctx
,
&
store
.
FindUser
{
Username
:
&
username
})
...
...
web/src/components/ResourceItemDropdown.tsx
View file @
d8d6de9f
...
...
@@ -17,15 +17,11 @@ interface Props {
const
ResourceItemDropdown
=
({
resource
}:
Props
)
=>
{
const
t
=
useTranslate
();
const
resourceStore
=
useResourceStore
();
const
resources
=
resourceStore
.
state
.
resources
;
const
handlePreviewBtnClick
=
(
resource
:
Resource
)
=>
{
const
resourceUrl
=
getResourceUrl
(
resource
);
if
(
resource
.
type
.
startsWith
(
"image"
))
{
showPreviewImageDialog
(
resources
.
filter
((
r
)
=>
r
.
type
.
startsWith
(
"image"
)).
map
((
r
)
=>
getResourceUrl
(
r
)),
resources
.
findIndex
((
r
)
=>
r
.
id
===
resource
.
id
)
);
showPreviewImageDialog
([
getResourceUrl
(
resource
)],
0
);
}
else
{
window
.
open
(
resourceUrl
);
}
...
...
web/src/helpers/api.ts
View file @
d8d6de9f
...
...
@@ -57,7 +57,7 @@ export function getUserList() {
}
export
function
getUserByUsername
(
username
:
string
)
{
return
axios
.
get
<
User
>
(
`/api/v1/user/
${
username
}
`
);
return
axios
.
get
<
User
>
(
`/api/v1/user/
name/
${
username
}
`
);
}
export
function
upsertUserSetting
(
upsert
:
UserSettingUpsert
)
{
...
...
web/src/pages/Archived.tsx
View file @
d8d6de9f
...
...
@@ -40,7 +40,7 @@ const Archived = () => {
<
section
className=
"w-full min-h-full flex flex-col md:flex-row justify-start items-start px-4 sm:px-2 sm:pt-4 pb-8 bg-zinc-100 dark:bg-zinc-800"
>
<
MobileHeader
showSearch=
{
false
}
/>
<
div
className=
"archived-memo-page"
>
<
div
className=
"mb-
4
mt-2 w-full"
>
<
div
className=
"mb-
2
mt-2 w-full"
>
<
SearchBar
/>
</
div
>
<
MemoFilter
/>
...
...
web/src/pages/Explore.tsx
View file @
d8d6de9f
...
...
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
import
{
toast
}
from
"react-hot-toast"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
import
{
useLocation
}
from
"react-router-dom"
;
import
{
useFilterStore
,
use
MemoStore
,
useUser
Store
}
from
"@/store/module"
;
import
{
useFilterStore
,
use
GlobalStore
,
useMemo
Store
}
from
"@/store/module"
;
import
{
TAG_REG
}
from
"@/labs/marked/parser"
;
import
{
DEFAULT_MEMO_LIMIT
}
from
"@/helpers/consts"
;
import
useLoading
from
"@/hooks/useLoading"
;
...
...
@@ -15,9 +15,9 @@ import SearchBar from "@/components/SearchBar";
const
Explore
=
()
=>
{
const
t
=
useTranslate
();
const
location
=
useLocation
();
const
globalStore
=
useGlobalStore
();
const
filterStore
=
useFilterStore
();
const
memoStore
=
useMemoStore
();
const
userStore
=
useUserStore
();
const
filter
=
filterStore
.
state
;
const
{
memos
}
=
memoStore
.
state
;
const
[
isComplete
,
setIsComplete
]
=
useState
<
boolean
>
(
false
);
...
...
@@ -55,19 +55,13 @@ const Explore = () => {
})
:
memos
;
const
username
=
userStore
.
getUsernameFromPath
();
let
sortedMemos
=
fetchedMemos
const
sortedMemos
=
fetchedMemos
.
filter
((
m
)
=>
m
.
rowStatus
===
"NORMAL"
&&
m
.
visibility
!==
"PRIVATE"
)
.
sort
((
mi
,
mj
)
=>
mj
.
displayTs
-
mi
.
displayTs
);
if
(
username
!=
undefined
)
{
sortedMemos
=
sortedMemos
.
filter
((
m
)
=>
m
.
creatorUsername
===
username
);
}
useEffect
(()
=>
{
const
username
=
userStore
.
getUsernameFromPath
();
memoStore
.
fetchAllMemos
(
DEFAULT_MEMO_LIMIT
,
0
,
username
)
.
fetchAllMemos
(
DEFAULT_MEMO_LIMIT
,
0
)
.
then
((
fetchedMemos
)
=>
{
if
(
fetchedMemos
.
length
<
DEFAULT_MEMO_LIMIT
)
{
setIsComplete
(
true
);
...
...
@@ -82,8 +76,7 @@ const Explore = () => {
const
handleFetchMoreClick
=
async
()
=>
{
try
{
const
username
=
userStore
.
getUsernameFromPath
();
const
fetchedMemos
=
await
memoStore
.
fetchAllMemos
(
DEFAULT_MEMO_LIMIT
,
memos
.
length
,
username
);
const
fetchedMemos
=
await
memoStore
.
fetchAllMemos
(
DEFAULT_MEMO_LIMIT
,
memos
.
length
);
if
(
fetchedMemos
.
length
<
DEFAULT_MEMO_LIMIT
)
{
setIsComplete
(
true
);
}
else
{
...
...
@@ -98,9 +91,11 @@ const Explore = () => {
return
(
<
section
className=
"w-full max-w-3xl min-h-full flex flex-col justify-start items-center px-4 sm:px-2 sm:pt-4 pb-8 bg-zinc-100 dark:bg-zinc-800"
>
<
MobileHeader
showSearch=
{
false
}
/>
{
globalStore
.
isDev
()
&&
(
<
div
className=
"mb-4 mt-2 w-full"
>
<
SearchBar
/>
</
div
>
)
}
{
!
loadingState
.
isLoading
&&
(
<
main
className=
"relative w-full h-auto flex flex-col justify-start items-start"
>
<
MemoFilter
/>
...
...
web/src/pages/Home.tsx
View file @
d8d6de9f
...
...
@@ -16,11 +16,9 @@ const Home = () => {
useEffect
(()
=>
{
const
currentUsername
=
userStore
.
getCurrentUsername
();
userStore
.
getUserByUsername
(
currentUsername
).
then
((
use
r
)
=>
{
if
(
!
user
)
{
userStore
.
getUserByUsername
(
currentUsername
).
catch
((
erro
r
)
=>
{
console
.
error
(
error
);
toast
.
error
(
t
(
"message.user-not-found"
));
return
;
}
});
},
[
userStore
.
getCurrentUsername
()]);
...
...
web/src/router/index.tsx
View file @
d8d6de9f
...
...
@@ -81,7 +81,7 @@ const router = createBrowserRouter([
},
{
path
:
"u/:username"
,
element
:
<
Explor
e
/>,
element
:
<
Hom
e
/>,
loader
:
async
()
=>
{
await
initialGlobalStateLoader
();
...
...
web/src/store/module/memo.ts
View file @
d8d6de9f
...
...
@@ -54,7 +54,7 @@ export const useMemoStore = () => {
return
fetchedMemos
;
},
fetchAllMemos
:
async
(
limit
=
DEFAULT_MEMO_LIMIT
,
offset
?:
number
,
username
?:
string
)
=>
{
fetchAllMemos
:
async
(
limit
=
DEFAULT_MEMO_LIMIT
,
offset
?:
number
)
=>
{
store
.
dispatch
(
setIsFetching
(
true
));
const
memoFind
:
MemoFind
=
{
rowStatus
:
"NORMAL"
,
...
...
@@ -62,10 +62,6 @@ export const useMemoStore = () => {
offset
,
};
if
(
username
!=
undefined
)
{
memoFind
.
creatorUsername
=
username
;
}
const
{
data
}
=
await
api
.
getAllMemos
(
memoFind
);
const
fetchedMemos
=
data
.
map
((
m
)
=>
convertResponseModelMemo
(
m
));
store
.
dispatch
(
upsertMemos
(
fetchedMemos
));
...
...
web/src/types/modules/shortcut.d.ts
View file @
d8d6de9f
...
...
@@ -3,7 +3,6 @@ type ShortcutId = number;
interface
Shortcut
{
id
:
ShortcutId
;
creatorUsername
:
string
;
rowStatus
:
RowStatus
;
createdTs
:
TimeStamp
;
updatedTs
:
TimeStamp
;
...
...
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