mirror of
https://github.com/usememos/memos.git
synced 2025-02-19 04:40:40 +01:00
fix: get user by username api (#2034)
This commit is contained in:
parent
56c321aeaa
commit
d8d6de9fca
@ -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 != "" {
|
||||
|
@ -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})
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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 />
|
||||
|
@ -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, useMemoStore, useUserStore } from "@/store/module";
|
||||
import { useFilterStore, useGlobalStore, useMemoStore } 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} />
|
||||
<div className="mb-4 mt-2 w-full">
|
||||
<SearchBar />
|
||||
</div>
|
||||
{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 />
|
||||
|
@ -16,11 +16,9 @@ const Home = () => {
|
||||
|
||||
useEffect(() => {
|
||||
const currentUsername = userStore.getCurrentUsername();
|
||||
userStore.getUserByUsername(currentUsername).then((user) => {
|
||||
if (!user) {
|
||||
toast.error(t("message.user-not-found"));
|
||||
return;
|
||||
}
|
||||
userStore.getUserByUsername(currentUsername).catch((error) => {
|
||||
console.error(error);
|
||||
toast.error(t("message.user-not-found"));
|
||||
});
|
||||
}, [userStore.getCurrentUsername()]);
|
||||
|
||||
|
@ -81,7 +81,7 @@ const router = createBrowserRouter([
|
||||
},
|
||||
{
|
||||
path: "u/:username",
|
||||
element: <Explore />,
|
||||
element: <Home />,
|
||||
loader: async () => {
|
||||
await initialGlobalStateLoader();
|
||||
|
||||
|
@ -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));
|
||||
|
1
web/src/types/modules/shortcut.d.ts
vendored
1
web/src/types/modules/shortcut.d.ts
vendored
@ -3,7 +3,6 @@ type ShortcutId = number;
|
||||
interface Shortcut {
|
||||
id: ShortcutId;
|
||||
|
||||
creatorUsername: string;
|
||||
rowStatus: RowStatus;
|
||||
createdTs: TimeStamp;
|
||||
updatedTs: TimeStamp;
|
||||
|
Loading…
x
Reference in New Issue
Block a user